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

Commit b83bc9e7 authored by Jay Thomas Sullivan's avatar Jay Thomas Sullivan
Browse files

[ECM] Add delay before setMode

Currently a race condition happens when:

1. InstallPackageHelper recently sent a ACTION_PACKAGE_ADDED broadcast
2. AppOpsService hasn't received ACTION_PACKAGE_ADDED yet
3. InstallPackageHelper calls setMode.

In this situation, setMode silently fails, because AppOpsService
sees that mUidStates[uid][packageName] isn't populated yet, which
normally happens when ACTION_PACKAGE_ADDED is received.

This CL is a short-term mitigation to the problem, adding short delay
before InstallPackageHelper calls setMode to mitigate the race condition.
A more robust solution should be added in a follow-up CL.

Bug: 384418063
Flag: android.permission.flags.enhanced_confirmation_mode_apis_enabled
Test: atest CtsPermissionUiTestCases:android.permissionui.cts.EnhancedConfirmationManagerTest
Change-Id: Id5b7de1b4aa1bd486ae53aa7101bea91c5723fc5
parent 99d0b778
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -3103,13 +3103,14 @@ final class InstallPackageHelper {
            if (android.permission.flags.Flags.enhancedConfirmationModeApisEnabled()
                    && android.security.Flags.extendEcmToAllSettings()) {
                final int appId = request.getAppId();
                mPm.mHandler.post(() -> {
                // TODO: b/388960315 - Implement a long-term solution to race condition
                mPm.mHandler.postDelayed(() -> {
                    for (int userId : firstUserIds) {
                        // MODE_DEFAULT means that the app's guardedness will be decided lazily
                        setAccessRestrictedSettingsMode(packageName, appId, userId,
                                AppOpsManager.MODE_DEFAULT);
                    }
                });
                }, 1000L);
            } else {
                // Apply restricted settings on potentially dangerous packages. Needs to happen
                // after appOpsManager is notified of the new package