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

Commit a5748144 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge changes from topic "appOpFeatureId"

* changes:
  Restrict the number of features or size of ids.
  Use Pools for noteOp related data objects
  Allow apps to define featureIds in the manifest
parents 789381b8 e52bd98d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -610,6 +610,7 @@ package android {
    field public static final int fastScrollTextColor = 16843609; // 0x1010359
    field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336
    field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339
    field public static final int featureId = 16844301; // 0x101060d
    field public static final int fillAfter = 16843197; // 0x10101bd
    field public static final int fillAlpha = 16843980; // 0x10104cc
    field public static final int fillBefore = 16843196; // 0x10101bc
+130 −43
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.util.ArrayMap;
import android.util.ArraySet;
import android.util.LongSparseArray;
import android.util.LongSparseLongArray;
import android.util.Pools;
import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
@@ -2341,15 +2342,31 @@ public class AppOpsManager {
     */
    @TestApi
    @SystemApi
    @Immutable
    @DataClass(genHiddenConstructor = true)
    // @DataClass(genHiddenConstructor = true, genHiddenCopyConstructor = true)
    // genHiddenCopyConstructor does not work for @hide @SystemApi classes
    public static final class OpEventProxyInfo implements Parcelable {
        /** UID of the proxy app that noted the op */
        private final @IntRange(from = 0) int mUid;
        private @IntRange(from = 0) int mUid;
        /** Package of the proxy that noted the op */
        private final @Nullable String mPackageName;
        private @Nullable String mPackageName;
        /** ID of the feature of the proxy that noted the op */
        private final @Nullable String mFeatureId;
        private @Nullable String mFeatureId;

        /**
         * Reinit existing object with new state.
         *
         * @param uid UID of the proxy app that noted the op
         * @param packageName Package of the proxy that noted the op
         * @param featureId ID of the feature of the proxy that noted the op
         *
         * @hide
         */
        public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName,
                @Nullable String featureId) {
            mUid = Preconditions.checkArgumentNonnegative(uid);
            mPackageName = packageName;
            mFeatureId = featureId;
        }



@@ -2392,6 +2409,18 @@ public class AppOpsManager {
            // onConstructed(); // You can define this method to get a callback
        }

        /**
         * Copy constructor
         *
         * @hide
         */
        @DataClass.Generated.Member
        public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) {
            mUid = orig.mUid;
            mPackageName = orig.mPackageName;
            mFeatureId = orig.mFeatureId;
        }

        /**
         * UID of the proxy app that noted the op
         */
@@ -2471,14 +2500,15 @@ public class AppOpsManager {
            }
        };

        /*
        @DataClass.Generated(
                time = 1576194071700L,
                time = 1576814974615L,
                codegenVersion = "1.0.14",
                sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
                inputSignatures = "private final @android.annotation.IntRange(from=0L) int mUid\nprivate final @android.annotation.Nullable java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
                inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mFeatureId\npublic  void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)")
        @Deprecated
        private void __metadata() {}

        */

        //@formatter:on
        // End of generated code
