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
This commit is contained in:
Winson
2021-03-23 15:17:43 -07:00
parent 5785c5c68f
commit f39842dbc5

View File

@@ -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<String> 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);
}
}