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

Commit 1cb4c72c authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Carry attributionTag for DropBoxManager

- Use PermissionChecker instead of manully implement permission check
- Need to keep old @UnsupportedUsage method

Fixes: 161443379
Test: atest CtsAppOpsTestCases:android.app.appops.cts.AppOpsLoggingTest#getNextDropBoxEntry
Change-Id: I5c3290c23312e8009a9345e8a58a6f734885f928
parent 35fedea3
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -375,7 +375,8 @@ public class DropBoxManager {
    @RequiresPermission(allOf = { READ_LOGS, PACKAGE_USAGE_STATS })
    public @Nullable Entry getNextEntry(String tag, long msec) {
        try {
            return mService.getNextEntry(tag, msec, mContext.getOpPackageName());
            return mService.getNextEntryWithAttribution(tag, msec, mContext.getOpPackageName(),
                    mContext.getAttributionTag());
        } catch (SecurityException e) {
            if (mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.P) {
                throw e;
+5 −1
Original line number Diff line number Diff line
@@ -37,6 +37,10 @@ interface IDropBoxManagerService {
    boolean isTagEnabled(String tag);

    /** @see DropBoxManager#getNextEntry */
    @UnsupportedAppUsage
    @UnsupportedAppUsage(maxTargetSdk=30,
            publicAlternatives="Use {@link android.os.DropBoxManager#getNextEntry} instead")
    DropBoxManager.Entry getNextEntry(String tag, long millis, String packageName);

    DropBoxManager.Entry getNextEntryWithAttribution(String tag, long millis, String packageName,
            String attributionTag);
}
+16 −6
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.server;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.content.BroadcastReceiver;
@@ -159,7 +160,14 @@ public final class DropBoxManagerService extends SystemService {

        @Override
        public DropBoxManager.Entry getNextEntry(String tag, long millis, String callingPackage) {
            return DropBoxManagerService.this.getNextEntry(tag, millis, callingPackage);
            return getNextEntryWithAttribution(tag, millis, callingPackage, null);
        }

        @Override
        public DropBoxManager.Entry getNextEntryWithAttribution(String tag, long millis,
                String callingPackage, String callingAttributionTag) {
            return DropBoxManagerService.this.getNextEntry(tag, millis, callingPackage,
                    callingAttributionTag);
        }

        @Override
@@ -470,7 +478,8 @@ public final class DropBoxManagerService extends SystemService {
        }
    }

    private boolean checkPermission(int callingUid, String callingPackage) {
    private boolean checkPermission(int callingUid, String callingPackage,
            @Nullable String callingAttributionTag) {
        // If callers have this permission, then we don't need to check
        // USAGE_STATS, because they are part of the system and have agreed to
        // check USAGE_STATS before passing the data along.
@@ -484,8 +493,9 @@ public final class DropBoxManagerService extends SystemService {
                android.Manifest.permission.READ_LOGS, TAG);

        // Callers also need the ability to read usage statistics
        switch (getContext().getSystemService(AppOpsManager.class)
                .noteOp(AppOpsManager.OP_GET_USAGE_STATS, callingUid, callingPackage)) {
        switch (getContext().getSystemService(AppOpsManager.class).noteOp(
                AppOpsManager.OP_GET_USAGE_STATS, callingUid, callingPackage, callingAttributionTag,
                null)) {
            case AppOpsManager.MODE_ALLOWED:
                return true;
            case AppOpsManager.MODE_DEFAULT:
@@ -498,8 +508,8 @@ public final class DropBoxManagerService extends SystemService {
    }

    public synchronized DropBoxManager.Entry getNextEntry(String tag, long millis,
            String callingPackage) {
        if (!checkPermission(Binder.getCallingUid(), callingPackage)) {
            String callingPackage, @Nullable String callingAttributionTag) {
        if (!checkPermission(Binder.getCallingUid(), callingPackage, callingAttributionTag)) {
            return null;
        }