Java Code Examples for android.os.Process#killProcess()

The following examples show how to use android.os.Process#killProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChromeBrowserInitializer.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private ActivityStateListener createActivityStateListener() {
    return new ActivityStateListener() {
        @Override
        public void onActivityStateChange(Activity activity, int newState) {
            if (newState == ActivityState.CREATED || newState == ActivityState.DESTROYED) {
                // Android destroys Activities at some point after a locale change, but doesn't
                // kill the process.  This can lead to a bug where Chrome is halfway RTL, where
                // stale natively-loaded resources are not reloaded (http://crbug.com/552618).
                if (!mInitialLocale.equals(Locale.getDefault())) {
                    Log.e(TAG, "Killing process because of locale change.");
                    Process.killProcess(Process.myPid());
                }

                DeviceFormFactor.resetValuesIfNeeded(mApplication);
            }
        }
    };
}
 
Example 2
Source File: ExoHelper.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Restart the application by setting a PendingIntent on the AlarmManager and then killing the
 * current process.
 *
 * @param context any current context from the application
 */
public static void restartApp(Context context) {
  Context appContext = context.getApplicationContext();
  final Intent launchIntent =
      appContext
          .getPackageManager()
          .getLaunchIntentForPackage(appContext.getPackageName())
          .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
  // Can be anything so long as it's unique. This part of the sha1sum of "buck"
  int id = 0xe354735f;
  final int flags =
      PendingIntent.FLAG_CANCEL_CURRENT
          | PendingIntent.FLAG_IMMUTABLE
          | PendingIntent.FLAG_ONE_SHOT;
  PendingIntent pendingIntent = PendingIntent.getActivity(appContext, id, launchIntent, flags);
  AlarmManager am = appContext.getSystemService(AlarmManager.class);
  long deadline = System.currentTimeMillis() + 500L;
  am.setExact(AlarmManager.RTC_WAKEUP, deadline, pendingIntent);
  Process.killProcess(Process.myPid());
}
 
Example 3
Source File: DebugSettingsFragment.java    From Android-Keyboard with Apache License 2.0 5 votes vote down vote up
@Override
public void onStop() {
    super.onStop();
    if (mServiceNeedsRestart) {
        Process.killProcess(Process.myPid());
    }
}
 
Example 4
Source File: IApkManagerImpl.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean killBackgroundProcesses(String pluginPackageName) throws RemoteException {
    boolean success = false;
    for (RunningAppProcessInfo info : ((ActivityManager) this.mContext.getSystemService("activity")).getRunningAppProcesses()) {
        if (info.pkgList != null) {
            String[] pkgListCopy = (String[]) Arrays.copyOf(info.pkgList, info.pkgList.length);
            Arrays.sort(pkgListCopy);
            if (Arrays.binarySearch(pkgListCopy, pluginPackageName) >= 0 && info.pid != Process.myPid()) {
                Log.i(TAG, "killBackgroundProcesses(%s),pkgList=%s,pid=%s", pluginPackageName, Arrays.toString(info.pkgList), Integer.valueOf(info.pid));
                Process.killProcess(info.pid);
                success = true;
            }
        }
    }
    return success;
}
 
Example 5
Source File: ContextHolder.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/**
 * Kill midlet process.
 */
public static void notifyDestroyed() {
	MicroActivity activity = currentActivity.get();
	if (activity != null) {
		activity.finish();
	}
	Process.killProcess(Process.myPid());
}
 
Example 6
Source File: RemoteService.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
public void onClick(View v) {
    // To kill the process hosting our service, we need to know its
    // PID.  Conveniently our service has a call that will return
    // to us that information.
    if (mSecondaryService != null) {
        try {
            int pid = mSecondaryService.getPid();
            // Note that, though this API allows us to request to
            // kill any process based on its PID, the kernel will
            // still impose standard restrictions on which PIDs you
            // are actually able to kill.  Typically this means only
            // the process running your application and any additional
            // processes created by that app as shown here; packages
            // sharing a common UID will also be able to kill each
            // other's processes.
            Process.killProcess(pid);
            mCallbackText.setText("Killed service process.");
        } catch (RemoteException ex) {
            // Recover gracefully from the process hosting the
            // server dying.
            // Just for purposes of the sample, put up a notification.
            Toast.makeText(Binding.this,
                    R.string.remote_call_failed,
                    Toast.LENGTH_SHORT).show();
        }
    }
}
 
Example 7
Source File: VirtualRuntime.java    From container with GNU General Public License v3.0 5 votes vote down vote up
public static <T> T crash(RemoteException e) throws RuntimeException {
    e.printStackTrace();
    if (VirtualCore.get().isVAppProcess()) {
        Process.killProcess(Process.myPid());
        System.exit(0);
    }
    throw new DeadServerException(e);
}
 
Example 8
Source File: CrashHandler.java    From letv with Apache License 2.0 5 votes vote down vote up
public void uncaughtException(Thread thread, Throwable ex) {
    try {
        LogInfo.log("king", "uncaughtException");
        throw new Exception(ex);
    } catch (Exception e) {
        e.printStackTrace();
        if (handleException(ex) || this.mDefaultHandler == null) {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e2) {
                LogInfo.log(TAG, "Error : " + e2);
            }
            PreferencesManager.getInstance().setCrashCount(PreferencesManager.getInstance().getCrashCount() + 1);
            if (PreferencesManager.getInstance().getDownloadFlag() != 1) {
                ((NotificationManager) LetvApplication.getInstance().getSystemService("notification")).cancel(1000);
            }
            DownloadManager.pauseAllDownload();
            LetvCacheMannager.getInstance().destroy();
            if (LetvConfig.isUmeng()) {
                MobclickAgent.onKillProcess(LetvApplication.getInstance());
            }
            Process.killProcess(Process.myPid());
            System.exit(1);
            return;
        }
        this.mDefaultHandler.uncaughtException(thread, ex);
        PreferencesManager.getInstance().setCrashCount(PreferencesManager.getInstance().getCrashCount() + 1);
    }
}
 
