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

Commit d9d9dbae authored by Songchun Fan's avatar Songchun Fan Committed by Android (Google) Code Review
Browse files

Merge "[am/incremental] make package unstartable if it crashes/ANRs while loading"

parents 23fb7a6a dfd41627
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -1122,4 +1122,8 @@ public abstract class PackageManagerInternal {
    public abstract IncrementalStatesInfo getIncrementalStatesInfo(String packageName,
    public abstract IncrementalStatesInfo getIncrementalStatesInfo(String packageName,
            int filterCallingUid, int userId);
            int filterCallingUid, int userId);


    /**
     * Notifies that a package has crashed or ANR'd.
     */
    public abstract void notifyPackageCrashOrAnr(String packageName);
}
}
+4 −0
Original line number Original line Diff line number Diff line
@@ -7595,6 +7595,10 @@ public class ActivityManagerService extends IActivityManager.Stub
                eventType, r, processName, null, null, null, null, null, null, crashInfo);
                eventType, r, processName, null, null, null, null, null, null, crashInfo);
        mAppErrors.crashApplication(r, crashInfo);
        mAppErrors.crashApplication(r, crashInfo);
        // Notify package manager service to possibly update package state
        if (r != null && r.info != null && r.info.packageName != null) {
            mPackageManagerInt.notifyPackageCrashOrAnr(r.info.packageName);
        }
    }
    }
    public void handleApplicationStrictModeViolation(
    public void handleApplicationStrictModeViolation(
+6 −0
Original line number Original line Diff line number Diff line
@@ -1764,6 +1764,12 @@ class ProcessRecord implements WindowProcessListener {
            makeAppNotRespondingLocked(activityShortComponentName,
            makeAppNotRespondingLocked(activityShortComponentName,
                    annotation != null ? "ANR " + annotation : "ANR", info.toString());
                    annotation != null ? "ANR " + annotation : "ANR", info.toString());


            // Notify package manager service to possibly update package state
            if (aInfo != null && aInfo.packageName != null) {
                mService.getPackageManagerInternalLocked().notifyPackageCrashOrAnr(
                        aInfo.packageName);
            }

            // mUiHandler can be null if the AMS is constructed with injector only. This will only
            // mUiHandler can be null if the AMS is constructed with injector only. This will only
            // happen in tests.
            // happen in tests.
            if (mService.mUiHandler != null) {
            if (mService.mUiHandler != null) {
+27 −0
Original line number Original line Diff line number Diff line
@@ -119,6 +119,33 @@ public final class IncrementalStates {
        }
        }
    }
    }


    /**
     * Change the startable state if the app has crashed or ANR'd during loading.
     * If the app is not loading (i.e., fully loaded), this event doesn't change startable state.
     */
    public void onCrashOrAnr() {
        if (DEBUG) {
            Slog.i(TAG, "received package crash or ANR event");
        }
        final boolean startableStateChanged;
        synchronized (mLock) {
            if (mStartableState.isStartable() && mLoadingState.isLoading()) {
                // Changing from startable -> unstartable only if app is still loading.
                mStartableState.adoptNewStartableStateLocked(false);
                startableStateChanged = true;
            } else {
                // If the app is fully loaded, the crash or ANR is caused by the app itself, so
                // we do not change the startable state.
                startableStateChanged = false;
            }
        }
        if (startableStateChanged) {
            mHandler.post(PooledLambda.obtainRunnable(
                    IncrementalStates::reportStartableState,
                    IncrementalStates.this).recycleOnUse());
        }
    }

    private void reportStartableState() {
    private void reportStartableState() {
        final Callback callback;
        final Callback callback;
        final boolean startable;
        final boolean startable;
+14 −0
Original line number Original line Diff line number Diff line
@@ -25843,6 +25843,20 @@ public class PackageManagerService extends IPackageManager.Stub
            }
            }
            return ps.getIncrementalStates();
            return ps.getIncrementalStates();
        }
        }
        @Override
        public void notifyPackageCrashOrAnr(@NonNull String packageName) {
            final PackageSetting ps;
            synchronized (mLock) {
                ps = mSettings.mPackages.get(packageName);
                if (ps == null) {
                    Slog.w(TAG, "Failed notifyPackageCrash. Package " + packageName
                            + " is not installed");
                    return;
                }
            }
            ps.setStatesOnCrashOrAnr();
        }
    }
    }
Loading