Slice and dice app ops - framework

Appops can be peformed by an app on its behalf and also on
behalf of another app, i.e. an app can perform a proxy op
and blame the work on another app. The proxy mechanims is
for apps doing work on behalf of other apps where GCore is
one example since the app doing the work needs to check if
the caller has access to the functionality - specifically
the app op backing a runtime permission in case the calling
app does not support runtime permissions.

Apps being able to blame work on other apps is a problem now
that we would be using historical op data to show permission
usage in the UI as apps can start blaming each other to gain
a competitive advantage.

To address the issue we are adding APIs for querying portions
of the app op data - last and historical. One can now get
the ops for work the app did for itself, work the app blamed
on other apps if the app is trusted, work the app blamed on
other apps if the app is not trusted, work other trusted apps
blamed on the app, work other untrusted apps blamed on the app.
A trusted app is one holding the permisison to update app op
stats which is privileged.

The data slicing API allow us to show in the UI only the trusted
poriton of the data which is work the app did for itself, work
trusted apps balmed on the app, and work the app if untrusted
blamed on other apps.

Test: atest CtsAppOpsTestCases

bug:111061782

Change-Id: I9a2bcaea272cb06f38ba742cf601a6dc3b287d5e
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index c8e8ef8..e28d484 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -1727,7 +1727,8 @@
         final List<AppOpsManager.PackageOps> pkgs = manager.getOpsForPackage(uid, packageName, ops);
         for (AppOpsManager.PackageOps pkg : CollectionUtils.emptyIfNull(pkgs)) {
             for (AppOpsManager.OpEntry op : CollectionUtils.emptyIfNull(pkg.getOps())) {
-                maxTime = Math.max(maxTime, op.getLastAccessTime());
+                maxTime = Math.max(maxTime, op.getLastAccessTime(
+                    AppOpsManager.OP_FLAGS_ALL_TRUSTED));
             }
         }
         return maxTime;