Prevent potential NPE when forcing stop package during boot

Some test cases may send package removal command before boot
complete, e.g. around SecondaryZygotePreload stage. Then
ActivityManagerService#setWindowManager is not called yet so
mRootWindowContainer in ATMS is null.

Bug: 219066637
Bug: 186665301
Test: Restart device by "adb shell am restart".
      And keep sending "adb uninstall $validPackageName".
      The device should still boot successfully without crash.
      And the target package is also removed successfully.
Change-Id: I2711fabb0755b53a9817ce81ab553e5ce2a8c389
This commit is contained in:
Riddle Hsu
2022-02-14 21:56:11 +08:00
parent cdd2a77e6b
commit 270799ad19

View File

@@ -6091,7 +6091,8 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
public boolean onForceStopPackage(String packageName, boolean doit, boolean evenPersistent,
int userId) {
synchronized (mGlobalLock) {
// In case if setWindowManager hasn't been called yet when booting.
if (mRootWindowContainer == null) return false;
return mRootWindowContainer.finishDisabledPackageActivities(packageName,
null /* filterByClasses */, doit, evenPersistent, userId,
// Only remove the activities without process because the activities with