WiGLE WiFi Wardriving FOSS v2.63版本的 MD5 值为:20a157bff1dec2e81d8268d404e15cb5

以下内容为反编译后的 KmlWriter.java 源代码,内容仅作参考


package net.wigle.wigleandroid.background;

import android.database.Cursor;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Set;
import net.wigle.wigleandroid.MainActivity;
import net.wigle.wigleandroid.db.DBException;
import net.wigle.wigleandroid.db.DatabaseHelper;
import net.wigle.wigleandroid.model.NetworkType;
import net.wigle.wigleandroid.util.FileUtility;
import org.apache.commons.io.IOUtils;
public class KmlWriter extends AbstractBackgroundTask {
    private static final String NO_SSID = "(no SSID)";
    private final Set<String> btNetworks;
    private final Set<String> networks;
    private final SimpleDateFormat sdf;

    public KmlWriter(FragmentActivity fragmentActivity, DatabaseHelper databaseHelper) {
        this(fragmentActivity, databaseHelper, null, null);
    }

    public KmlWriter(FragmentActivity fragmentActivity, DatabaseHelper databaseHelper, Set<String> set, Set<String> set2) {
        super(fragmentActivity, databaseHelper, "KmlWriter", true);
        this.sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.UK);
        this.networks = set == null ? null : new HashSet(set);
        this.btNetworks = set2 != null ? new HashSet(set2) : null;
    }

    @Override
    protected void subRun() throws IOException {
        Status status;
        String str;
        String str2;
        Object obj;
        Cursor cursor;
        Cursor cursor2;
        Cursor cursor3;
        long j;
        Cursor singleNetwork;
        long j2;
        SimpleDateFormat simpleDateFormat;
        String str3;
        int i;
        HashSet hashSet;
        KmlWriter kmlWriter = this;
        String str4 = "ex problem: ";
        Bundle bundle = new Bundle();
        SimpleDateFormat simpleDateFormat2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US);
        String str5 = FileUtility.WIWI_PREFIX + new SimpleDateFormat("yyyyMMddHHmmss", Locale.US).format(new Date()) + FileUtility.KML_EXT;
        int i2 = 0;
        FileOutputStream createFile = FileUtility.createFile(kmlWriter.context, str5, false);
        ObservationUploader.writeFos(createFile, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<kml xmlns=\"http://www.opengis.net/kml/2.2\"><Document><Style id=\"red\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/red.png</href></Icon></IconStyle></Style><Style id=\"yellow\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/yellow.png</href></Icon></IconStyle></Style><Style id=\"green\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/green.png</href></Icon></IconStyle></Style><Style id=\"blue\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/blue.png</href></Icon></IconStyle></Style><Style id=\"pink\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/pink.png</href></Icon></IconStyle></Style><Style id=\"ltblue\"><IconStyle><Icon><href>http://maps.google.com/mapfiles/ms/icons/lightblue.png</href></Icon></IconStyle></Style><Style id=\"zeroConfidence\"><IconStyle><Icon><href>https://maps.google.com/mapfiles/kml/pal2/icon18.png</href></Icon></IconStyle></Style><Folder><name>Wifi Networks</name>\n");
        try {
            try {
                try {
                    try {
                        try {
                            try {
                                if (kmlWriter.networks == null) {
                                    try {
                                        cursor2 = kmlWriter.dbHelper.networkIterator(DatabaseHelper.NetworkFilter.WIFI);
                                    } catch (Exception e) {
                                        e = e;
                                        str = str5;
                                        str2 = str4;
                                        cursor3 = null;
                                        e.printStackTrace();
                                        String str6 = str2;
                                        MainActivity.error(str6 + e, e);
                                        MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                        Status status2 = Status.EXCEPTION;
                                        bundle.putString(BackgroundGuiHandler.ERROR, str6 + e);
                                        if (cursor3 != null) {
                                        }
                                        status = status2;
                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                        createFile.close();
                                        String str7 = str;
                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7);
                                        bundle.putString(BackgroundGuiHandler.FILENAME, str7);
                                        MainActivity.info("done with kml export");
                                        if (status == 0) {
                                        }
                                    }
                                    try {
                                        str = str5;
                                        try {
                                            long writeKmlFromCursor = writeKmlFromCursor(createFile, cursor2, simpleDateFormat2, 0L, kmlWriter.dbHelper.getNetworkCount(), bundle);
                                            Cursor networkIterator = kmlWriter.dbHelper.networkIterator(DatabaseHelper.NetworkFilter.CELL);
                                            ObservationUploader.writeFos(createFile, "</Folder>\n<Folder><name>Cellular Networks</name>\n");
                                            long writeKmlFromCursor2 = writeKmlFromCursor(createFile, networkIterator, simpleDateFormat2, writeKmlFromCursor, kmlWriter.dbHelper.getNetworkCount(), bundle);
                                            cursor2 = kmlWriter.dbHelper.networkIterator(DatabaseHelper.NetworkFilter.BT);
                                            ObservationUploader.writeFos(createFile, "</Folder>\n<Folder><name>Bluetooth Networks</name>\n");
                                            MainActivity.info("Full KML Export: " + kmlWriter.dbHelper.getNetworkCount() + " per db, wrote " + (writeKmlFromCursor(createFile, cursor2, simpleDateFormat2, writeKmlFromCursor + writeKmlFromCursor2, kmlWriter.dbHelper.getNetworkCount(), bundle) + writeKmlFromCursor2 + writeKmlFromCursor) + " total.");
                                            str2 = "ex problem: ";
                                        } catch (Exception e2) {
                                            e = e2;
                                            str2 = "ex problem: ";
                                            cursor3 = cursor2;
                                            e.printStackTrace();
                                            String str62 = str2;
                                            MainActivity.error(str62 + e, e);
                                            MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                            Status status22 = Status.EXCEPTION;
                                            bundle.putString(BackgroundGuiHandler.ERROR, str62 + e);
                                            if (cursor3 != null) {
                                            }
                                            status = status22;
                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                            createFile.close();
                                            String str72 = str;
                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72);
                                            bundle.putString(BackgroundGuiHandler.FILENAME, str72);
                                            MainActivity.info("done with kml export");
                                            if (status == 0) {
                                            }
                                        }
                                    } catch (InterruptedException e3) {
                                        e = e3;
                                        str = str5;
                                        MainActivity.info("Writing Kml Interrupted: " + e);
                                        if (cursor2 != null) {
                                            cursor2.close();
                                        }
                                        status = 0;
                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                        createFile.close();
                                        String str722 = str;
                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722);
                                        bundle.putString(BackgroundGuiHandler.FILENAME, str722);
                                        MainActivity.info("done with kml export");
                                        if (status == 0) {
                                        }
                                    } catch (DBException e4) {
                                        e = e4;
                                        str = str5;
                                        cursor = cursor2;
                                        kmlWriter.dbHelper.deathDialog("Writing Kml", e);
                                        Status status3 = Status.EXCEPTION;
                                        if (cursor != null) {
                                            cursor.close();
                                        }
                                        status = status3;
                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                        createFile.close();
                                        String str7222 = str;
                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222);
                                        bundle.putString(BackgroundGuiHandler.FILENAME, str7222);
                                        MainActivity.info("done with kml export");
                                        if (status == 0) {
                                        }
                                    } catch (Exception e5) {
                                        e = e5;
                                        str = str5;
                                    }
                                } else {
                                    str = str5;
                                    String str8 = "</Folder>\n<Folder><name>Bluetooth Networks</name>\n";
                                    try {
                                        try {
                                            HashSet hashSet2 = new HashSet();
                                            int size = kmlWriter.networks.size();
                                            Set<String> set = kmlWriter.btNetworks;
                                            if (set != null) {
                                                i2 = set.size();
                                            }
                                            int i3 = size + i2;
                                            long j3 = 0;
                                            long j4 = 0;
                                            for (String str9 : kmlWriter.networks) {
                                                try {
                                                    singleNetwork = kmlWriter.dbHelper.getSingleNetwork(str9, DatabaseHelper.NetworkFilter.WIFI);
                                                    str2 = str4;
                                                    j2 = j3;
                                                    simpleDateFormat = simpleDateFormat2;
                                                    str3 = str8;
                                                    i = i3;
                                                    hashSet = hashSet2;
                                                } catch (InterruptedException e6) {
                                                    e = e6;
                                                    cursor2 = null;
                                                    kmlWriter = this;
                                                    MainActivity.info("Writing Kml Interrupted: " + e);
                                                    if (cursor2 != null) {
                                                    }
                                                    status = 0;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str72222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str72222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (DBException e7) {
                                                    e = e7;
                                                    cursor = null;
                                                    kmlWriter = this;
                                                    kmlWriter.dbHelper.deathDialog("Writing Kml", e);
                                                    Status status32 = Status.EXCEPTION;
                                                    if (cursor != null) {
                                                    }
                                                    status = status32;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str722222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str722222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (Exception e8) {
                                                    e = e8;
                                                    str2 = str4;
                                                    cursor3 = null;
                                                    kmlWriter = this;
                                                    e.printStackTrace();
                                                    String str622 = str2;
                                                    MainActivity.error(str622 + e, e);
                                                    MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                    Status status222 = Status.EXCEPTION;
                                                    bundle.putString(BackgroundGuiHandler.ERROR, str622 + e);
                                                    if (cursor3 != null) {
                                                    }
                                                    status = status222;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str7222222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str7222222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (Throwable th) {
                                                    th = th;
                                                    status = 0;
                                                    if (status != 0) {
                                                    }
                                                    throw th;
                                                }
                                                try {
                                                    long writeKmlFromCursor3 = writeKmlFromCursor(createFile, singleNetwork, simpleDateFormat2, j4, i3, bundle);
                                                    if (0 == writeKmlFromCursor3) {
                                                        hashSet.add(str9);
                                                        j3 = j2 + 1;
                                                    } else {
                                                        j3 = j2;
                                                    }
                                                    singleNetwork.close();
                                                    if (writeKmlFromCursor3 > 0) {
                                                        j4++;
                                                    }
                                                    kmlWriter = this;
                                                    hashSet2 = hashSet;
                                                    i3 = i;
                                                    str4 = str2;
                                                    str8 = str3;
                                                    simpleDateFormat2 = simpleDateFormat;
                                                } catch (InterruptedException e9) {
                                                    e = e9;
                                                    kmlWriter = this;
                                                    cursor2 = singleNetwork;
                                                    MainActivity.info("Writing Kml Interrupted: " + e);
                                                    if (cursor2 != null) {
                                                    }
                                                    status = 0;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str72222222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str72222222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (DBException e10) {
                                                    e = e10;
                                                    kmlWriter = this;
                                                    cursor = singleNetwork;
                                                    kmlWriter.dbHelper.deathDialog("Writing Kml", e);
                                                    Status status322 = Status.EXCEPTION;
                                                    if (cursor != null) {
                                                    }
                                                    status = status322;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str722222222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722222222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str722222222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (Exception e11) {
                                                    e = e11;
                                                    kmlWriter = this;
                                                    cursor3 = singleNetwork;
                                                    e.printStackTrace();
                                                    String str6222 = str2;
                                                    MainActivity.error(str6222 + e, e);
                                                    MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                    Status status2222 = Status.EXCEPTION;
                                                    bundle.putString(BackgroundGuiHandler.ERROR, str6222 + e);
                                                    if (cursor3 != null) {
                                                    }
                                                    status = status2222;
                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                    createFile.close();
                                                    String str7222222222 = str;
                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222222222);
                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str7222222222);
                                                    MainActivity.info("done with kml export");
                                                    if (status == 0) {
                                                    }
                                                } catch (Throwable th2) {
                                                    th = th2;
                                                    status = singleNetwork;
                                                    if (status != 0) {
                                                    }
                                                    throw th;
                                                }
                                            }
                                            SimpleDateFormat simpleDateFormat3 = simpleDateFormat2;
                                            int i4 = i3;
                                            str2 = str4;
                                            String str10 = str8;
                                            long j5 = j3;
                                            HashSet hashSet3 = hashSet2;
                                            try {
                                                ObservationUploader.writeFos(createFile, "</Folder>\n<Folder><name>Cellular Networks</name>\n");
                                                Iterator it = hashSet3.iterator();
                                                while (it.hasNext()) {
                                                    String str11 = (String) it.next();
                                                    try {
                                                        Cursor singleNetwork2 = this.dbHelper.getSingleNetwork(str11, DatabaseHelper.NetworkFilter.CELL);
                                                        int i5 = i4;
                                                        Iterator it2 = it;
                                                        long j6 = j5;
                                                        kmlWriter = this;
                                                        try {
                                                            long writeKmlFromCursor4 = writeKmlFromCursor(createFile, singleNetwork2, simpleDateFormat3, j4, i5, bundle);
                                                            singleNetwork2.close();
                                                            if (writeKmlFromCursor4 > 0) {
                                                                j4++;
                                                            } else {
                                                                try {
                                                                    MainActivity.warn("unfound cell: [" + str11 + "]");
                                                                } catch (Exception e12) {
                                                                    e = e12;
                                                                    cursor3 = null;
                                                                    e.printStackTrace();
                                                                    String str62222 = str2;
                                                                    MainActivity.error(str62222 + e, e);
                                                                    MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                                    Status status22222 = Status.EXCEPTION;
                                                                    bundle.putString(BackgroundGuiHandler.ERROR, str62222 + e);
                                                                    if (cursor3 != null) {
                                                                    }
                                                                    status = status22222;
                                                                    ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                                    createFile.close();
                                                                    String str72222222222 = str;
                                                                    bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222222222);
                                                                    bundle.putString(BackgroundGuiHandler.FILENAME, str72222222222);
                                                                    MainActivity.info("done with kml export");
                                                                    if (status == 0) {
                                                                    }
                                                                }
                                                            }
                                                            j5 = j6;
                                                            i4 = i5;
                                                            it = it2;
                                                        } catch (Exception e13) {
                                                            e = e13;
                                                            cursor3 = cursor2;
                                                            e.printStackTrace();
                                                            String str622222 = str2;
                                                            MainActivity.error(str622222 + e, e);
                                                            MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                            Status status222222 = Status.EXCEPTION;
                                                            bundle.putString(BackgroundGuiHandler.ERROR, str622222 + e);
                                                            if (cursor3 != null) {
                                                            }
                                                            status = status222222;
                                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                            createFile.close();
                                                            String str722222222222 = str;
                                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722222222222);
                                                            bundle.putString(BackgroundGuiHandler.FILENAME, str722222222222);
                                                            MainActivity.info("done with kml export");
                                                            if (status == 0) {
                                                            }
                                                        }
                                                    } catch (InterruptedException e14) {
                                                        e = e14;
                                                        kmlWriter = this;
                                                        cursor2 = null;
                                                        MainActivity.info("Writing Kml Interrupted: " + e);
                                                        if (cursor2 != null) {
                                                        }
                                                        status = 0;
                                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                        createFile.close();
                                                        String str7222222222222 = str;
                                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222222222222);
                                                        bundle.putString(BackgroundGuiHandler.FILENAME, str7222222222222);
                                                        MainActivity.info("done with kml export");
                                                        if (status == 0) {
                                                        }
                                                    } catch (DBException e15) {
                                                        e = e15;
                                                        kmlWriter = this;
                                                        cursor = null;
                                                        kmlWriter.dbHelper.deathDialog("Writing Kml", e);
                                                        Status status3222 = Status.EXCEPTION;
                                                        if (cursor != null) {
                                                        }
                                                        status = status3222;
                                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                        createFile.close();
                                                        String str72222222222222 = str;
                                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222222222222);
                                                        bundle.putString(BackgroundGuiHandler.FILENAME, str72222222222222);
                                                        MainActivity.info("done with kml export");
                                                        if (status == 0) {
                                                        }
                                                    } catch (Exception e16) {
                                                        e = e16;
                                                        kmlWriter = this;
                                                        cursor3 = null;
                                                        e.printStackTrace();
                                                        String str6222222 = str2;
                                                        MainActivity.error(str6222222 + e, e);
                                                        MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                        Status status2222222 = Status.EXCEPTION;
                                                        bundle.putString(BackgroundGuiHandler.ERROR, str6222222 + e);
                                                        if (cursor3 != null) {
                                                        }
                                                        status = status2222222;
                                                        ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                        createFile.close();
                                                        String str722222222222222 = str;
                                                        bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722222222222222);
                                                        bundle.putString(BackgroundGuiHandler.FILENAME, str722222222222222);
                                                        MainActivity.info("done with kml export");
                                                        if (status == 0) {
                                                        }
                                                    } catch (Throwable th3) {
                                                        th = th3;
                                                        status = 0;
                                                        if (status != 0) {
                                                            status.close();
                                                        }
                                                        throw th;
                                                    }
                                                }
                                                int i6 = i4;
                                                long j7 = j5;
                                                kmlWriter = this;
                                                ObservationUploader.writeFos(createFile, str10);
                                                Set<String> set2 = kmlWriter.btNetworks;
                                                if (set2 != null) {
                                                    Iterator<String> it3 = set2.iterator();
                                                    long j8 = 0;
                                                    while (it3.hasNext()) {
                                                        String next = it3.next();
                                                        singleNetwork = kmlWriter.dbHelper.getSingleNetwork(next, DatabaseHelper.NetworkFilter.BT);
                                                        Iterator<String> it4 = it3;
                                                        try {
                                                            if (0 == writeKmlFromCursor(createFile, singleNetwork, simpleDateFormat3, j4, i6, bundle)) {
                                                                j8++;
                                                                MainActivity.error("unfound BT network: [" + next + "]");
                                                            }
                                                            singleNetwork.close();
                                                            j4++;
                                                            it3 = it4;
                                                        } catch (InterruptedException e17) {
                                                            e = e17;
                                                            cursor2 = singleNetwork;
                                                            MainActivity.info("Writing Kml Interrupted: " + e);
                                                            if (cursor2 != null) {
                                                            }
                                                            status = 0;
                                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                            createFile.close();
                                                            String str7222222222222222 = str;
                                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222222222222222);
                                                            bundle.putString(BackgroundGuiHandler.FILENAME, str7222222222222222);
                                                            MainActivity.info("done with kml export");
                                                            if (status == 0) {
                                                            }
                                                        } catch (DBException e18) {
                                                            e = e18;
                                                            cursor = singleNetwork;
                                                            kmlWriter.dbHelper.deathDialog("Writing Kml", e);
                                                            Status status32222 = Status.EXCEPTION;
                                                            if (cursor != null) {
                                                            }
                                                            status = status32222;
                                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                            createFile.close();
                                                            String str72222222222222222 = str;
                                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222222222222222);
                                                            bundle.putString(BackgroundGuiHandler.FILENAME, str72222222222222222);
                                                            MainActivity.info("done with kml export");
                                                            if (status == 0) {
                                                            }
                                                        } catch (Exception e19) {
                                                            e = e19;
                                                            cursor3 = singleNetwork;
                                                            e.printStackTrace();
                                                            String str62222222 = str2;
                                                            MainActivity.error(str62222222 + e, e);
                                                            MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                                            Status status22222222 = Status.EXCEPTION;
                                                            bundle.putString(BackgroundGuiHandler.ERROR, str62222222 + e);
                                                            if (cursor3 != null) {
                                                            }
                                                            status = status22222222;
                                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                                            createFile.close();
                                                            String str722222222222222222 = str;
                                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str722222222222222222);
                                                            bundle.putString(BackgroundGuiHandler.FILENAME, str722222222222222222);
                                                            MainActivity.info("done with kml export");
                                                            if (status == 0) {
                                                            }
                                                        } catch (Throwable th4) {
                                                            th = th4;
                                                            status = singleNetwork;
                                                            if (status != 0) {
                                                            }
                                                            throw th;
                                                        }
                                                    }
                                                    j = j8;
                                                } else {
                                                    j = 0;
                                                }
                                                StringBuilder append = new StringBuilder().append("Completed; WiFi Fail: ").append(j7).append(" BT Fail: ").append(j).append(" from total count: ").append(i6).append(" (non-bt-networks: ").append(kmlWriter.networks.size()).append(" btnets:");
                                                Set<String> set3 = kmlWriter.btNetworks;
                                                MainActivity.info(append.append(set3 != null ? Integer.valueOf(set3.size()) : "null").append(")").toString());
                                                cursor2 = null;
                                            } catch (InterruptedException e20) {
                                                e = e20;
                                                kmlWriter = this;
                                            } catch (DBException e21) {
                                                e = e21;
                                                kmlWriter = this;
                                            } catch (Exception e22) {
                                                e = e22;
                                                kmlWriter = this;
                                            } catch (Throwable th5) {
                                                th = th5;
                                            }
                                        } catch (Exception e23) {
                                            e = e23;
                                            str2 = str4;
                                            cursor3 = null;
                                            e.printStackTrace();
                                            String str622222222 = str2;
                                            MainActivity.error(str622222222 + e, e);
                                            MainActivity.writeError(kmlWriter, e, kmlWriter.context);
                                            Status status222222222 = Status.EXCEPTION;
                                            bundle.putString(BackgroundGuiHandler.ERROR, str622222222 + e);
                                            if (cursor3 != null) {
                                                cursor3.close();
                                            }
                                            status = status222222222;
                                            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
                                            createFile.close();
                                            String str7222222222222222222 = str;
                                            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str7222222222222222222);
                                            bundle.putString(BackgroundGuiHandler.FILENAME, str7222222222222222222);
                                            MainActivity.info("done with kml export");
                                            if (status == 0) {
                                            }
                                        }
                                    } catch (InterruptedException e24) {
                                        e = e24;
                                    } catch (DBException e25) {
                                        e = e25;
                                    }
                                }
                                status = Status.WRITE_SUCCESS;
                                if (cursor2 != null) {
                                    cursor2.close();
                                }
                            } catch (InterruptedException e26) {
                                e = e26;
                            } catch (DBException e27) {
                                e = e27;
                            }
                        } catch (Throwable th6) {
                            th = th6;
                            status = obj;
                        }
                    } catch (Throwable th7) {
                        th = th7;
                    }
                } catch (Exception e28) {
                    e = e28;
                    str2 = "ex problem: ";
                    str = str5;
                }
            } catch (InterruptedException e29) {
                e = e29;
                str = str5;
            } catch (DBException e30) {
                e = e30;
                str = str5;
            }
            ObservationUploader.writeFos(createFile, "</Folder>\n</Document></kml>");
            createFile.close();
            String str72222222222222222222 = str;
            bundle.putString(BackgroundGuiHandler.FILEPATH, FileUtility.getSDPath() + str72222222222222222222);
            bundle.putString(BackgroundGuiHandler.FILENAME, str72222222222222222222);
            MainActivity.info("done with kml export");
            if (status == 0) {
                kmlWriter.sendBundledMessage(status.ordinal(), bundle);
            }
        } catch (Throwable th8) {
            th = th8;
        }
    }

    private long writeKmlFromCursor(OutputStream outputStream, Cursor cursor, SimpleDateFormat simpleDateFormat, long j, long j2, Bundle bundle) throws IOException, InterruptedException {
        String str;
        long j3;
        KmlWriter kmlWriter = this;
        Cursor cursor2 = cursor;
        cursor.moveToFirst();
        long j4 = j2;
        long j5 = 0;
        while (!cursor.isAfterLast()) {
            if (wasInterrupted()) {
                throw new InterruptedException("we were interrupted");
            }
            String string = cursor2.getString(0);
            String string2 = cursor2.getString(1);
            int i = cursor2.getInt(2);
            String string3 = cursor2.getString(3);
            long j6 = cursor2.getLong(4);
            double d = cursor2.getDouble(5);
            long j7 = j4;
            double d2 = cursor2.getDouble(6);
            int i2 = cursor2.getInt(7);
            long j8 = j5;
            String string4 = cursor2.getString(8);
            String format = kmlWriter.sdf.format(new Date(j6));
            NetworkType typeForCode = NetworkType.typeForCode(string4);
            String str2 = "zeroConfidence";
            if (typeForCode == null) {
                str = "zeroConfidence";
            } else {
                str = "zeroConfidence";
                if (NetworkType.WIFI.equals(typeForCode)) {
                    str2 = string3.contains("WPA") ? "red" : string3.contains("WEP") ? "yellow" : "green";
                } else if (NetworkType.BLE.equals(typeForCode)) {
                    str2 = "ltblue";
                } else if (NetworkType.BT.equals(typeForCode)) {
                    str2 = "blue";
                } else {
                    str2 = (NetworkType.CDMA.equals(typeForCode) || NetworkType.GSM.equals(typeForCode) || NetworkType.LTE.equals(typeForCode) || NetworkType.WCDMA.equals(typeForCode)) ? "pink" : str;
                }
            }
            if (j6 == 0) {
                str2 = str;
            }
            byte[] bytes = string2.getBytes(MainActivity.ENCODING);
            kmlWriter.filterIllegalXml(bytes);
            if (bytes.length == 0) {
                bytes = NO_SSID.getBytes(MainActivity.ENCODING);
            }
            String str3 = str2;
            if (typeForCode.equals(NetworkType.WIFI)) {
                ObservationUploader.writeFos(outputStream, "<Placemark>\n<name><![CDATA[");
                outputStream.write(bytes);
                ObservationUploader.writeFos(outputStream, "]]></name>\n");
                ObservationUploader.writeFos(outputStream, "<description><![CDATA[Network ID: " + string + "\nCapabilities: " + string3 + "\nFrequency: " + i + "\nTimestamp: " + j6 + "\nTime: " + format + "\nSignal: " + i2 + "\nType: " + typeForCode.name() + IOUtils.LINE_SEPARATOR_UNIX + ("Encryption: " + encryptionStringForCapabilities(string3) + IOUtils.LINE_SEPARATOR_UNIX) + "]]></description><styleUrl>#" + str3 + "</styleUrl>\n");
                ObservationUploader.writeFos(outputStream, "<Point>\n");
                ObservationUploader.writeFos(outputStream, "<coordinates>" + d2 + "," + d + "</coordinates>");
                ObservationUploader.writeFos(outputStream, "</Point>\n</Placemark>\n");
            } else if (typeForCode.equals(NetworkType.CDMA) || typeForCode.equals(NetworkType.LTE) || typeForCode.equals(NetworkType.GSM) || typeForCode.equals(NetworkType.WCDMA)) {
                ObservationUploader.writeFos(outputStream, "<Placemark>\n<name><![CDATA[");
                outputStream.write(bytes);
                ObservationUploader.writeFos(outputStream, "]]></name>\n");
                ObservationUploader.writeFos(outputStream, "<description><![CDATA[Network ID: " + string + "\nCapabilities: " + string3 + "\nFrequency: " + i + "\nTimestamp: " + j6 + "\nTime: " + format + "\nSignal: " + i2 + "\nType: " + typeForCode.name() + "]]></description><styleUrl>#" + str3 + "</styleUrl>\n");
                ObservationUploader.writeFos(outputStream, "<Point>\n");
                ObservationUploader.writeFos(outputStream, "<coordinates>" + d2 + "," + d + "</coordinates>");
                ObservationUploader.writeFos(outputStream, "</Point>\n</Placemark>\n");
            } else if (typeForCode.equals(NetworkType.BT) || typeForCode.equals(NetworkType.BLE)) {
                ObservationUploader.writeFos(outputStream, "<Placemark>\n<name><![CDATA[");
                outputStream.write(bytes);
                ObservationUploader.writeFos(outputStream, "]]></name>\n");
                ObservationUploader.writeFos(outputStream, "<description><![CDATA[Network ID: " + string + "\nCapabilities: " + string3 + "\nFrequency: " + i + "\nTimestamp: " + j6 + "\nTime: " + format + "\nSignal: " + i2 + "\nType: " + typeForCode.name() + "]]></description><styleUrl>#" + str3 + "</styleUrl>\n");
                ObservationUploader.writeFos(outputStream, "<Point>\n");
                ObservationUploader.writeFos(outputStream, "<coordinates>" + d2 + "," + d + "</coordinates>");
                ObservationUploader.writeFos(outputStream, "</Point>\n</Placemark>\n");
            } else {
                MainActivity.warn("unknown network type " + typeForCode + "for network: " + string);
            }
            j5 = j8 + 1;
            if (j5 % 1000 == 0) {
                j3 = j7;
                MainActivity.info("lineCount: " + j5 + " of " + j3);
            } else {
                j3 = j7;
            }
            if (j3 == 0) {
                j3 = 1;
            }
            sendPercentTimesTen((int) (((j5 + j) * 1000) / j3), bundle);
            cursor.moveToNext();
            kmlWriter = this;
            j4 = j3;
            cursor2 = cursor;
        }
        return j5;
    }

    private static String encryptionStringForCapabilities(String str) {
        return str.contains("WPA3") ? "WPA3" : str.contains("WPA2") ? "WPA2" : str.contains("WPA") ? "WPA" : str.contains("WEP") ? "WEP" : "Unknown";
    }

    private void filterIllegalXml(byte[] bArr) {
        for (int i = 0; i < bArr.length; i++) {
            byte b = bArr[i];
            if ((b >= 0 && b <= 8) || ((b >= 11 && b <= 31) || ((b >= Byte.MAX_VALUE && b <= 132) || (b >= 134 && b <= 159)))) {
                bArr[i] = 32;
            }
        }
    }
}