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

Commit 635d5c7c authored by Winson Chiu's avatar Winson Chiu Committed by Android (Google) Code Review
Browse files

Merge "Skip domain verify broadcast if ActivityManager isn't ready" into sc-dev

parents f803a76f f39842db
Loading
Loading
Loading
Loading
+27 −7
Original line number Diff line number Diff line
@@ -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;
        }

        switch (phase) {
            case PHASE_ACTIVITY_MANAGER_READY:
                mCanSendBroadcasts = true;
                break;
            case PHASE_BOOT_COMPLETED:
                verifyPackages(null, false);
                break;
        }
    }

    @Override
@@ -858,7 +867,7 @@ public class DomainVerificationService extends SystemService
        }

        if (sendBroadcast) {
            sendBroadcastForPackage(pkgName);
            sendBroadcast(pkgName);
        }
    }

@@ -937,7 +946,7 @@ public class DomainVerificationService extends SystemService
        }

        if (sendBroadcast && hasAutoVerifyDomains) {
            sendBroadcastForPackage(pkgName);
            sendBroadcast(pkgName);
        }
    }

@@ -1098,8 +1107,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() {
@@ -1183,7 +1203,7 @@ public class DomainVerificationService extends SystemService
        }

        if (!packagesToBroadcast.isEmpty()) {
            mProxy.sendBroadcastForPackages(packagesToBroadcast);
            sendBroadcast(packagesToBroadcast);
        }
    }