Example 9
Source File: CrashHandler.java    From FimiX8-RE with MIT License 5 votes vote down vote up
public void uncaughtException(Thread thread, Throwable ex) {
    if (handleException(ex) || this.mDefaultHandler == null) {
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            Log.e(TAG, "error : ", e);
        }
        Process.killProcess(Process.myPid());
        System.exit(1);
        return;
    }
    this.mDefaultHandler.uncaughtException(thread, ex);
}
 
Example 10
Source File: SongBroadCast.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
public void disableContext(Context context) {
    NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(context);
    notificationManagerCompat.cancel(1);
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.O) {
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.deleteNotificationChannel("channel_01");
    }
    Process.killProcess(Process.myPid());
}
 
Example 11
Source File: InformaActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
public void wipe()
{
	String action = PreferenceManager.getDefaultSharedPreferences(this).getString(Preferences.Keys.PANIC_ACTION, "0");
	boolean wipeEntireApp = (Integer.parseInt(action) == 1);
	
	dataWipe();
	if (wipeEntireApp)
	{
		deleteApp();
	}
	else
	{
		Process.killProcess(Process.myPid());
	}
}
 
Example 12
Source File: TaskController.java    From batteryhub with Apache License 2.0 5 votes vote down vote up
public void killApp(final Task task) {
    ActivityManager activityManager = (ActivityManager)
            mContext.getSystemService(Context.ACTIVITY_SERVICE);
    activityManager.killBackgroundProcesses(task.getPackageInfo().packageName);
    for (int pid : task.getProcesses()) {
        Process.killProcess(pid);
    }
}
 
Example 13
Source File: ExoMetaLogActivity.java    From buck with Apache License 2.0 5 votes vote down vote up
@Override
public void onDestroy() {
  super.onDestroy();

  // Workaround for the fact that that "am force-stop" doesn't work on Gingerbread.
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
    Process.killProcess(Process.myPid());
  }
}
 
Example 14
Source File: SecurityBundleListner.java    From ACDD with MIT License 4 votes vote down vote up
@Override
public void handleMessage(Message message) {
    Process.killProcess(Process.myPid());
}
 
Example 15
Source File: MiddlewareActivity.java    From freeline with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void run() {

            //通过定时器启动提高重新启动应用的成功率
            Context context = MiddlewareActivity.this;

            Intent intent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

            AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            mgr.set(AlarmManager.RTC, System.currentTimeMillis() + DELAY_TIME, pendingIntent);

            Log.d(TAG, "kill process: " + Process.myPid());
            Process.killProcess(Process.myPid());
        }
 
Example 16
Source File: ChildProcessServiceImpl.java    From 365browser with Apache License 2.0 4 votes vote down vote up
@Override
public void crashIntentionallyForTesting() {
    Process.killProcess(Process.myPid());
}
 
Example 17
Source File: ServiceStartArguments.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onClick(View v) {
    // This is to simulate the service being killed while it is
    // running in the background.
    Process.killProcess(Process.myPid());
}
 
Example 18
Source File: SecurityFrameListener.java    From AtlasForAndroid with MIT License 4 votes vote down vote up
public void handleMessage(Message message) {
    Process.killProcess(Process.myPid());
}
 
Example 19
Source File: AppErrors.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean handleAppCrashInActivityController(ProcessRecord r,
                                                   ApplicationErrorReport.CrashInfo crashInfo,
                                                   String shortMsg, String longMsg,
                                                   String stackTrace, long timeMillis,
                                                   int callingPid, int callingUid) {
    if (mService.mController == null) {
        return false;
    }

    try {
        String name = r != null ? r.processName : null;
        int pid = r != null ? r.pid : callingPid;
        int uid = r != null ? r.info.uid : callingUid;
        if (!mService.mController.appCrashed(name, pid,
                shortMsg, longMsg, timeMillis, crashInfo.stackTrace)) {
            if ("1".equals(SystemProperties.get(SYSTEM_DEBUGGABLE, "0"))
                    && "Native crash".equals(crashInfo.exceptionClassName)) {
                Slog.w(TAG, "Skip killing native crashed app " + name
                        + "(" + pid + ") during testing");
            } else {
                Slog.w(TAG, "Force-killing crashed app " + name
                        + " at watcher's request");
                if (r != null) {
                    if (!makeAppCrashingLocked(r, shortMsg, longMsg, stackTrace, null))
                    {
                        r.kill("crash", true);
                    }
                } else {
                    // Huh.
                    Process.killProcess(pid);
                    ActivityManagerService.killProcessGroup(uid, pid);
                }
            }
            return true;
        }
    } catch (RemoteException e) {
        mService.mController = null;
        Watchdog.getInstance().setActivityController(null);
    }
    return false;
}
 
Example 20
Source File: HuluCrashHandler.java    From SoloPi with Apache License 2.0 4 votes vote down vote up
@Override
public void onAppCrash(Thread t, Throwable e) {
    Process.killProcess(Process.myPid());
}