public void onDestroy() { running = false; if (scanThread != null) scanThread.interrupt(); if (myWLocate != null) myWLocate.doPause(); sensorManager.unregisterListener( this, sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER)); if (scanData.getmView() != null) { ((WindowManager) getSystemService(WINDOW_SERVICE)).removeView(scanData.getmView()); scanData.setmView(null); } try { if (wl != null) wl.release(); } catch (RuntimeException re) { } wl = null; try { scanThread.join(1000); } catch (InterruptedException ie) { } System.exit(0); }
private void checkAndLaunchUpdate() { Log.i(LOG_FILE_NAME, "Checking for an update"); int statusCode = 8; // UNEXPECTED_ERROR File baseUpdateDir = null; if (Build.VERSION.SDK_INT >= 8) baseUpdateDir = getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS); else baseUpdateDir = new File(Environment.getExternalStorageDirectory().getPath(), "download"); File updateDir = new File(new File(baseUpdateDir, "updates"), "0"); File updateFile = new File(updateDir, "update.apk"); File statusFile = new File(updateDir, "update.status"); if (!statusFile.exists() || !readUpdateStatus(statusFile).equals("pending")) return; if (!updateFile.exists()) return; Log.i(LOG_FILE_NAME, "Update is available!"); // Launch APK File updateFileToRun = new File(updateDir, getPackageName() + "-update.apk"); try { if (updateFile.renameTo(updateFileToRun)) { String amCmd = "/system/bin/am start -a android.intent.action.VIEW " + "-n com.android.packageinstaller/.PackageInstallerActivity -d file://" + updateFileToRun.getPath(); Log.i(LOG_FILE_NAME, amCmd); Runtime.getRuntime().exec(amCmd); statusCode = 0; // OK } else { Log.i(LOG_FILE_NAME, "Cannot rename the update file!"); statusCode = 7; // WRITE_ERROR } } catch (Exception e) { Log.i(LOG_FILE_NAME, "error launching installer to update", e); } // Update the status file String status = statusCode == 0 ? "succeeded\n" : "failed: " + statusCode + "\n"; OutputStream outStream; try { byte[] buf = status.getBytes("UTF-8"); outStream = new FileOutputStream(statusFile); outStream.write(buf, 0, buf.length); outStream.close(); } catch (Exception e) { Log.i(LOG_FILE_NAME, "error writing status file", e); } if (statusCode == 0) System.exit(0); }
@Override protected void onNewIntent(Intent intent) { if (checkLaunchState(LaunchState.GeckoExiting)) { // We're exiting and shouldn't try to do anything else just incase // we're hung for some reason we'll force the process to exit System.exit(0); return; } final String action = intent.getAction(); if (ACTION_DEBUG.equals(action) && checkAndSetLaunchState(LaunchState.Launching, LaunchState.WaitForDebugger)) { mMainHandler.postDelayed( new Runnable() { public void run() { Log.i(LOG_FILE_NAME, "Launching from debug intent after 5s wait"); setLaunchState(LaunchState.Launching); launch(null); } }, 1000 * 5 /* 5 seconds */); Log.i(LOG_FILE_NAME, "Intent : ACTION_DEBUG - waiting 5s before launching"); return; } if (checkLaunchState(LaunchState.WaitForDebugger) || launch(intent)) return; if (Intent.ACTION_MAIN.equals(action)) { Log.i(LOG_FILE_NAME, "Intent : ACTION_MAIN"); GeckoAppShell.sendEventToGecko(new GeckoEvent("")); } else if (Intent.ACTION_VIEW.equals(action)) { String uri = intent.getDataString(); GeckoAppShell.sendEventToGecko(new GeckoEvent(uri)); Log.i(LOG_FILE_NAME, "onNewIntent: " + uri); } else if (ACTION_WEBAPP.equals(action)) { String uri = intent.getStringExtra("args"); GeckoAppShell.sendEventToGecko(new GeckoEvent(uri)); Log.i(LOG_FILE_NAME, "Intent : WEBAPP - " + uri); } else if (ACTION_BOOKMARK.equals(action)) { String args = intent.getStringExtra("args"); GeckoAppShell.sendEventToGecko(new GeckoEvent(args)); Log.i(LOG_FILE_NAME, "Intent : BOOKMARK - " + args); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.offline: if (prefs.getBoolean("hideOffline", false)) service.setPreference("hideOffline", false); else service.setPreference("hideOffline", true); updateMenu(); updateList(); break; case R.id.status: RosterDialogs.changeStatusDialog(this, null, null); break; case android.R.id.home: RosterDialogs.changeStatusDialog(this, null, null); break; case R.id.add: RosterDialogs.addDialog(this, null); break; case R.id.search: menu.removeItem(R.id.chats); item.expandActionView(); break; case R.id.bookmarks: Intent bIntent = new Intent(this, Bookmarks.class); startActivity(bIntent); break; case R.id.chats: ChangeChatDialog.show(this); break; case R.id.accounts: Intent aIntent = new Intent(this, Accounts.class); startActivity(aIntent); break; case R.id.prefs: startActivityForResult(new Intent(this, Preferences.class), ACTIVITY_PREFERENCES); break; case R.id.disco: startActivity(new Intent(this, ServiceDiscovery.class)); break; case R.id.notes: startActivity(new Intent(this, NotesActivity.class)); break; case R.id.xml: startActivity(new Intent(this, XMLConsole.class)); break; case R.id.notify: if (prefs.getBoolean("soundDisabled", false)) service.setPreference("soundDisabled", false); else service.setPreference("soundDisabled", true); updateMenu(); break; case R.id.exit: if (prefs.getBoolean("DeleteHistory", false)) { getContentResolver().delete(JTalkProvider.CONTENT_URI, null, null); } Notify.cancelAll(this); stopService(new Intent(this, JTalkService.class)); finish(); System.exit(0); break; default: return false; } return true; }
public void forceQuit() { System.exit(0); }