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

Commit aaa4d9c7 authored by Sam Mortimer's avatar Sam Mortimer Committed by Gerrit Code Review
Browse files

AppOps: track op persistence by name instead of id

On XML write, include the op name.  On XML read, map
the name back to op id (if it exists).

Persistent AppOp state now follows the op name instead
numeric id.  This means you can upgrade between
versions of CM and the op number does not matter.
Handy when merging with future android code drops
(CM AppOp ids might be used by Google).

Change-Id: Iffc02095b6838a34ff999f8db51c2c6739dd0db8
parent da6d8814
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -303,6 +303,18 @@ public class AppOpsManager {
        return op < sOpNames.length ? sOpNames[op] : ("Unknown(" + op + ")");
    }

    /**
     * Map a non-localized name for the operation back to the Op number
     */
    public static int nameToOp(String name) {
        for (int i = 0; i < sOpNames.length; i++) {
            if (sOpNames[i].equals(name)) {
                return i;
            }
        }
        return OP_NONE;
    }

    /**
     * Retrieve the permission associated with an operation, or null if there is not one.
     */
+11 −1
Original line number Diff line number Diff line
@@ -1067,7 +1067,16 @@ public class AppOpsService extends IAppOpsService.Stub {

            String tagName = parser.getName();
            if (tagName.equals("op")) {
                int code = Integer.parseInt(parser.getAttributeValue(null, "n"));
                int code = AppOpsManager.OP_NONE;
                String codeStr = parser.getAttributeValue(null, "n");
                if (codeStr != null) {
                    code = Integer.parseInt(codeStr);
                }
                /* use op name string if it exists */
                String codeNameStr = parser.getAttributeValue(null, "ns");
                if (codeNameStr != null) {
                    code = AppOpsManager.nameToOp(codeNameStr);
                }
                boolean strict = isStrict(code, uid, pkgName);
                Op op = new Op(code, strict);
                String mode = parser.getAttributeValue(null, "m");
@@ -1150,6 +1159,7 @@ public class AppOpsService extends IAppOpsService.Stub {
                            AppOpsManager.OpEntry op = ops.get(j);
                            out.startTag(null, "op");
                            out.attribute(null, "n", Integer.toString(op.getOp()));
                            out.attribute(null, "ns", AppOpsManager.opToName(op.getOp()));
                            out.attribute(null, "m", Integer.toString(op.getMode()));
                            long time = op.getTime();
                            if (time != 0) {