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

Commit 549506b4 authored by Winson Chung's avatar Winson Chung
Browse files

Enable printing stack traces for activity starts based on a sysprop

- For non-platform devs who don't have a platform checkout, having the
  ability to enable a stack trace for all processes in the system
  can help further narrow down the origin of the launch.  Having it in
  logcat vs debugging the process can also be helpful if there are other
  adjacent logs to cross-reference with.
- Usage:
    // Enabling
    adb shell setprop persist.wm.debug.start_activity true
    adb reboot
    adb logcat -s "Instrumentation"

    // Disabling
    adb shell setprop persist.wm.debug.start_activity \"\"
    adb reboot

Fixes: 309020623
Test: adb shell setprop persist.wm.debug.start_activity true
Change-Id: I0b2ba15106053daddcaad246ebf97c339298c325
parent 0edd8471
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -6348,6 +6348,10 @@ public class Activity extends ContextThemeWrapper
     */
    public boolean startActivityIfNeeded(@RequiresPermission @NonNull Intent intent,
            int requestCode, @Nullable Bundle options) {
        if (Instrumentation.DEBUG_START_ACTIVITY) {
            Log.d("Instrumentation", "startActivity: intent=" + intent
                    + " requestCode=" + requestCode + " options=" + options, new Throwable());
        }
        if (mParent == null) {
            int result = ActivityManager.START_RETURN_INTENT_TO_CALLER;
            try {
+41 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.os.Process;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.os.TestLooperManager;
import android.os.UserHandle;
import android.os.UserManager;
@@ -67,6 +68,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.TimeoutException;

/**
@@ -100,6 +102,10 @@ public class Instrumentation {

    private static final boolean VERBOSE = Log.isLoggable(TAG, Log.VERBOSE);

    // If set, will print the stack trace for activity starts within the process
    static final boolean DEBUG_START_ACTIVITY = Build.IS_DEBUGGABLE &&
            SystemProperties.getBoolean("persist.wm.debug.start_activity", false);

    /**
     * @hide
     */
@@ -577,6 +583,9 @@ public class Instrumentation {
     */
    @NonNull
    public Activity startActivitySync(@NonNull Intent intent, @Nullable Bundle options) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: intent=" + intent + " options=" + options, new Throwable());
        }
        validateNotAppThread();

        final Activity activity;
@@ -1891,6 +1900,10 @@ public class Instrumentation {
    public ActivityResult execStartActivity(
            Context who, IBinder contextThread, IBinder token, Activity target,
            Intent intent, int requestCode, Bundle options) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: who=" + who + " source=" + target + " intent=" + intent
                    + " requestCode=" + requestCode + " options=" + options, new Throwable());
        }
        Objects.requireNonNull(intent);
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        Uri referrer = target != null ? target.onProvideReferrer() : null;
@@ -1971,6 +1984,14 @@ public class Instrumentation {
    public int execStartActivitiesAsUser(Context who, IBinder contextThread,
            IBinder token, Activity target, Intent[] intents, Bundle options,
            int userId) {
        if (DEBUG_START_ACTIVITY) {
            StringJoiner joiner = new StringJoiner(", ");
            for (Intent i : intents) {
                joiner.add(i.toString());
            }
            Log.d(TAG, "startActivities: who=" + who + " source=" + target + " userId=" + userId
                    + " intents=[" + joiner + "] options=" + options, new Throwable());
        }
        Objects.requireNonNull(intents);
        for (int i = intents.length - 1; i >= 0; i--) {
            Objects.requireNonNull(intents[i]);
@@ -2055,6 +2076,11 @@ public class Instrumentation {
    public ActivityResult execStartActivity(
        Context who, IBinder contextThread, IBinder token, String target,
        Intent intent, int requestCode, Bundle options) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: who=" + who + " target=" + target
                    + " intent=" + intent + " requestCode=" + requestCode
                    + " options=" + options, new Throwable());
        }
        Objects.requireNonNull(intent);
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        if (isSdkSandboxAllowedToStartActivities()) {
@@ -2130,6 +2156,11 @@ public class Instrumentation {
    public ActivityResult execStartActivity(
            Context who, IBinder contextThread, IBinder token, String resultWho,
            Intent intent, int requestCode, Bundle options, UserHandle user) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: who=" + who + " user=" + user + " intent=" + intent
                    + " requestCode=" + requestCode + " resultWho=" + resultWho
                    + " options=" + options, new Throwable());
        }
        Objects.requireNonNull(intent);
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        if (isSdkSandboxAllowedToStartActivities()) {
@@ -2184,6 +2215,12 @@ public class Instrumentation {
            Context who, IBinder contextThread, IBinder token, Activity target,
            Intent intent, int requestCode, Bundle options,
            boolean ignoreTargetSecurity, int userId) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: who=" + who + " source=" + target + " userId=" + userId
                    + " intent=" + intent + " requestCode=" + requestCode
                    + " ignoreTargetSecurity=" + ignoreTargetSecurity + " options=" + options,
                    new Throwable());
        }
        Objects.requireNonNull(intent);
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        if (isSdkSandboxAllowedToStartActivities()) {
@@ -2239,6 +2276,10 @@ public class Instrumentation {
    public void execStartActivityFromAppTask(
            Context who, IBinder contextThread, IAppTask appTask,
            Intent intent, Bundle options) {
        if (DEBUG_START_ACTIVITY) {
            Log.d(TAG, "startActivity: who=" + who + " intent=" + intent
                    + " options=" + options, new Throwable());
        }
        Objects.requireNonNull(intent);
        IApplicationThread whoThread = (IApplicationThread) contextThread;
        if (isSdkSandboxAllowedToStartActivities()) {