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

Commit ce030289 authored by Chris Craik's avatar Chris Craik
Browse files

Add 'profileable' application manifest tag

Bug: 117841084
Test: atest CtsAtraceHostTestCases:AtraceHostTest

Allow apps to opt-in to important profiling features (systrace, binder
tracing), without requiring debuggable=true. Debuggable has
significant performance overhead, and is undesirable for profiling.

Profileable is set to true when debuggable is true.

Change-Id: I16aaa7bc60dee4b1b262e169ac285759d57d8198
parent 8233d9f6
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -1209,6 +1209,7 @@ package android {
    field public static final int shareInterpolator = 16843195; // 0x10101bb
    field public static final int sharedUserId = 16842763; // 0x101000b
    field public static final int sharedUserLabel = 16843361; // 0x1010261
    field public static final int shell = 16844180; // 0x1010594
    field public static final int shortcutDisabledMessage = 16844075; // 0x101052b
    field public static final int shortcutId = 16844072; // 0x1010528
    field public static final int shortcutLongLabel = 16844074; // 0x101052a
@@ -10820,6 +10821,7 @@ package android.content.pm {
    method public int describeContents();
    method public void dump(android.util.Printer, java.lang.String);
    method public static java.lang.CharSequence getCategoryTitle(android.content.Context, int);
    method public boolean isProfileableByShell();
    method public boolean isVirtualPreload();
    method public java.lang.CharSequence loadDescription(android.content.pm.PackageManager);
    field public static final int CATEGORY_AUDIO = 1; // 0x1
+8 −5
Original line number Diff line number Diff line
@@ -5878,14 +5878,17 @@ public final class ActivityThread extends ClientTransactionHandler {
            }
        }

        // Allow application-generated systrace messages if we're debuggable.
        boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        Trace.setAppTracingAllowed(isAppDebuggable);
        ThreadedRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE);
        if (isAppDebuggable && data.enableBinderTracking) {
        // Allow binder tracing, and application-generated systrace messages if we're profileable.
        boolean isAppProfileable = data.appInfo.isProfileableByShell();
        Trace.setAppTracingAllowed(isAppProfileable);
        if (isAppProfileable && data.enableBinderTracking) {
            Binder.enableTracing();
        }

        // Allow renderer debugging features if we're debuggable.
        boolean isAppDebuggable = (data.appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
        ThreadedRenderer.setDebuggingEnabled(isAppDebuggable || Build.IS_DEBUGGABLE);

        /**
         * Initialize the default http proxy in this process for the reasons we set the time zone.
         */
+16 −0
Original line number Diff line number Diff line
@@ -635,6 +635,13 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int PRIVATE_FLAG_USES_NON_SDK_API = 1 << 22;

    /**
     * Indicates whether this application can be profiled by the shell user,
     * even when running on a device that is running in user mode.
     * @hide
     */
    public static final int PRIVATE_FLAG_PROFILEABLE_BY_SHELL = 1 << 23;

    /** @hide */
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_" }, value = {
            PRIVATE_FLAG_ACTIVITIES_RESIZE_MODE_RESIZEABLE,
@@ -654,6 +661,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
            PRIVATE_FLAG_PRIVILEGED,
            PRIVATE_FLAG_PRODUCT,
            PRIVATE_FLAG_PRODUCT_SERVICES,
            PRIVATE_FLAG_PROFILEABLE_BY_SHELL,
            PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER,
            PRIVATE_FLAG_SIGNED_WITH_PLATFORM_KEY,
            PRIVATE_FLAG_STATIC_SHARED_LIBRARY,
@@ -1928,6 +1936,14 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
        return (privateFlags & PRIVATE_FLAG_VIRTUAL_PRELOAD) != 0;
    }

    /**
     * Returns whether or not this application can be profiled by the shell user,
     * even when running on a device that is running in user mode.
     */
    public boolean isProfileableByShell() {
        return (privateFlags & PRIVATE_FLAG_PROFILEABLE_BY_SHELL) != 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.
+10 −0
Original line number Diff line number Diff line
@@ -3501,6 +3501,8 @@ public class PackageParser {
                com.android.internal.R.styleable.AndroidManifestApplication_debuggable,
                false)) {
            ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
            // Debuggable implies profileable
            ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL;
        }

        if (sa.getBoolean(
@@ -3867,6 +3869,14 @@ public class PackageParser {
                // Dependencies for app installers; we don't currently try to
                // enforce this.
                XmlUtils.skipCurrentTag(parser);
            } else if (tagName.equals("profileable")) {
                sa = res.obtainAttributes(parser,
                        com.android.internal.R.styleable.AndroidManifestProfileable);
                if (sa.getBoolean(
                        com.android.internal.R.styleable.AndroidManifestProfileable_shell, false)) {
                    ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_PROFILEABLE_BY_SHELL;
                }
                XmlUtils.skipCurrentTag(parser);

            } else {
                if (!RIGID_PARSER) {
+6 −0
Original line number Diff line number Diff line
@@ -2735,4 +2735,10 @@
        <attr name="name" format="string" />
    </declare-styleable>


    <declare-styleable name="AndroidManifestProfileable" parent="AndroidManifestApplication">
        <!-- Flag indicating whether the application can be profiled by the shell user,
             even when running on a device that is running in user mode. -->
        <attr name="shell" format="boolean" />
    </declare-styleable>
</resources>
Loading