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

Commit 822ca6ec authored by Charles Chen's avatar Charles Chen
Browse files

Improve logging of embed failure

There's a lot of issue about embed failure from 1P apps.
Usually, it's because the Activity is going to launch on a new Task,
which is not allowed to embed.
This Cl tries to improve the logging to make 1P developers know how
to fix the embed failure.

fixes: 234414942
Test: presubmit
Change-Id: Id0ea961997afdec2b4f7d49c56f76e9ffc2f0360
parent 615efcdc
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -106,6 +106,24 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
    public @interface LaunchMode {
    }

    /** @hide */
    public static String launchModeToString(@LaunchMode int launchMode) {
        switch(launchMode) {
            case LAUNCH_MULTIPLE:
                return "LAUNCH_MULTIPLE";
            case LAUNCH_SINGLE_TOP:
                return "LAUNCH_SINGLE_TOP";
            case LAUNCH_SINGLE_TASK:
                return "LAUNCH_SINGLE_TASK";
            case LAUNCH_SINGLE_INSTANCE:
                return "LAUNCH_SINGLE_INSTANCE";
            case LAUNCH_SINGLE_INSTANCE_PER_TASK:
                return "LAUNCH_SINGLE_INSTANCE_PER_TASK";
            default:
                return "unknown=" + launchMode;
        }
    }

    /**
     * The launch mode style requested by the activity.  From the
     * {@link android.R.attr#launchMode} attribute.
@@ -1585,7 +1603,7 @@ public class ActivityInfo extends ComponentInfo implements Parcelable {
                    + " persistableMode=" + persistableModeToString());
        }
        if (launchMode != 0 || flags != 0 || privateFlags != 0 || theme != 0) {
            pw.println(prefix + "launchMode=" + launchMode
            pw.println(prefix + "launchMode=" + launchModeToString(launchMode)
                    + " flags=0x" + Integer.toHexString(flags)
                    + " privateFlags=0x" + Integer.toHexString(privateFlags)
                    + " theme=0x" + Integer.toHexString(theme));
+17 −8
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_INSTANCE_PER_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TASK;
import static android.content.pm.ActivityInfo.LAUNCH_SINGLE_TOP;
import static android.content.pm.ActivityInfo.launchModeToString;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;
import static android.os.Process.INVALID_UID;
import static android.view.Display.DEFAULT_DISPLAY;
@@ -2041,8 +2042,20 @@ class ActivityStarter {
        }

        if (mInTaskFragment != null && !canEmbedActivity(mInTaskFragment, r, newTask, targetTask)) {
            Slog.e(TAG, "Permission denied: Cannot embed " + r + " to " + mInTaskFragment.getTask()
                    + " targetTask= " + targetTask);
            final StringBuilder errorMsg = new StringBuilder("Permission denied: Cannot embed " + r
                    + " to " + mInTaskFragment.getTask() + ". newTask=" + newTask + ", targetTask= "
                    + targetTask);
            if (newTask && isLaunchModeOneOf(LAUNCH_SINGLE_INSTANCE,
                    LAUNCH_SINGLE_INSTANCE_PER_TASK, LAUNCH_SINGLE_TASK)) {
                errorMsg.append("\nActivity tries to launch on a new task because the launch mode"
                        + " is " + launchModeToString(mLaunchMode));
            } else if (newTask && (mLaunchFlags & (FLAG_ACTIVITY_NEW_DOCUMENT
                    | FLAG_ACTIVITY_NEW_TASK)) != 0) {
                errorMsg.append("\nActivity tries to launch on a new task because the launch flags"
                        + " contains FLAG_ACTIVITY_NEW_DOCUMENT or FLAG_ACTIVITY_NEW_TASK. "
                        + "mLaunchFlag=" + mLaunchFlags);
            }
            Slog.e(TAG, errorMsg.toString());
            return START_PERMISSION_DENIED;
        }

@@ -3232,12 +3245,8 @@ class ActivityStarter {
            pw.println(mOptions);
        }
        pw.print(prefix);
        pw.print("mLaunchSingleTop=");
        pw.print(LAUNCH_SINGLE_TOP == mLaunchMode);
        pw.print(" mLaunchSingleInstance=");
        pw.print(LAUNCH_SINGLE_INSTANCE == mLaunchMode);
        pw.print(" mLaunchSingleTask=");
        pw.println(LAUNCH_SINGLE_TASK == mLaunchMode);
        pw.print("mLaunchMode=");
        pw.print(launchModeToString(mLaunchMode));
        pw.print(prefix);
        pw.print("mLaunchFlags=0x");
        pw.print(Integer.toHexString(mLaunchFlags));