Fix reading app ops data - framework
There was an optimized code path that is hit if the op
has not been accessed that does not write the uid state
information which did not add the closing tag which
resulted in producing a malformed XML.
Test: atest android.app.appops.cts.AppOpsTest#testNonHistoricalStatePersistence
bug:128872367
Change-Id: Iaddcce09b41f3e124e1838b65731d8dac9ca64e3
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 9c26526..10b67c1 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -1132,7 +1132,7 @@
.build();
Preconditions.checkNotNull(callback, "callback cannot be null");
- mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
+ mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
Binder.getCallingPid(), Binder.getCallingUid(), "getHistoricalOps");
final String[] opNamesArray = (opNames != null)
@@ -1144,6 +1144,14 @@
}
@Override
+ public void reloadNonHistoricalState() {
+ mContext.enforcePermission(Manifest.permission.MANAGE_APPOPS,
+ Binder.getCallingPid(), Binder.getCallingUid(), "reloadNonHistoricalState");
+ writeState();
+ readState();
+ }
+
+ @Override
public List<AppOpsManager.PackageOps> getUidOps(int uid, int[] ops) {
mContext.enforcePermission(android.Manifest.permission.GET_APP_OPS_STATS,
Binder.getCallingPid(), Binder.getCallingUid(), null);
@@ -2998,6 +3006,7 @@
final LongSparseArray keys = op.collectKeys();
if (keys == null || keys.size() <= 0) {
+ out.endTag(null, "op");
continue;
}