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

Commit 49bd9e1e authored by Philip P. Moltmann's avatar Philip P. Moltmann
Browse files

Refactor app-op access/reject counters

The last system was too confusing and caused bugs. The new system is
easier to understand.

This still uses the key which is the combination of uidState and
op-flags. I.e. now we collect access + rejection events for the
cross-product of
- package (parameter to noteOp)
- featureId (parameter to noteOp)
- op (parameter to noteOp)
- uidState of the package the noteOp was called
- opFlags (based on which app called the noteOp and how trusted this app
was)

uidState + opFlags are usually combined into the "key" variable.

This also unifies the APIs in Op*Entry to be the same of each data-field
of an op-entry.

Note: This temporarily breaks
com.android.server.appop.AppOpsActiveWatcherTest#testIsRunning as active
ops are not yet reported. This needs to be fixed by a follow up change.

Bug: 144997947
Test: atest --test-mapping services/core/java/com/android/server/appop/
Change-Id: I9844f9886b1c032d01de51bbb46267e3244b6da6
parent 848cc353
Loading
Loading
Loading
Loading
+27 −12
Original line number Diff line number Diff line
@@ -473,15 +473,20 @@ package android.app {
  public static final class AppOpsManager.OpEntry implements android.os.Parcelable {
    method public int describeContents();
    method public long getDuration();
    method @Deprecated public long getDuration();
    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.OpFeatureEntry> getFeatures();
    method public long getLastAccessBackgroundTime(int);
    method public long getLastAccessForegroundTime(int);
    method public long getLastAccessTime(int);
    method public long getLastAccessTime(int, int, int);
    method public long getLastBackgroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
    method public long getLastDuration(int);
    method public long getLastDuration(int, int, int);
    method public long getLastForegroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
    method public long getLastRejectBackgroundTime(int);
    method public long getLastRejectForegroundTime(int);
    method public long getLastRejectTime(int);
@@ -489,34 +494,44 @@ package android.app {
    method public int getMode();
    method @NonNull public String getOpStr();
    method @Deprecated @Nullable public String getProxyPackageName();
    method @Nullable public String getProxyPackageName(int, int);
    method @Deprecated @Nullable public String getProxyPackageName(int, int);
    method @Deprecated public int getProxyUid();
    method public int getProxyUid(int, int);
    method @Deprecated public int getProxyUid(int, int);
    method public boolean isRunning();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEntry> CREATOR;
  }
  public static final class AppOpsManager.OpFeatureEntry {
    method public long getDuration();
  public static final class AppOpsManager.OpEventProxyInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getFeatureId();
    method @Nullable public String getPackageName();
    method @IntRange(from=0) public int getUid();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEventProxyInfo> CREATOR;
  }
  public static final class AppOpsManager.OpFeatureEntry implements android.os.Parcelable {
    method public int describeContents();
    method public long getLastAccessBackgroundTime(int);
    method public long getLastAccessForegroundTime(int);
    method public long getLastAccessTime(int);
    method public long getLastAccessTime(int, int, int);
    method public long getLastBackgroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
    method public long getLastDuration(int);
    method public long getLastDuration(int, int, int);
    method public long getLastForegroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
    method public long getLastRejectBackgroundTime(int);
    method public long getLastRejectForegroundTime(int);
    method public long getLastRejectTime(int);
    method public long getLastRejectTime(int, int, int);
    method @Nullable public String getProxyFeatureId();
    method @Nullable public String getProxyFeatureId(int, int);
    method @Nullable public String getProxyPackageName();
    method @Nullable public String getProxyPackageName(int, int);
    method public int getProxyUid();
    method public int getProxyUid(int, int);
    method public boolean isRunning();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpFeatureEntry> CREATOR;
  }
  public static final class AppOpsManager.PackageOps implements android.os.Parcelable {
@@ -524,7 +539,7 @@ package android.app {
    method @NonNull public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
    method @NonNull public String getPackageName();
    method public int getUid();
    method public void writeToParcel(android.os.Parcel, int);
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.PackageOps> CREATOR;
  }
+36 −11
Original line number Diff line number Diff line
@@ -157,6 +157,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 static String[] getOpStrs();
    method @NonNull @RequiresPermission("android.permission.GET_APP_OPS_STATS") public java.util.List<android.app.AppOpsManager.PackageOps> getOpsForPackage(int, @NonNull String, @Nullable java.lang.String...);
    method public boolean isOperationActive(int, int, String);
    method @RequiresPermission("android.permission.MANAGE_APPOPS") public void offsetHistory(long);
    method public static int opToDefaultMode(@NonNull String);
@@ -307,15 +308,20 @@ package android.app {

  public static final class AppOpsManager.OpEntry implements android.os.Parcelable {
    method public int describeContents();
    method public long getDuration();
    method @Deprecated public long getDuration();
    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.OpFeatureEntry> getFeatures();
    method public long getLastAccessBackgroundTime(int);
    method public long getLastAccessForegroundTime(int);
    method public long getLastAccessTime(int);
    method public long getLastAccessTime(int, int, int);
    method public long getLastBackgroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
    method public long getLastDuration(int);
    method public long getLastDuration(int, int, int);
    method public long getLastForegroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
    method public long getLastRejectBackgroundTime(int);
    method public long getLastRejectForegroundTime(int);
    method public long getLastRejectTime(int);
@@ -323,34 +329,53 @@ package android.app {
    method public int getMode();
    method @NonNull public String getOpStr();
    method @Deprecated @Nullable public String getProxyPackageName();
    method @Nullable public String getProxyPackageName(int, int);
    method @Deprecated @Nullable public String getProxyPackageName(int, int);
    method @Deprecated public int getProxyUid();
    method public int getProxyUid(int, int);
    method @Deprecated public int getProxyUid(int, int);
    method public boolean isRunning();
    method public void writeToParcel(android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEntry> CREATOR;
  }

  public static final class AppOpsManager.OpFeatureEntry {
    method public long getDuration();
  public static final class AppOpsManager.OpEventProxyInfo implements android.os.Parcelable {
    method public int describeContents();
    method @Nullable public String getFeatureId();
    method @Nullable public String getPackageName();
    method @IntRange(from=0) public int getUid();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEventProxyInfo> CREATOR;
  }

  public static final class AppOpsManager.OpFeatureEntry implements android.os.Parcelable {
    method public int describeContents();
    method public long getLastAccessBackgroundTime(int);
    method public long getLastAccessForegroundTime(int);
    method public long getLastAccessTime(int);
    method public long getLastAccessTime(int, int, int);
    method public long getLastBackgroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
    method public long getLastDuration(int);
    method public long getLastDuration(int, int, int);
    method public long getLastForegroundDuration(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
    method public long getLastRejectBackgroundTime(int);
    method public long getLastRejectForegroundTime(int);
    method public long getLastRejectTime(int);
    method public long getLastRejectTime(int, int, int);
    method @Nullable public String getProxyFeatureId();
    method @Nullable public String getProxyFeatureId(int, int);
    method @Nullable public String getProxyPackageName();
    method @Nullable public String getProxyPackageName(int, int);
    method public int getProxyUid();
    method public int getProxyUid(int, int);
    method public boolean isRunning();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpFeatureEntry> CREATOR;
  }

  public static final class AppOpsManager.PackageOps implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
    method @NonNull public String getPackageName();
    method public int getUid();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.PackageOps> CREATOR;
  }

  public class DownloadManager {
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package android.app;

parcelable AppOpsManager.PackageOps;
parcelable AppOpsManager.NoteOpEventProxyInfo;
parcelable AppOpsManager.NoteOpEvent;
parcelable AppOpsManager.OpFeatureEntry;
parcelable AppOpsManager.OpEntry;

parcelable AppOpsManager.HistoricalOp;
+1110 −780

File changed.

Preview size limit exceeded, changes collapsed.

+7 −11
Original line number Diff line number Diff line
@@ -17,8 +17,7 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Process;
import android.os.UserHandle;
import android.os.UserManager;
import android.util.LongSparseLongArray;
import android.util.Pair;
import android.util.LongSparseArray;

import org.junit.Before;
import org.junit.Ignore;
@@ -159,14 +158,11 @@ public class RecentLocationAccessesTest {

    private OpEntry createOpEntryWithTime(int op, long time) {
        // Slot for background access timestamp.
        final LongSparseLongArray accessTimes = new LongSparseLongArray();
        accessTimes.put(AppOpsManager.makeKey(AppOpsManager.UID_STATE_BACKGROUND,
            AppOpsManager.OP_FLAG_SELF), time);

        OpFeatureEntry.Builder featureEntry = new OpFeatureEntry.Builder(false, accessTimes,
                null /*rejectTimes*/, null /*durations*/, null /* proxyUids */,
                null /* proxyPackages */, null /* proxyFeatureIds */);
        return new OpEntry(op, AppOpsManager.MODE_ALLOWED,
                new Pair[]{new Pair(null, featureEntry)});
        final LongSparseArray<AppOpsManager.NoteOpEvent> accessEvents = new LongSparseArray<>();
        accessEvents.put(AppOpsManager.makeKey(AppOpsManager.UID_STATE_BACKGROUND,
            AppOpsManager.OP_FLAG_SELF), new AppOpsManager.NoteOpEvent(time, -1, null));

        return new OpEntry(op, AppOpsManager.MODE_ALLOWED, Collections.singletonMap(null,
                new OpFeatureEntry(op, false, accessEvents, null)));
    }
}
Loading