Search in sources :

Example 1 with ObservationUploader

use of net.wigle.wigleandroid.background.ObservationUploader in project wigle-wifi-wardriving by wiglenet.

the class MainActivity method finish.

// @Override
@Override
public void finish() {
    info("MAIN: finish. networks: " + state.wifiReceiver.getRunNetworkCount());
    final boolean wasFinishing = state.finishing.getAndSet(true);
    if (wasFinishing) {
        info("MAIN: finish called twice!");
    }
    // interrupt this just in case
    final ObservationUploader observationUploader = state.observationUploader;
    if (observationUploader != null) {
        observationUploader.setInterrupted();
    }
    if (state.gpsListener != null) {
        // save our location for later runs
        state.gpsListener.saveLocation();
    }
    // close the db. not in destroy, because it'll still write after that.
    state.dbHelper.close();
    final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    if (state.gpsListener != null) {
        locationManager.removeGpsStatusListener(state.gpsListener);
        try {
            locationManager.removeUpdates(state.gpsListener);
        } catch (final SecurityException ex) {
            error("SecurityException on finish: " + ex, ex);
        }
    }
    // stop the service, so when we die it's both stopped and unbound and will die
    final Intent serviceIntent = new Intent(this, WigleService.class);
    stopService(serviceIntent);
    try {
        // have to use the app context to bind to the service, cuz we're in tabs
        getApplicationContext().unbindService(state.serviceConnection);
    } catch (final IllegalArgumentException ex) {
        MainActivity.info("serviceConnection not registered: " + ex, ex);
    }
    // release the lock before turning wifi off
    if (state.wifiLock != null && state.wifiLock.isHeld()) {
        try {
            state.wifiLock.release();
        } catch (Exception ex) {
            MainActivity.error("exception releasing wifi lock: " + ex, ex);
        }
    }
    final SharedPreferences prefs = this.getSharedPreferences(ListFragment.SHARED_PREFS, 0);
    final boolean wifiWasOff = prefs.getBoolean(ListFragment.PREF_WIFI_WAS_OFF, false);
    // don't call on emulator, it crashes it
    if (wifiWasOff && !state.inEmulator) {
        // well turn it of now that we're done
        final WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
        MainActivity.info("turning back off wifi");
        try {
            wifiManager.setWifiEnabled(false);
        } catch (Exception ex) {
            MainActivity.error("exception turning wifi back off: " + ex, ex);
        }
    }
    TelephonyManager tele = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
    if (tele != null && state.phoneState != null) {
        tele.listen(state.phoneState, PhoneStateListener.LISTEN_NONE);
    }
    if (state.tts != null) {
        if (!isMuted()) {
            // give time for the above "done" to be said
            sleep(250);
        }
        state.tts.shutdown();
    }
    // clean up.
    if (state.soundPop != null) {
        state.soundPop.release();
    }
    if (state.soundNewPop != null) {
        state.soundNewPop.release();
    }
    super.finish();
}
Also used : LocationManager(android.location.LocationManager) WifiManager(android.net.wifi.WifiManager) SharedPreferences(android.content.SharedPreferences) TelephonyManager(android.telephony.TelephonyManager) ObservationUploader(net.wigle.wigleandroid.background.ObservationUploader) Intent(android.content.Intent) IOException(java.io.IOException)

Example 2 with ObservationUploader

use of net.wigle.wigleandroid.background.ObservationUploader in project wigle-wifi-wardriving by wiglenet.

the class MainActivity method backgroundUploadFile.

/**
 * pure-background upload method fo intent-based uploads
 */
public void backgroundUploadFile() {
    MainActivity.info("background upload file");
    if (this == null) {
        return;
    }
    final State state = getState();
    setTransferring();
    state.observationUploader = new ObservationUploader(this, ListFragment.lameStatic.dbHelper, null, false, false, false);
    try {
        state.observationUploader.startDownload(null);
    } catch (WiGLEAuthException waex) {
        MainActivity.warn("Authentication failure on background run upload");
    }
}
Also used : PhoneState(net.wigle.wigleandroid.listener.PhoneState) ObservationUploader(net.wigle.wigleandroid.background.ObservationUploader)

Example 3 with ObservationUploader

use of net.wigle.wigleandroid.background.ObservationUploader in project wigle-wifi-wardriving by wiglenet.

the class DataFragment method handleDialog.

