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

Commit c7a4c9a0 authored by Yuting's avatar Yuting Committed by Yuting Fang
Browse files

Fix several bugs in AppOp code that were introduced by device aware AppOp

These bugs are identified by reading the code or new CTS test.

Bug: 325776049
Test: atest AppOpsDeviceAwareTest
Change-Id: Ic251fb98c3ba46bc1b1f04da2d2301706f7c2607
parent 017fde98
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -251,6 +251,7 @@ package android.app {
    method @RequiresPermission("android.permission.MANAGE_APPOPS") public void getHistoricalOpsFromDiskRaw(@NonNull android.app.AppOpsManager.HistoricalOpsRequest, @Nullable java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.app.AppOpsManager.HistoricalOps>);
    method public static int getNumOps();
    method public boolean isOperationActive(int, int, String);
    method public int noteOpNoThrow(int, @NonNull android.content.AttributionSource, @Nullable String);
    method @RequiresPermission("android.permission.MANAGE_APPOPS") public void offsetHistory(long);
    method public static String opToPermission(int);
    method public static int permissionToOpCode(String);
+21 −9
Original line number Diff line number Diff line
@@ -8272,15 +8272,25 @@ public class AppOpsManager {
                cb = new IAppOpsCallback.Stub() {
                    public void opChanged(int op, int uid, String packageName,
                            String persistentDeviceId) {
                        if (Flags.deviceAwarePermissionApisEnabled()) {
                            if (callback instanceof OnOpChangedInternalListener) {
                                ((OnOpChangedInternalListener)callback).onOpChanged(op, packageName,
                                        persistentDeviceId);
                            }
                            if (sAppOpInfos[op].name != null) {

                                callback.onOpChanged(sAppOpInfos[op].name, packageName,
                                        UserHandle.getUserId(uid), persistentDeviceId);
                            }
                        } else {
                            if (callback instanceof OnOpChangedInternalListener) {
                                ((OnOpChangedInternalListener) callback).onOpChanged(op,
                                        packageName);
                            }
                            if (sAppOpInfos[op].name != null) {
                                callback.onOpChanged(sAppOpInfos[op].name, packageName,
                                        UserHandle.getUserId(uid));
                            }
                        }
                    }
                };
                mModeWatchers.put(callback, cb);
@@ -8940,6 +8950,8 @@ public class AppOpsManager {
     *
     * @hide
     */
    @TestApi
    @SuppressLint("UnflaggedApi")
    public int noteOpNoThrow(int op, @NonNull AttributionSource attributionSource,
            @Nullable String message) {
        return noteOpNoThrow(op, attributionSource.getUid(), attributionSource.getPackageName(),
+1 −2
Original line number Diff line number Diff line
@@ -359,8 +359,7 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis
                        new PermissionGroupUsage(usage.packageName, usage.uid, usage.lastAccessTime,
                                permGroup,
                                usage.isRunning, isPhone, usage.attributionTag, attributionLabel,
                                usagesWithLabels.valueAt(usageNum),
                                VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT));
                                usagesWithLabels.valueAt(usageNum), deviceId));
            }
        }

+10 −2
Original line number Diff line number Diff line
@@ -661,8 +661,12 @@ public class AppOpsService extends IAppOpsService.Stub {
        @NonNull OpEntry createEntryLocked(String persistentDeviceId) {
            // TODO(b/308201969): Update this method when we introduce disk persistence of events
            // for accesses on external devices.
            final ArrayMap<String, AttributedOp> attributedOps = mDeviceAttributedOps.get(
            ArrayMap<String, AttributedOp> attributedOps = mDeviceAttributedOps.get(
                    persistentDeviceId);
            if (attributedOps == null) {
                attributedOps = new ArrayMap<>();
            }

            final ArrayMap<String, AppOpsManager.AttributedOpEntry> attributionEntries =
                    new ArrayMap<>(attributedOps.size());
            for (int i = 0; i < attributedOps.size(); i++) {
@@ -680,8 +684,12 @@ public class AppOpsService extends IAppOpsService.Stub {
        @NonNull OpEntry createSingleAttributionEntryLocked(@Nullable String attributionTag) {
            // TODO(b/308201969): Update this method when we introduce disk persistence of events
            // for accesses on external devices.
            final ArrayMap<String, AttributedOp> attributedOps = mDeviceAttributedOps.get(
            ArrayMap<String, AttributedOp> attributedOps = mDeviceAttributedOps.get(
                    PERSISTENT_DEVICE_ID_DEFAULT);
            if (attributedOps == null) {
                attributedOps = new ArrayMap<>();
            }

            final ArrayMap<String, AttributedOpEntry> attributionEntries = new ArrayMap<>(1);
            if (attributedOps.get(attributionTag) != null) {
                attributionEntries.put(attributionTag,
+1 −1
Original line number Diff line number Diff line
@@ -237,7 +237,7 @@ public final class PermissionPolicyService extends SystemService {
        mAppOpsCallback = new IAppOpsCallback.Stub() {
            public void opChanged(int op, int uid, @Nullable String packageName,
                    String persistentDeviceId) {
                if (Objects.equals(persistentDeviceId,
                if (!Objects.equals(persistentDeviceId,
                        VirtualDeviceManager.PERSISTENT_DEVICE_ID_DEFAULT)) {
                    return;
                }