@@ -2490,15 +2520,48 @@ public class AppOpsManager {
     *
     * @hide
     */
    @Immutable
    //@DataClass codegen verifier is broken
    public static final class NoteOpEvent implements Parcelable {
        /** Time of noteOp event */
        public final @IntRange(from = 0) long noteTime;
        private @IntRange(from = 0) long mNoteTime;
        /** The duration of this event (in case this is a startOp event, -1 otherwise). */
        public final @IntRange(from = -1) long duration;
        private @IntRange(from = -1) long mDuration;
        /** Proxy information of the noteOp event */
        public final @Nullable OpEventProxyInfo proxy;
        private @Nullable OpEventProxyInfo mProxy;

        /**
         * Reinit existing object with new state.
         *
         * @param noteTime Time of noteOp event
         * @param duration The duration of this event (in case this is a startOp event,
         *                 -1 otherwise).
         * @param proxy Proxy information of the noteOp event
         * @param proxyPool  The pool to release previous {@link OpEventProxyInfo} to
         */
        public void reinit(@IntRange(from = 0) long noteTime,
                @IntRange(from = -1) long duration,
                @Nullable OpEventProxyInfo proxy,
                @NonNull Pools.Pool<OpEventProxyInfo> proxyPool) {
            mNoteTime = Preconditions.checkArgumentNonnegative(noteTime);
            mDuration = Preconditions.checkArgumentInRange(duration, -1L, Long.MAX_VALUE,
                    "duration");

            if (mProxy != null) {
                proxyPool.release(mProxy);
            }
            mProxy = proxy;
        }

        /**
         * Copy constructor
         *
         * @hide
         */
        public NoteOpEvent(@NonNull NoteOpEvent original) {
            this(original.mNoteTime, original.mDuration,
                    original.mProxy != null ? new OpEventProxyInfo(original.mProxy) : null);
        }



        // Code below generated by codegen v1.0.14.
@@ -2529,19 +2592,43 @@ public class AppOpsManager {
                @IntRange(from = 0) long noteTime,
                @IntRange(from = -1) long duration,
                @Nullable OpEventProxyInfo proxy) {
            this.noteTime = noteTime;
            this.mNoteTime = noteTime;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, noteTime,
                    IntRange.class, null, mNoteTime,
                    "from", 0);
            this.duration = duration;
            this.mDuration = duration;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, duration,
                    IntRange.class, null, mDuration,
                    "from", -1);
            this.proxy = proxy;
            this.mProxy = proxy;

            // onConstructed(); // You can define this method to get a callback
        }

        /**
         * Time of noteOp event
         */
        @DataClass.Generated.Member
        public @IntRange(from = 0) long getNoteTime() {
            return mNoteTime;
        }

        /**
         * The duration of this event (in case this is a startOp event, -1 otherwise).
         */
        @DataClass.Generated.Member
        public @IntRange(from = -1) long getDuration() {
            return mDuration;
        }

        /**
         * Proxy information of the noteOp event
         */
        @DataClass.Generated.Member
        public @Nullable OpEventProxyInfo getProxy() {
            return mProxy;
        }

        @Override
        @DataClass.Generated.Member
        public void writeToParcel(@NonNull Parcel dest, int flags) {
@@ -2549,11 +2636,11 @@ public class AppOpsManager {
            // void parcelFieldName(Parcel dest, int flags) { ... }

            byte flg = 0;
            if (proxy != null) flg |= 0x4;
            if (mProxy != null) flg |= 0x4;
            dest.writeByte(flg);
            dest.writeLong(noteTime);
            dest.writeLong(duration);
            if (proxy != null) dest.writeTypedObject(proxy, flags);
            dest.writeLong(mNoteTime);
            dest.writeLong(mDuration);
            if (mProxy != null) dest.writeTypedObject(mProxy, flags);
        }

        @Override
@@ -2568,20 +2655,19 @@ public class AppOpsManager {
            // static FieldType unparcelFieldName(Parcel in) { ... }

            byte flg = in.readByte();
            long _noteTime = in.readLong();
            long _duration = in.readLong();
            OpEventProxyInfo _proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(
                    OpEventProxyInfo.CREATOR);
            long noteTime = in.readLong();
            long duration = in.readLong();
            OpEventProxyInfo proxy = (flg & 0x4) == 0 ? null : (OpEventProxyInfo) in.readTypedObject(OpEventProxyInfo.CREATOR);

            this.noteTime = _noteTime;
            this.mNoteTime = noteTime;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, noteTime,
                    IntRange.class, null, mNoteTime,
                    "from", 0);
            this.duration = _duration;
            this.mDuration = duration;
            com.android.internal.util.AnnotationValidations.validate(
                    IntRange.class, null, duration,
                    IntRange.class, null, mDuration,
                    "from", -1);
            this.proxy = _proxy;
            this.mProxy = proxy;

            // onConstructed(); // You can define this method to get a callback
        }
