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

Commit 6ea939f3 authored by Florian Mayer's avatar Florian Mayer
Browse files

Add profileable opt-out to packages.list.

We now have two notions of profileable:
 * profileable from shell: the user can profile the app using ADB-based
   tools (e.g. Android Studio or shell) . This is off unless the app
   opts in.
 * profileable from platform services: trusted platform services can,
   in accordance to the app installer's Terms Of Service profile the
   app. This is the default unless the app opts out. This is enforced
   by the profilers with information provided by the framework.

A new flag <profileable android:enable="false"/> can be used to opt out
of profiling in general. If this is not given, the app is considered
profilable by the platform, but the data will *not* be exposed to the
user via shell or adb. If profiles of the app should be given to the
user (e.g. for using Android Studio), <profileable
android:shell="true"/> can can still be used.

We write whether the app opted out or not to packages.list, to be
consumed by the profilers.

CTS-Coverage-Bug: 186720347

Test: m
Test: on userdebug: /data/system/packages.list for preinstalled, Play
      Store installed app and sideloaded app.
Test: on user: atest CtsPerfettoTestCases.
Bug: 170284829

Change-Id: I8d4bbedc043976fd11a95a511bd95a05c7ced7b9
parent b2de16f2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -11920,6 +11920,7 @@ package android.content.pm {
    method public int getGwpAsanMode();
    method public int getMemtagMode();
    method public int getNativeHeapZeroInitialized();
    method public boolean isProfileable();
    method public boolean isProfileableByShell();
    method public boolean isResourceOverlay();
    method public boolean isVirtualPreload();
+1 −1
Original line number Diff line number Diff line
@@ -6558,7 +6558,7 @@ public final class ActivityThread extends ClientTransactionHandler

        // Allow binder tracing, and application-generated systrace messages if we're profileable.
        boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        boolean isAppProfileable = isAppDebuggable || data.appInfo.isProfileableByShell();
        boolean isAppProfileable = isAppDebuggable || data.appInfo.isProfileable();
        Trace.setAppTracingAllowed(isAppProfileable);
        if ((isAppProfileable || Build.IS_DEBUGGABLE) && data.enableBinderTracking) {
            Binder.enableTracing();
+29 −0
Original line number Diff line number Diff line
@@ -771,6 +771,19 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoPrivateFlags {}

    /**
     * Value for {@link #privateFlagsExt}: whether this application can be profiled, either by the
     * shell user or the system.
     * @hide
     */
    public static final int PRIVATE_FLAG_EXT_PROFILEABLE = 1 << 0;

    /** @hide */
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
            PRIVATE_FLAG_EXT_PROFILEABLE,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoPrivateFlagsExt {}
    /**
     * Constant corresponding to <code>allowed</code> in the
     * {@link android.R.attr#autoRevokePermissions} attribute.
@@ -803,6 +816,12 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
    @TestApi
    public @ApplicationInfoPrivateFlags int privateFlags;

    /**
     * More private/hidden flags. See {@code PRIVATE_FLAG_EXT_...} constants.
     * @hide
     */
    public @ApplicationInfoPrivateFlagsExt int privateFlagsExt;

    /**
     * @hide
     */
@@ -1771,6 +1790,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        theme = orig.theme;
        flags = orig.flags;
        privateFlags = orig.privateFlags;
        privateFlagsExt = orig.privateFlagsExt;
        requiresSmallestWidthDp = orig.requiresSmallestWidthDp;
        compatibleWidthLimitDp = orig.compatibleWidthLimitDp;
        largestWidthLimitDp = orig.largestWidthLimitDp;
@@ -1855,6 +1875,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        dest.writeInt(theme);
        dest.writeInt(flags);
        dest.writeInt(privateFlags);
        dest.writeInt(privateFlagsExt);
        dest.writeInt(requiresSmallestWidthDp);
        dest.writeInt(compatibleWidthLimitDp);
        dest.writeInt(largestWidthLimitDp);
@@ -1944,6 +1965,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        theme = source.readInt();
        flags = source.readInt();
        privateFlags = source.readInt();
        privateFlagsExt = source.readInt();
        requiresSmallestWidthDp = source.readInt();
        compatibleWidthLimitDp = source.readInt();
        largestWidthLimitDp = source.readInt();
@@ -2363,6 +2385,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return (privateFlags & PRIVATE_FLAG_PROFILEABLE_BY_SHELL) != 0;
    }

    /**
     * Returns whether this application can be profiled, either by the shell user or the system.
     */
    public boolean isProfileable() {
        return (privateFlagsExt & PRIVATE_FLAG_EXT_PROFILEABLE) != 0;
    }

    /**
     * Returns true if the app has declared in its manifest that it wants its split APKs to be
     * loaded into isolated Contexts, with their own ClassLoaders and Resources objects.
+9 −0
Original line number Diff line number Diff line
@@ -802,6 +802,15 @@ public class PackageInfoWithoutStateUtils {
        return privateFlags;
    }

    /** @see ApplicationInfo#privateFlagsExt */
    public static int appInfoPrivateFlagsExt(ParsingPackageRead pkg) {
        // @formatter:off
        int privateFlagsExt =
                flag(pkg.isProfileable(), ApplicationInfo.PRIVATE_FLAG_EXT_PROFILEABLE);
        // @formatter:on
        return privateFlagsExt;
    }

    private static boolean checkUseInstalled(ParsingPackageRead pkg, PackageUserState state,
            @PackageManager.PackageInfoFlags int flags) {
        // If available for the target user
+2 −0
Original line number Diff line number Diff line
@@ -200,6 +200,8 @@ public interface ParsingPackage extends ParsingPackageRead {

    ParsingPackage setProfileableByShell(boolean profileableByShell);

    ParsingPackage setProfileable(boolean profileable);

    ParsingPackage setRequestLegacyExternalStorage(boolean requestLegacyExternalStorage);

    ParsingPackage setAllowNativeHeapPointerTagging(boolean allowNativeHeapPointerTagging);
Loading