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

Commit 5bf50d9b authored by Nate Myren's avatar Nate Myren Committed by Automerger Merge Worker
Browse files

Merge "Create Attribution Chains in HistoricalOps" into sc-dev am: 3e51f7ca am: f811370b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14963609

Change-Id: I4b90537c0c9252e28686d6e8315754c2d63a5b02
parents 3bda7746 f811370b
Loading
Loading
Loading
Loading
+38 −12
Original line number Diff line number Diff line
@@ -4803,6 +4803,16 @@ public class AppOpsManager {
    @SystemApi
    public static final int HISTORY_FLAG_DISCRETE = 1 << 1;

    /**
     * Flag for querying app op history: assemble attribution chains, and attach the last visible
     * node in the chain to the start as a proxy info. This only applies to discrete accesses.
     *
     * TODO 191512294: Add to @SystemApi
     *
     * @hide
     */
    public static final int HISTORY_FLAG_GET_ATTRIBUTION_CHAINS = 1 << 2;

    /**
     * Flag for querying app op history: get all types of historical access information.
     *
@@ -4819,7 +4829,8 @@ public class AppOpsManager {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(flag = true, prefix = { "HISTORY_FLAG_" }, value = {
            HISTORY_FLAG_AGGREGATE,
            HISTORY_FLAG_DISCRETE
            HISTORY_FLAG_DISCRETE,
            HISTORY_FLAG_GET_ATTRIBUTION_CHAINS
    })
    public @interface OpHistoryFlags {}

@@ -5037,7 +5048,8 @@ public class AppOpsManager {
             * @return This builder.
             */
            public @NonNull Builder setHistoryFlags(@OpHistoryFlags int flags) {
                Preconditions.checkFlagsArgument(flags, HISTORY_FLAGS_ALL);
                Preconditions.checkFlagsArgument(flags,
                        HISTORY_FLAGS_ALL | HISTORY_FLAG_GET_ATTRIBUTION_CHAINS);
                mHistoryFlags = flags;
                return this;
            }
@@ -5290,8 +5302,17 @@ public class AppOpsManager {
                @Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
                long discreteAccessTime, long discreteAccessDuration) {
            getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
                    uidState, opFlag, discreteAccessTime, discreteAccessDuration);
        };
                    uidState, opFlag, discreteAccessTime, discreteAccessDuration, null);
        }

        /** @hide */
        public void addDiscreteAccess(int opCode, int uid, @NonNull String packageName,
                @Nullable String attributionTag, @UidState int uidState, @OpFlags int opFlag,
                long discreteAccessTime, long discreteAccessDuration,
                @Nullable OpEventProxyInfo proxy) {
            getOrCreateHistoricalUidOps(uid).addDiscreteAccess(opCode, packageName, attributionTag,
                    uidState, opFlag, discreteAccessTime, discreteAccessDuration, proxy);
        }


        /** @hide */
