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

Commit f052b987 authored by Marc Kassis's avatar Marc Kassis Committed by Android (Google) Code Review
Browse files

Merge "Add Reason and Sub-reasons for Application exit."

parents 6de81fd2 dd9e1d94
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -5153,6 +5153,8 @@ package android.app {
    field public static final int REASON_INITIALIZATION_FAILURE = 7; // 0x7
    field public static final int REASON_LOW_MEMORY = 3; // 0x3
    field public static final int REASON_OTHER = 13; // 0xd
    field public static final int REASON_PACKAGE_STATE_CHANGE = 15; // 0xf
    field public static final int REASON_PACKAGE_UPDATED = 16; // 0x10
    field public static final int REASON_PERMISSION_CHANGE = 8; // 0x8
    field public static final int REASON_SIGNALED = 2; // 0x2
    field public static final int REASON_UNKNOWN = 0; // 0x0
+32 −0
Original line number Diff line number Diff line
@@ -133,6 +133,10 @@ public final class ApplicationExitInfo implements Parcelable {
     * Application process was killed because of the user request, for example,
     * user clicked the "Force stop" button of the application in the Settings,
     * or removed the application away from Recents.
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE}, one of the uses of this
     * reason was to indicate that an app was killed due to it being updated or any of its component
     * states have changed without {@link android.content.pm.PackageManager#DONT_KILL_APP}
     */
    public static final int REASON_USER_REQUESTED = 10;

@@ -161,6 +165,23 @@ public final class ApplicationExitInfo implements Parcelable {
     */
    public static final int REASON_FREEZER = 14;

    /**
     * Application process was killed because the app was disabled, or any of its
     * component states have changed without {@link android.content.pm.PackageManager#DONT_KILL_APP}
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * {@link #REASON_USER_REQUESTED} was used to indicate that an app was updated.
     */
    public static final int REASON_PACKAGE_STATE_CHANGE = 15;

    /**
     * Application process was killed because it was updated.
     * <p>
     * Prior to {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * {@link #REASON_USER_REQUESTED} was used to indicate that an app was updated.
     */
    public static final int REASON_PACKAGE_UPDATED = 16;

    /**
     * Application process kills subreason is unknown.
     *
@@ -403,6 +424,11 @@ public final class ApplicationExitInfo implements Parcelable {
     * {@link #REASON_USER_REQUESTED}.
     *
     * For internal use only.
     *
     * @deprecated starting {@link android.os.Build.VERSION_CODES#UPSIDE_DOWN_CAKE},
     * an app being killed due to a package update will have the reason
     * {@link #REASON_PACKAGE_UPDATED}
     *
     * @hide
     */
    public static final int SUBREASON_PACKAGE_UPDATE = 25;
@@ -566,6 +592,8 @@ public final class ApplicationExitInfo implements Parcelable {
        REASON_DEPENDENCY_DIED,
        REASON_OTHER,
        REASON_FREEZER,
        REASON_PACKAGE_STATE_CHANGE,
        REASON_PACKAGE_UPDATED,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Reason {}
@@ -1246,6 +1274,10 @@ public final class ApplicationExitInfo implements Parcelable {
                return "OTHER KILLS BY SYSTEM";
            case REASON_FREEZER:
                return "FREEZER";
            case REASON_PACKAGE_STATE_CHANGE:
                return "STATE CHANGE";
            case REASON_PACKAGE_UPDATED:
                return "PACKAGE UPDATED";
            default:
                return "UNKNOWN";
        }
+2 −1
Original line number Diff line number Diff line
@@ -311,7 +311,8 @@ interface IActivityManager {
    int handleIncomingUser(int callingPid, int callingUid, int userId, boolean allowAll,
            boolean requireFull, in String name, in String callerPackage);
    void addPackageDependency(in String packageName);
    void killApplication(in String pkg, int appId, int userId, in String reason);
    void killApplication(in String pkg, int appId, int userId, in String reason,
            int exitInfoReason);
    @UnsupportedAppUsage
    void closeSystemDialogs(in String reason);
    @UnsupportedAppUsage
+53 −19
Original line number Diff line number Diff line
@@ -1794,11 +1794,13 @@ public class ActivityManagerService extends IActivityManager.Stub
                synchronized (ActivityManagerService.this) {
                    final int appId = msg.arg1;
                    final int userId = msg.arg2;
                    Bundle bundle = (Bundle) msg.obj;
                    String pkg = bundle.getString("pkg");
                    String reason = bundle.getString("reason");
                    SomeArgs args = (SomeArgs) msg.obj;
                    String pkg = (String) args.arg1;
                    String reason = (String) args.arg2;
                    int exitInfoReason = (int) args.arg3;
                    args.recycle();
                    forceStopPackageLocked(pkg, appId, false, false, true, false,
                            false, userId, reason);
                            false, userId, reason, exitInfoReason);
                }
            } break;
@@ -4211,7 +4213,8 @@ public class ActivityManagerService extends IActivityManager.Stub
     * The pkg name and app id have to be specified.
     */
    @Override
    public void killApplication(String pkg, int appId, int userId, String reason) {
    public void killApplication(String pkg, int appId, int userId, String reason,
            int exitInfoReason) {
        if (pkg == null) {
            return;
        }
@@ -4227,10 +4230,11 @@ public class ActivityManagerService extends IActivityManager.Stub
            Message msg = mHandler.obtainMessage(KILL_APPLICATION_MSG);
            msg.arg1 = appId;
            msg.arg2 = userId;
            Bundle bundle = new Bundle();
            bundle.putString("pkg", pkg);
            bundle.putString("reason", reason);
            msg.obj = bundle;
            SomeArgs args = SomeArgs.obtain();
            args.arg1 = pkg;
            args.arg2 = reason;
            args.arg3 = exitInfoReason;
            msg.obj = args;
            mHandler.sendMessage(msg);
        } else {
            throw new SecurityException(callerUid + " cannot kill pkg: " +
@@ -4620,7 +4624,20 @@ public class ActivityManagerService extends IActivityManager.Stub
    @GuardedBy("this")
    final boolean forceStopPackageLocked(String packageName, int appId,
            boolean callerWillRestart, boolean purgeCache, boolean doit,
            boolean evenPersistent, boolean uninstalling, int userId, String reason) {
            boolean evenPersistent, boolean uninstalling, int userId, String reasonString) {
        int reason = packageName == null ? ApplicationExitInfo.REASON_USER_STOPPED
                : ApplicationExitInfo.REASON_USER_REQUESTED;
        return forceStopPackageLocked(packageName, appId, callerWillRestart, purgeCache, doit,
                evenPersistent, uninstalling, userId, reasonString, reason);
    }
    @GuardedBy("this")
    final boolean forceStopPackageLocked(String packageName, int appId,
            boolean callerWillRestart, boolean purgeCache, boolean doit,
            boolean evenPersistent, boolean uninstalling, int userId, String reasonString,
            int reason) {
        int i;
        if (userId == UserHandle.USER_ALL && packageName == null) {
@@ -4636,9 +4653,9 @@ public class ActivityManagerService extends IActivityManager.Stub
        if (doit) {
            if (packageName != null) {
                Slog.i(TAG, "Force stopping " + packageName + " appid=" + appId
                        + " user=" + userId + ": " + reason);
                        + " user=" + userId + ": " + reasonString);
            } else {
                Slog.i(TAG, "Force stopping u" + userId + ": " + reason);
                Slog.i(TAG, "Force stopping u" + userId + ": " + reasonString);
            }
            mAppErrors.resetProcessCrashTime(packageName == null, appId, userId);
@@ -4650,15 +4667,20 @@ public class ActivityManagerService extends IActivityManager.Stub
            // becomes visible when killing its other processes with visible activities.
            didSomething = mAtmInternal.onForceStopPackage(
                    packageName, doit, evenPersistent, userId);
            int subReason;
            if (reason == ApplicationExitInfo.REASON_USER_REQUESTED) {
                subReason = ApplicationExitInfo.SUBREASON_FORCE_STOP;
            } else {
                subReason = ApplicationExitInfo.SUBREASON_UNKNOWN;
            }
            didSomething |= mProcessList.killPackageProcessesLSP(packageName, appId, userId,
                    ProcessList.INVALID_ADJ, callerWillRestart, false /* allowRestart */, doit,
                    evenPersistent, true /* setRemoved */, uninstalling,
                    packageName == null ? ApplicationExitInfo.REASON_USER_STOPPED
                    : ApplicationExitInfo.REASON_USER_REQUESTED,
                    ApplicationExitInfo.SUBREASON_FORCE_STOP,
                    reason,
                    subReason,
                    (packageName == null ? ("stop user " + userId) : ("stop " + packageName))
                    + " due to " + reason);
                    + " due to " + reasonString);
        }
        if (mServices.bringDownDisabledPackageServicesLocked(
@@ -14401,12 +14423,13 @@ public class ActivityManagerService extends IActivityManager.Stub
                                final boolean killProcess =
                                        !intent.getBooleanExtra(Intent.EXTRA_DONT_KILL_APP, false);
                                final boolean fullUninstall = removed && !replacing;
                                if (removed) {
                                    if (killProcess) {
                                        forceStopPackageLocked(ssp, UserHandle.getAppId(
                                                intent.getIntExtra(Intent.EXTRA_UID, -1)),
                                                false, true, true, false, fullUninstall, userId,
                                                removed ? "pkg removed" : "pkg changed");
                                                "pkg removed");
                                        getPackageManagerInternal()
                                                .onPackageProcessKilledForUninstall(ssp);
                                    } else {
@@ -14437,14 +14460,25 @@ public class ActivityManagerService extends IActivityManager.Stub
                                    }
                                } else {
                                    if (killProcess) {
                                        int reason;
                                        int subReason;
                                        if (replacing) {
                                            reason = ApplicationExitInfo.REASON_PACKAGE_UPDATED;
                                            subReason = ApplicationExitInfo.SUBREASON_UNKNOWN;
                                        } else {
                                            reason =
                                                    ApplicationExitInfo.REASON_PACKAGE_STATE_CHANGE;
                                            subReason = ApplicationExitInfo.SUBREASON_UNKNOWN;
                                        }
                                        final int extraUid = intent.getIntExtra(Intent.EXTRA_UID,
                                                -1);
                                        synchronized (mProcLock) {
                                            mProcessList.killPackageProcessesLSP(ssp,
                                                    UserHandle.getAppId(extraUid),
                                                    userId, ProcessList.INVALID_ADJ,
                                                    ApplicationExitInfo.REASON_USER_REQUESTED,
                                                    ApplicationExitInfo.SUBREASON_PACKAGE_UPDATE,
                                                    reason,
                                                    subReason,
                                                    "change " + ssp);
                                        }
                                    }
+2 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import static com.android.server.pm.PackageManagerService.TAG;
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.ApplicationExitInfo;
import android.app.ApplicationPackageManager;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
@@ -237,7 +238,7 @@ final class DeletePackageHelper {
        synchronized (mPm.mInstallLock) {
            if (DEBUG_REMOVE) Slog.d(TAG, "deletePackageX: pkg=" + packageName + " user=" + userId);
            try (PackageFreezer freezer = mPm.freezePackageForDelete(packageName, freezeUser,
                    deleteFlags, "deletePackageX")) {
                    deleteFlags, "deletePackageX", ApplicationExitInfo.REASON_OTHER)) {
                res = deletePackageLIF(packageName, UserHandle.of(removeUser), true, allUsers,
                        deleteFlags | PackageManager.DELETE_CHATTY, info, true);
            }
Loading