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

Commit ffbba997 authored by Guojing Yuan's avatar Guojing Yuan Committed by Android (Google) Code Review
Browse files

Merge "[CDM] Fix exemption logic to only apply to the current user" into main

parents 3c1340a6 0b7155b7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -241,7 +241,8 @@ public class CompanionDeviceManagerService extends SystemService {

        Binder.withCleanCallingIdentity(() -> {
            ExecutorService executor = Executors.newSingleThreadExecutor();
            executor.execute(mCompanionExemptionProcessor::updateAutoRevokeExemptions);
            executor.execute(() -> mCompanionExemptionProcessor.updateAutoRevokeExemptions(
                    user.getUserIdentifier()));
        });
    }

+23 −26
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static android.app.AppOpsManager.MODE_IGNORED;
import static com.android.server.companion.utils.PackageUtils.getPackageInfo;

import android.annotation.SuppressLint;
import android.annotation.UserIdInt;
import android.app.ActivityManagerInternal;
import android.app.AppOpsManager;
import android.companion.AssociationInfo;
@@ -39,9 +40,7 @@ import android.util.Pair;
import android.util.Slog;

import com.android.internal.util.ArrayUtils;
import com.android.server.LocalServices;
import com.android.server.companion.association.AssociationStore;
import com.android.server.pm.UserManagerInternal;
import com.android.server.wm.ActivityTaskManagerInternal;

import java.io.File;
@@ -172,16 +171,15 @@ public class CompanionExemptionProcessor {
     * Update auto revoke exemptions.
     * If the app has any association, exempt it from permission auto revoke.
     */
    public void updateAutoRevokeExemptions() {
    public void updateAutoRevokeExemptions(@UserIdInt int userId) {
        Slog.d(TAG, "maybeGrantAutoRevokeExemptions()");

        PackageManager pm = mContext.getPackageManager();
        for (int userId : LocalServices.getService(UserManagerInternal.class).getUserIds()) {
        SharedPreferences pref = mContext.getSharedPreferences(
                new File(Environment.getUserSystemDirectory(userId), PREF_FILE_NAME),
                Context.MODE_PRIVATE);
        if (pref.getBoolean(PREF_KEY_AUTO_REVOKE_GRANTS_DONE, false)) {
                continue;
            return;
        }

        try {
@@ -203,7 +201,6 @@ public class CompanionExemptionProcessor {
            pref.edit().putBoolean(PREF_KEY_AUTO_REVOKE_GRANTS_DONE, true).apply();
        }
    }
    }

    @SuppressLint("MissingPermission")
    private void updateAutoRevokeExemption(String packageName, int uid, boolean hasAssociations) {