Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 493f2bd8 authored by Dianne Hackborn's avatar Dianne Hackborn Committed by Android (Google) Code Review
Browse files

Merge "Add more details about why a force stop is happening."

parents 5b5d1096 21d9b566
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -1410,7 +1410,8 @@ public abstract class ActivityManagerNative extends Binder implements IActivityM
            data.enforceInterface(IActivityManager.descriptor);
            String pkg = data.readString();
            int appid = data.readInt();
            killApplicationWithAppId(pkg, appid);
            String reason = data.readString();
            killApplicationWithAppId(pkg, appid, reason);
            reply.writeNoException();
            return true;
        }
@@ -3692,12 +3693,14 @@ class ActivityManagerProxy implements IActivityManager
        data.recycle();
    }
    
    public void killApplicationWithAppId(String pkg, int appid) throws RemoteException {
    public void killApplicationWithAppId(String pkg, int appid, String reason)
            throws RemoteException {
        Parcel data = Parcel.obtain();
        Parcel reply = Parcel.obtain();
        data.writeInterfaceToken(IActivityManager.descriptor);
        data.writeString(pkg);
        data.writeInt(appid);
        data.writeString(reason);
        mRemote.transact(KILL_APPLICATION_WITH_APPID_TRANSACTION, data, reply, 0);
        reply.readException();
        data.recycle();
+2 −1
Original line number Diff line number Diff line
@@ -283,7 +283,8 @@ public interface IActivityManager extends IInterface {
    public void stopAppSwitches() throws RemoteException;
    public void resumeAppSwitches() throws RemoteException;
    
    public void killApplicationWithAppId(String pkg, int appid) throws RemoteException;
    public void killApplicationWithAppId(String pkg, int appid, String reason)
            throws RemoteException;
    
    public void closeSystemDialogs(String reason) throws RemoteException;
    
+36 −24
Original line number Diff line number Diff line
@@ -1226,9 +1226,11 @@ public final class ActivityManagerService extends ActivityManagerNative
                synchronized (ActivityManagerService.this) {
                    int appid = msg.arg1;
                    boolean restart = (msg.arg2 == 1);
                    String pkg = (String) msg.obj;
                    Bundle bundle = (Bundle)msg.obj;
                    String pkg = bundle.getString("pkg");
                    String reason = bundle.getString("reason");
                    forceStopPackageLocked(pkg, appid, restart, false, true, false,
                            UserHandle.USER_ALL);
                            UserHandle.USER_ALL, reason);
                }
            } break;
            case FINALIZE_PENDING_INTENT_MSG: {
@@ -3620,7 +3622,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                        android.Manifest.permission.CLEAR_APP_USER_DATA,
                        pid, uid, -1, true)
                        == PackageManager.PERMISSION_GRANTED) {
                    forceStopPackageLocked(packageName, pkgUid);
                    forceStopPackageLocked(packageName, pkgUid, "clear data");
                } else {
                    throw new SecurityException(pid+" does not have permission:"+
                            android.Manifest.permission.CLEAR_APP_USER_DATA+" to clear data" +
@@ -3739,7 +3741,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            Slog.w(TAG, msg);
            throw new SecurityException(msg);
        }
        userId = handleIncomingUser(Binder.getCallingPid(), Binder.getCallingUid(),
        final int callingPid = Binder.getCallingPid();
        userId = handleIncomingUser(callingPid, Binder.getCallingUid(),
                userId, true, true, "forceStopPackage", null);
        long callingId = Binder.clearCallingIdentity();
        try {
@@ -3765,7 +3768,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                                + packageName + ": " + e);
                    }
                    if (isUserRunningLocked(user, false)) {
                        forceStopPackageLocked(packageName, pkgUid);
                        forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid);
                    }
                }
            }