@@ -5623,9 +5644,10 @@ public class AppOpsManager {

        private void addDiscreteAccess(int opCode, @NonNull String packageName,
                @Nullable String attributionTag, @UidState int uidState,
                @OpFlags int flag, long discreteAccessTime, long discreteAccessDuration) {
                @OpFlags int flag, long discreteAccessTime, long discreteAccessDuration,
                @Nullable OpEventProxyInfo proxy) {
            getOrCreateHistoricalPackageOps(packageName).addDiscreteAccess(opCode, attributionTag,
                    uidState, flag, discreteAccessTime, discreteAccessDuration);
                    uidState, flag, discreteAccessTime, discreteAccessDuration, proxy);
        };

        /**
@@ -5889,9 +5911,9 @@ public class AppOpsManager {

        private void addDiscreteAccess(int opCode, @Nullable String attributionTag,
                @UidState int uidState, @OpFlags int flag, long discreteAccessTime,
                long discreteAccessDuration) {
                long discreteAccessDuration, @Nullable OpEventProxyInfo proxy) {
            getOrCreateAttributedHistoricalOps(attributionTag).addDiscreteAccess(opCode, uidState,
                    flag, discreteAccessTime, discreteAccessDuration);
                    flag, discreteAccessTime, discreteAccessDuration, proxy);
        }

        /**
@@ -6212,9 +6234,10 @@ public class AppOpsManager {
        }

        private void addDiscreteAccess(int opCode, @UidState int uidState, @OpFlags int flag,
                long discreteAccessTime, long discreteAccessDuration) {
                long discreteAccessTime, long discreteAccessDuration,
                @Nullable OpEventProxyInfo proxy) {
            getOrCreateHistoricalOp(opCode).addDiscreteAccess(uidState,flag, discreteAccessTime,
                    discreteAccessDuration);
                    discreteAccessDuration, proxy);
        }

        /**
@@ -6583,11 +6606,12 @@ public class AppOpsManager {
        }

        private void addDiscreteAccess(@UidState int uidState, @OpFlags int flag,
                long discreteAccessTime, long discreteAccessDuration) {
                long discreteAccessTime, long discreteAccessDuration,
                @Nullable OpEventProxyInfo proxy) {
            List<AttributedOpEntry> discreteAccesses = getOrCreateDiscreteAccesses();
            LongSparseArray<NoteOpEvent> accessEvents = new LongSparseArray<>();
            long key = makeKey(uidState, flag);
            NoteOpEvent note = new NoteOpEvent(discreteAccessTime, discreteAccessDuration, null);
            NoteOpEvent note = new NoteOpEvent(discreteAccessTime, discreteAccessDuration, proxy);
            accessEvents.append(key, note);
            AttributedOpEntry access = new AttributedOpEntry(mOp, false, accessEvents, null);
            int insertionPoint = discreteAccesses.size() - 1;
@@ -10022,6 +10046,8 @@ public class AppOpsManager {
                    NoteOpEvent existingAccess = accessEvents.get(key);
                    if (existingAccess == null || existingAccess.getDuration() == -1) {
                        accessEvents.append(key, access);
                    } else if (existingAccess.mProxy == null && access.mProxy != null ) {
                        existingAccess.mProxy = access.mProxy;
                    }
                }
                if (reject != null) {
+25 −10
Original line number Diff line number Diff line
@@ -908,9 +908,32 @@ public final class PermissionManager {
     */
    public static boolean shouldShowPackageForIndicatorCached(@NonNull Context context,
            @NonNull String packageName) {
        if (SYSTEM_PKG.equals(packageName)) {
            return false;
        return !getIndicatorExemptedPackages(context).contains(packageName);
    }

    /**
     * Get the list of packages that are not shown by the indicators. Only a select few roles, and
     * the system app itself, are hidden. These values are updated at most every 15 seconds.
     * @hide
     */
    public static Set<String> getIndicatorExemptedPackages(@NonNull Context context) {
        updateIndicatorExemptedPackages(context);
        ArraySet<String> pkgNames = new ArraySet<>();
        pkgNames.add(SYSTEM_PKG);
        for (int i = 0; i < INDICATOR_EXEMPTED_PACKAGES.length; i++) {
            String exemptedPackage = INDICATOR_EXEMPTED_PACKAGES[i];
            if (exemptedPackage != null) {
                pkgNames.add(exemptedPackage);
            }
        }
        return pkgNames;
    }

    /**
     * Update the cached indicator exempted packages
     * @hide
     */
    public static void updateIndicatorExemptedPackages(@NonNull Context context) {
        long now = SystemClock.elapsedRealtime();
        if (sLastIndicatorUpdateTime == -1
                || (now - sLastIndicatorUpdateTime) > EXEMPTED_INDICATOR_ROLE_UPDATE_FREQUENCY_MS) {
@@ -919,14 +942,6 @@ public final class PermissionManager {
                INDICATOR_EXEMPTED_PACKAGES[i] = context.getString(EXEMPTED_ROLES[i]);
            }
        }
        for (int i = 0; i < EXEMPTED_ROLES.length; i++) {
            String exemptedPackage = INDICATOR_EXEMPTED_PACKAGES[i];
            if (exemptedPackage != null && exemptedPackage.equals(packageName)) {
                return false;
            }
        }

        return true;
    }
    /**
     * Gets the list of packages that have permissions that specified
+3 −1
Original line number Diff line number Diff line
@@ -410,7 +410,9 @@ public class PermissionUsageHelper implements AppOpsManager.OnOpActiveChangedLis

            int usageAttr = usage.getPackageIdHash();
            // If this usage has a proxy, but is not a proxy, it is the end of a chain.
            if (!proxies.containsKey(usageAttr) && usage.proxy != null) {
            // TODO remove once camera converted
            if (!proxies.containsKey(usageAttr) && usage.proxy != null
                    && !usage.op.equals(OPSTR_RECORD_AUDIO)) {
                proxyLabels.put(usage, new ArrayList<>());
                proxyPackages.add(usage.getPackageIdHash());
            }
+29 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util.function;

import java.util.function.Consumer;


/**
 * A 12-argument {@link Consumer}
 *
 * @hide
 */
public interface DodecConsumer<A, B, C, D, E, F, G, H, I, J, K, L> {
    void accept(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l);
}
+28 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.util.function;

import java.util.function.Function;

/**
 * A 12-argument {@link Function}
 *
 * @hide
 */
public interface DodecFunction<A, B, C, D, E, F, G, H, I, J, K, L, R> {
    R apply(A a, B b, C c, D d, E e, F f, G g, H h, I i, J j, K k, L l);
}
Loading