@SuppressLint("SetTextI18n")
@Override
public void handleDialog(final int dialogId) {
    final SharedPreferences prefs = getActivity().getSharedPreferences(ListFragment.SHARED_PREFS, 0);
    final SharedPreferences.Editor editor = prefs.edit();
    final View view = getView();
    switch(dialogId) {
        case CSV_RUN_DIALOG:
            {
                // actually need this Activity context, for dialogs
                ObservationUploader observationUploader = new ObservationUploader(getActivity(), ListFragment.lameStatic.dbHelper, DataFragment.this, true, false, true);
                observationUploader.start();
                break;
            }
        case CSV_DB_DIALOG:
            {
                ObservationUploader observationUploader = new ObservationUploader(getActivity(), ListFragment.lameStatic.dbHelper, DataFragment.this, true, true, false);
                observationUploader.start();
                break;
            }
        case KML_RUN_DIALOG:
            {
                KmlWriter kmlWriter = new KmlWriter(getActivity(), ListFragment.lameStatic.dbHelper, ListFragment.lameStatic.runNetworks);
                kmlWriter.start();
                break;
            }
        case KML_DB_DIALOG:
            {
                KmlWriter kmlWriter = new KmlWriter(getActivity(), ListFragment.lameStatic.dbHelper);
                kmlWriter.start();
                break;
            }
        case BACKUP_DIALOG:
            {
                BackupTask task = new BackupTask(DataFragment.this, MainActivity.getMainActivity(DataFragment.this));
                task.execute();
                break;
            }
        case IMPORT_DIALOG:
            {
                this.createAndStartImport();
                break;
            }
        case ZERO_OUT_DIALOG:
            {
                editor.putLong(ListFragment.PREF_DB_MARKER, 0L);
                editor.apply();
                if (view != null) {
                    final TextView tv = (TextView) view.findViewById(R.id.reset_maxid_text);
                    tv.setText(getString(R.string.setting_max_id) + " 0");
                }
                break;
            }
        case MAX_OUT_DIALOG:
            {
                final long maxDB = prefs.getLong(ListFragment.PREF_MAX_DB, 0L);
                editor.putLong(ListFragment.PREF_DB_MARKER, maxDB);
                editor.apply();
                if (view != null) {
                    // set the text on the other button
                    final TextView tv = (TextView) view.findViewById(R.id.reset_maxid_text);
                    tv.setText(getString(R.string.setting_max_id) + " " + maxDB);
                }
                break;
            }
        case DELETE_DIALOG:
            {
                // blow away the DB
                ListFragment.lameStatic.dbHelper.clearDatabase();
                // update markers
                editor.putLong(ListFragment.PREF_DB_MARKER, 0L);
                editor.putLong(ListFragment.PREF_DB_MARKER, 0L);
                editor.apply();
                if (view != null) {
                    final TextView tv = (TextView) view.findViewById(R.id.reset_maxid_text);
                    tv.setText(getString(R.string.setting_max_id) + " " + 0L);
                }
                try {
                    ListFragment.lameStatic.dbHelper.getNetworkCountFromDB();
                } catch (DBException dbe) {
                    MainActivity.warn("Failed to update network count on DB clear: ", dbe);
                }
                break;
            }
        default:
            MainActivity.warn("Data unhandled dialogId: " + dialogId);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) ObservationUploader(net.wigle.wigleandroid.background.ObservationUploader) KmlWriter(net.wigle.wigleandroid.background.KmlWriter) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint)

Example 4 with ObservationUploader

use of net.wigle.wigleandroid.background.ObservationUploader in project wigle-wifi-wardriving by wiglenet.

the class ListFragment method uploadFile.

public void uploadFile(final DatabaseHelper dbHelper) {
    MainActivity.info("upload file");
    final MainActivity main = MainActivity.getMainActivity(this);
    if (main == null) {
        return;
    }
    final State state = main.getState();
    main.setTransferring();
    // actually need this Activity context, for dialogs
    // writeEntireDb and writeRun are both false, so PREF_DB_MARKER is used
    state.observationUploader = new ObservationUploader(main, ListFragment.lameStatic.dbHelper, this, false, false, false);
    try {
        state.observationUploader.startDownload(this);
    } catch (WiGLEAuthException waex) {
        MainActivity.warn("Authentication failure on run upload");
    }
}
Also used : State(net.wigle.wigleandroid.MainActivity.State) ObservationUploader(net.wigle.wigleandroid.background.ObservationUploader)

Aggregations

ObservationUploader (net.wigle.wigleandroid.background.ObservationUploader)4 SharedPreferences (android.content.SharedPreferences)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 LocationManager (android.location.LocationManager)1 WifiManager (android.net.wifi.WifiManager)1 TelephonyManager (android.telephony.TelephonyManager)1 View (android.view.View)1 TextView (android.widget.TextView)1 IOException (java.io.IOException)1 State (net.wigle.wigleandroid.MainActivity.State)1 KmlWriter (net.wigle.wigleandroid.background.KmlWriter)1 PhoneState (net.wigle.wigleandroid.listener.PhoneState)1