@@ -3778,7 +3781,7 @@ public final class ActivityManagerService extends ActivityManagerNative
     * The pkg name and app id have to be specified.
     */
    @Override
    public void killApplicationWithAppId(String pkg, int appid) {
    public void killApplicationWithAppId(String pkg, int appid, String reason) {
        if (pkg == null) {
            return;
        }
@@ -3794,7 +3797,10 @@ public final class ActivityManagerService extends ActivityManagerNative
            Message msg = mHandler.obtainMessage(KILL_APPLICATION_MSG);
            msg.arg1 = appid;
            msg.arg2 = 0;
            msg.obj = pkg;
            Bundle bundle = new Bundle();
            bundle.putString("pkg", pkg);
            bundle.putString("reason", reason);
            msg.obj = bundle;
            mHandler.sendMessage(msg);
        } else {
            throw new SecurityException(callerUid + " cannot kill pkg: " +
@@ -3896,9 +3902,9 @@ public final class ActivityManagerService extends ActivityManagerNative
        }
    }
    private void forceStopPackageLocked(final String packageName, int uid) {
    private void forceStopPackageLocked(final String packageName, int uid, String reason) {
        forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false,
                false, true, false, UserHandle.getUserId(uid));
                false, true, false, UserHandle.getUserId(uid), reason);
        Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED,
                Uri.fromParts("package", packageName, null));
        if (!mProcessesReady) {
@@ -3913,8 +3919,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                MY_PID, Process.SYSTEM_UID, UserHandle.getUserId(uid));
    }
    private void forceStopUserLocked(int userId) {
        forceStopPackageLocked(null, -1, false, false, true, false, userId);
    private void forceStopUserLocked(int userId, String reason) {
        forceStopPackageLocked(null, -1, false, false, true, false, userId, reason);
        Intent intent = new Intent(Intent.ACTION_USER_STOPPED);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY
                | Intent.FLAG_RECEIVER_FOREGROUND);
@@ -3996,7 +4002,7 @@ public final class ActivityManagerService extends ActivityManagerNative
    private final boolean forceStopPackageLocked(String name, int appId,
            boolean callerWillRestart, boolean purgeCache, boolean doit,
            boolean evenPersistent, int userId) {
            boolean evenPersistent, int userId, String reason) {
        int i;
        int N;
@@ -4014,10 +4020,10 @@ public final class ActivityManagerService extends ActivityManagerNative
        if (doit) {
            if (name != null) {
                Slog.i(TAG, "Force stopping package " + name + " appid=" + appId
                        + " user=" + userId);
                Slog.i(TAG, "Force stopping " + name + " appid=" + appId
                        + " user=" + userId + ": " + reason);
            } else {
                Slog.i(TAG, "Force stopping user " + userId);
                Slog.i(TAG, "Force stopping u" + userId + ": " + reason);
            }
            Iterator<SparseArray<Long>> badApps = mProcessCrashTimes.getMap().values().iterator();
@@ -4051,7 +4057,7 @@ public final class ActivityManagerService extends ActivityManagerNative
        boolean didSomething = killPackageProcessesLocked(name, appId, userId,
                -100, callerWillRestart, true, doit, evenPersistent,
                name == null ? ("force stop user " + userId) : ("force stop " + name));
                name == null ? ("stop user " + userId) : ("stop " + name));
        if (mStackSupervisor.forceStopPackageLocked(name, doit, evenPersistent, userId)) {
            if (!doit) {
@@ -4535,7 +4541,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                if (pkgs != null) {
                    for (String pkg : pkgs) {
                        synchronized (ActivityManagerService.this) {
                            if (forceStopPackageLocked(pkg, -1, false, false, false, false, 0)) {
                            if (forceStopPackageLocked(pkg, -1, false, false, false, false, 0,
                                    "finished booting")) {
                                setResultCode(Activity.RESULT_OK);
                                return;
                            }
@@ -7546,7 +7553,7 @@ public final class ActivityManagerService extends ActivityManagerNative
            if (packageName != null) {
                final long origId = Binder.clearCallingIdentity();
                forceStopPackageLocked(packageName, -1, false, false, true, true,
                        UserHandle.USER_ALL);
                        UserHandle.USER_ALL, "set debug app");
                Binder.restoreCallingIdentity(origId);
            }
        }
@@ -11976,7 +11983,8 @@ public final class ActivityManagerService extends ActivityManagerNative
                        String list[] = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST);
                        if (list != null && (list.length > 0)) {
                            for (String pkg : list) {
                                forceStopPackageLocked(pkg, -1, false, true, true, false, userId);
                                forceStopPackageLocked(pkg, -1, false, true, true, false, userId,
                                        "storage unmount");
                            }
                            sendPackageBroadcastLocked(
                                    IApplicationThread.EXTERNAL_STORAGE_UNAVAILABLE, list, userId);
@@ -11985,12 +11993,14 @@ public final class ActivityManagerService extends ActivityManagerNative
                        Uri data = intent.getData();
                        String ssp;
                        if (data != null && (ssp=data.getSchemeSpecificPart()) != null) {
                            boolean removed = Intent.ACTION_PACKAGE_REMOVED.equals(
                                    intent.getAction());
                            if (!intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false)) {
                                forceStopPackageLocked(ssp,
                                        intent.getIntExtra(Intent.EXTRA_UID, -1), false, true, true,
                                        false, userId);
                                        false, userId, removed ? "pkg removed" : "pkg changed");
                            }
                            if (Intent.ACTION_PACKAGE_REMOVED.equals(intent.getAction())) {
                            if (removed) {
                                sendPackageBroadcastLocked(IApplicationThread.PACKAGE_REMOVED,
                                        new String[] {ssp}, userId);
                                if (!intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)) {
@@ -12462,7 +12472,8 @@ public final class ActivityManagerService extends ActivityManagerNative
            final long origId = Binder.clearCallingIdentity();
            // Instrumentation can kill and relaunch even persistent processes
            forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, userId);
            forceStopPackageLocked(ii.targetPackage, -1, true, false, true, true, userId,
                    "start instr");
            ProcessRecord app = addAppLocked(ai, false);
            app.instrumentationClass = className;
            app.instrumentationInfo = ai;
@@ -12529,7 +12540,8 @@ public final class ActivityManagerService extends ActivityManagerNative
        app.instrumentationProfileFile = null;
        app.instrumentationArguments = null;
        forceStopPackageLocked(app.info.packageName, -1, false, false, true, true, app.userId);
        forceStopPackageLocked(app.info.packageName, -1, false, false, true, true, app.userId,
                "finished inst");
    }
    public void finishInstrumentation(IApplicationThread target,
@@ -14808,7 +14820,7 @@ public final class ActivityManagerService extends ActivityManagerNative
                // Clean up all state and processes associated with the user.
                // Kill all the processes for the user.
                forceStopUserLocked(userId);
                forceStopUserLocked(userId, "finish user");
            }
        }
+6 −6
Original line number Diff line number Diff line
@@ -4545,7 +4545,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        // version of the application while the new one gets installed.
        if ((parseFlags & PackageManager.INSTALL_REPLACE_EXISTING) != 0) {
            killApplication(pkg.applicationInfo.packageName,
                        pkg.applicationInfo.uid);
                        pkg.applicationInfo.uid, "update pkg");
        }

        // Also need to kill any apps that are dependent on the library.
@@ -4553,7 +4553,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            for (int i=0; i<clientLibPkgs.size(); i++) {
                PackageParser.Package clientPkg = clientLibPkgs.get(i);
                killApplication(clientPkg.applicationInfo.packageName,
                        clientPkg.applicationInfo.uid);
                        clientPkg.applicationInfo.uid, "update lib");
            }
        }

@@ -4903,14 +4903,14 @@ public class PackageManagerService extends IPackageManager.Stub {
        return NativeLibraryHelper.copyNativeBinariesIfNeededLI(scanFile, nativeLibraryDir);
    }

    private void killApplication(String pkgName, int appId) {
    private void killApplication(String pkgName, int appId, String reason) {
        // Request the ActivityManager to kill the process(only for existing packages)
        // so that we do not end up in a confused state while the user is still using the older
        // version of the application while the new one gets installed.
        IActivityManager am = ActivityManagerNative.getDefault();
        if (am != null) {
            try {
                am.killApplicationWithAppId(pkgName, appId);
                am.killApplicationWithAppId(pkgName, appId, reason);
            } catch (RemoteException e) {
            }
        }
@@ -8273,7 +8273,7 @@ public class PackageManagerService extends IPackageManager.Stub {
            }
        }

        killApplication(packageName, oldPkg.applicationInfo.uid);
        killApplication(packageName, oldPkg.applicationInfo.uid, "replace sys pkg");

        res.removedInfo.uid = oldPkg.applicationInfo.uid;
        res.removedInfo.removedPackage = packageName;
@@ -9078,7 +9078,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        } else {
            if (DEBUG_REMOVE) Slog.d(TAG, "Removing non-system package:" + ps.name);
            // Kill application pre-emptively especially for apps on sd.
            killApplication(packageName, ps.appId);
            killApplication(packageName, ps.appId, "uninstall pkg");
            ret = deleteInstalledPackageLI(ps, deleteCodeAndResources, flags,
                    allUserHandles, perUserInstalled,
                    outInfo, writeSettings);