@@ -2602,10 +2688,10 @@ public class AppOpsManager {

        /*
        @DataClass.Generated(
                time = 1574809856220L,
                time = 1576811792274L,
                codegenVersion = "1.0.14",
                sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
                inputSignatures = "public final @android.annotation.IntRange(from=0L) long noteTime\npublic final @android.annotation.IntRange(from=-1) long duration\npublic final @android.annotation.Nullable android.app.NoteOpEventProxyInfo proxy\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass")
                inputSignatures = "private @android.annotation.IntRange(from=0L) long mNoteTime\nprivate @android.annotation.IntRange(from=-1) long mDuration\nprivate @android.annotation.Nullable android.app.OpEventProxyInfo mProxy\npublic  void reinit(long,long,android.app.OpEventProxyInfo,android.util.Pools.Pool<android.app.OpEventProxyInfo>)\npublic @java.lang.Override java.lang.Object clone()\nclass NoteOpEvent extends java.lang.Object implements [android.os.Parcelable, java.lang.Cloneable]\n@com.android.internal.util.DataClass")
        @Deprecated
        private void __metadata() {}
         */
@@ -2751,7 +2837,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.noteTime;
            return lastEvent.getNoteTime();
        }

        /**
@@ -2847,7 +2933,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.noteTime;
            return lastEvent.getNoteTime();
        }

        /**
@@ -2922,7 +3008,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.duration;
            return lastEvent.getDuration();
        }

        /**
@@ -3000,7 +3086,7 @@ public class AppOpsManager {
                return null;
            }

            return lastEvent.proxy;
            return lastEvent.getProxy();
        }

        private static class LongSparseArrayParceling implements
@@ -3304,7 +3390,7 @@ public class AppOpsManager {
                        toUidState, flags);

                if (lastAccessEvent == null || (lastFeatureAccessEvent != null
                        && lastFeatureAccessEvent.noteTime > lastAccessEvent.noteTime)) {
                        && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) {
                    lastAccessEvent = lastFeatureAccessEvent;
                }
            }
@@ -3335,7 +3421,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.noteTime;
            return lastEvent.getNoteTime();
        }

        /**
@@ -3418,7 +3504,7 @@ public class AppOpsManager {
                        toUidState, flags);

                if (lastAccessEvent == null || (lastFeatureAccessEvent != null
                        && lastFeatureAccessEvent.noteTime > lastAccessEvent.noteTime)) {
                        && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) {
                    lastAccessEvent = lastFeatureAccessEvent;
                }
            }
@@ -3449,7 +3535,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.noteTime;
            return lastEvent.getNoteTime();
        }

        /**
@@ -3544,7 +3630,7 @@ public class AppOpsManager {
                return -1;
            }

            return lastEvent.duration;
            return lastEvent.getDuration();
        }

        /**
@@ -3674,7 +3760,7 @@ public class AppOpsManager {
                return null;
            }

            return lastEvent.proxy;
            return lastEvent.getProxy();
        }


@@ -7331,7 +7417,8 @@ public class AppOpsManager {
                final long key = makeKey(uidState, flag);

                NoteOpEvent event = events.get(key);
                if (lastEvent == null || event != null && event.noteTime > lastEvent.noteTime) {
                if (lastEvent == null
                        || event != null && event.getNoteTime() > lastEvent.getNoteTime()) {
                    lastEvent = event;
                }
            }
+1 −0
Original line number Diff line number Diff line
@@ -202,6 +202,7 @@ public class PackageParser {
    public static final String TAG_OVERLAY = "overlay";
    public static final String TAG_PACKAGE = "package";
    public static final String TAG_PACKAGE_VERIFIER = "package-verifier";
    public static final String TAG_FEATURE = "feature";
    public static final String TAG_PERMISSION = "permission";
    public static final String TAG_PERMISSION_GROUP = "permission-group";
    public static final String TAG_PERMISSION_TREE = "permission-tree";
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.content.pm.PackageUserState;
import android.content.pm.SharedLibraryInfo;
import android.content.pm.parsing.ComponentParseUtils.ParsedActivity;
import android.content.pm.parsing.ComponentParseUtils.ParsedActivityIntentInfo;
import android.content.pm.parsing.ComponentParseUtils.ParsedFeature;
import android.content.pm.parsing.ComponentParseUtils.ParsedInstrumentation;
import android.content.pm.parsing.ComponentParseUtils.ParsedPermission;
import android.content.pm.parsing.ComponentParseUtils.ParsedPermissionGroup;
@@ -244,6 +245,9 @@ public interface AndroidPackage extends Parcelable {
    @Nullable
    List<ParsedInstrumentation> getInstrumentations();

    @Nullable
    List<ParsedFeature> getFeatures();

    @Nullable
    List<ParsedPermissionGroup> getPermissionGroups();

+36 −0
Original line number Diff line number Diff line
@@ -793,6 +793,10 @@ public class ApkParseUtils {
                    parseResult = parseKeySets(parseInput, parsingPackage, res, parser);
                    success = parseResult.isSuccess();
                    break;
                case PackageParser.TAG_FEATURE:
                    parseResult = parseFeature(parseInput, parsingPackage, res, parser);
                    success = parseResult.isSuccess();
                    break;
                case PackageParser.TAG_PERMISSION_GROUP:
                    parseResult = parsePermissionGroup(parseInput, parsingPackage, res,
                            parser);
@@ -880,6 +884,13 @@ public class ApkParseUtils {
            );
        }

        if (!ComponentParseUtils.ParsedFeature.isCombinationValid(parsingPackage.getFeatures())) {
            return parseInput.error(
                    INSTALL_PARSE_FAILED_BAD_MANIFEST,
                    "Combination <feature> tags are not valid"
            );
        }

        convertNewPermissions(parsingPackage);

        convertSplitPermissions(parsingPackage);
@@ -1260,6 +1271,31 @@ public class ApkParseUtils {
        return parseInput.success(parsingPackage);
    }

    private static ParseResult parseFeature(
            ParseInput parseInput,
            ParsingPackage parsingPackage,
            Resources res,
            XmlResourceParser parser
    ) throws IOException, XmlPullParserException {
        // TODO(b/135203078): Remove, replace with ParseResult
        String[] outError = new String[1];

        ComponentParseUtils.ParsedFeature parsedFeature =
                ComponentParseUtils.parseFeature(res, parser, outError);

        if (parsedFeature == null || outError[0] != null) {
            return parseInput.error(
                    PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED,
                    outError[0]
            );
        }

        parsingPackage.addFeature(parsedFeature);

        return parseInput.success(parsingPackage);
    }


    private static ParseResult parsePermissionGroup(
            ParseInput parseInput,
            ParsingPackage parsingPackage,
Loading