From f39842dbc5ab098587f7582792361ae751970e31 Mon Sep 17 00:00:00 2001 From: Winson Date: Tue, 23 Mar 2021 15:17:43 -0700 Subject: [PATCH] Skip domain verify broadcast if ActivityManager isn't ready It's possible these are scheduled at boot, before ActivityManager is ready. If that happens, just skip them. The domain verification agent is supposed to scan through all the packages at boot to re-schedule any packages/domains that need verification, so dropping the install time broadcast at boot isn't a concern. Bug: 183127964 Change-Id: Ie44b41a3108253c7cf7702f7f3c08e49223414b4 --- .../domain/DomainVerificationService.java | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java index a0e252a8a28a6..eea2af415e865 100644 --- a/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java +++ b/services/core/java/com/android/server/pm/verify/domain/DomainVerificationService.java @@ -148,6 +148,8 @@ public class DomainVerificationService extends SystemService @NonNull private DomainVerificationProxy mProxy = new DomainVerificationProxyUnavailable(); + private boolean mCanSendBroadcasts; + public DomainVerificationService(@NonNull Context context, @NonNull SystemConfig systemConfig, @NonNull PlatformCompat platformCompat) { super(context); @@ -181,11 +183,18 @@ public class DomainVerificationService extends SystemService @Override public void onBootPhase(int phase) { super.onBootPhase(phase); - if (phase != SystemService.PHASE_BOOT_COMPLETED || !hasRealVerifier()) { + if (!hasRealVerifier()) { return; } - verifyPackages(null, false); + switch (phase) { + case PHASE_ACTIVITY_MANAGER_READY: + mCanSendBroadcasts = true; + break; + case PHASE_BOOT_COMPLETED: + verifyPackages(null, false); + break; + } } @Override @@ -857,7 +866,7 @@ public class DomainVerificationService extends SystemService } if (sendBroadcast) { - sendBroadcastForPackage(pkgName); + sendBroadcast(pkgName); } } @@ -936,7 +945,7 @@ public class DomainVerificationService extends SystemService } if (sendBroadcast && hasAutoVerifyDomains) { - sendBroadcastForPackage(pkgName); + sendBroadcast(pkgName); } } @@ -1097,8 +1106,19 @@ public class DomainVerificationService extends SystemService return mCollector; } - private void sendBroadcastForPackage(@NonNull String packageName) { - mProxy.sendBroadcastForPackages(Collections.singleton(packageName)); + private void sendBroadcast(@NonNull String packageName) { + sendBroadcast(Collections.singleton(packageName)); + } + + private void sendBroadcast(@NonNull Set packageNames) { + if (!mCanSendBroadcasts) { + // If the system cannot send broadcasts, it's probably still in boot, so dropping this + // request should be fine. The verification agent should re-scan packages once boot + // completes. + return; + } + + mProxy.sendBroadcastForPackages(packageNames); } private boolean hasRealVerifier() { @@ -1182,7 +1202,7 @@ public class DomainVerificationService extends SystemService } if (!packagesToBroadcast.isEmpty()) { - mProxy.sendBroadcastForPackages(packagesToBroadcast); + sendBroadcast(packagesToBroadcast); } }