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

Commit 8b1f1be2 authored by Chilun's avatar Chilun Committed by Chilun Huang
Browse files

Use the same logic to launch home activity

The original logic of startDockOrHome is using the intent with
CATEGORY_HOME to find the home activity, which is not guarantee to
support secondary display. That may cause no response when tap the home
key on secondary display.

RootActivityContainer#startHomeOnDisplay already has a complete flow to
find the proper secondary launcher for secondary display.
So, let's expose startHomeOnDisplay through ActivityTaskManagerInternal
and let PhoneWindowManager can use the same logic to launch home activity.

One more change is to be consistent with InputDispatcher to fallback to top
focused display if the specific display id is invalid.

Bug: 127348870
Test: atest ActivityManagerMultiDisplayTests
Test: atest ActivityManagerActivityVisibilityTests
Test: atest ActivityManagerSplitScreenTests#testMinimizeAndUnminimizeThenGoingHome
Test: atest ActivityMetricsLoggerTests#testAppHotLaunchSetsWaitResultDelayData
Change-Id: Iebef462f244ef2457a2e7c9ad0a706aebe291fe8
parent a3e9de11
Loading
Loading
Loading
Loading
+4 −16
Original line number Diff line number Diff line
@@ -104,7 +104,6 @@ import static com.android.server.wm.WindowManagerPolicyProto.WINDOW_MANAGER_DRAW
import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.ActivityManagerInternal;
import android.app.ActivityOptions;
import android.app.ActivityTaskManager;
import android.app.AppOpsManager;
import android.app.IUiModeManager;
@@ -5114,6 +5113,7 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            awakenDreams();
        }

        // Start dock.
        Intent dock = createHomeDockIntent();
        if (dock != null) {
            try {
@@ -5126,21 +5126,9 @@ public class PhoneWindowManager implements WindowManagerPolicy {
            }
        }

        Intent intent;

        if (fromHomeKey) {
            intent = new Intent(mHomeIntent);
            intent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, fromHomeKey);
        } else {
            intent = mHomeIntent;
        }
        final Bundle bundle = getLaunchDisplayIdBundle(displayId);
        startActivityAsUser(intent, bundle, UserHandle.CURRENT);
    }

    private @Nullable Bundle getLaunchDisplayIdBundle(int displayId) {
        return (displayId == INVALID_DISPLAY) ? null
                : ActivityOptions.makeBasic().setLaunchDisplayId(displayId).toBundle();
        // Start home.
        mActivityTaskManagerInternal.startHomeOnDisplay(mCurrentUserId, "startDockOrHome",
                displayId, fromHomeKey);
    }

    /**
+13 −0
Original line number Diff line number Diff line
@@ -352,6 +352,19 @@ public abstract class ActivityTaskManagerInternal {
    /** @return The intent used to launch the home activity. */
    public abstract Intent getHomeIntent();
    public abstract boolean startHomeActivity(int userId, String reason);
    /**
     * This starts home activity on displays that can have system decorations based on displayId -
     * Default display always use primary home component.
     * For Secondary displays, the home activity must have category SECONDARY_HOME and then resolves
     * according to the priorities listed below.
     *  - If default home is not set, always use the secondary home defined in the config.
     *  - Use currently selected primary home activity.
     *  - Use the activity in the same package as currently selected primary home activity.
     *    If there are multiple activities matched, use first one.
     *  - Use the secondary home defined in the config.
     */
    public abstract boolean startHomeOnDisplay(int userId, String reason, int displayId,
            boolean fromHomeKey);
    /** Start home activities on all displays that support system decorations. */
    public abstract boolean startHomeOnAllDisplays(int userId, String reason);
    /** @return true if the given process is the factory test process. */
+7 −0
Original line number Diff line number Diff line
@@ -6489,6 +6489,13 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        @Override
        public boolean startHomeOnDisplay(int userId, String reason, int displayId,
                boolean fromHomeKey) {
            return mRootActivityContainer.startHomeOnDisplay(userId, reason, displayId,
                    fromHomeKey);
        }

        @Override
        public boolean startHomeOnAllDisplays(int userId, String reason) {
            synchronized (mGlobalLock) {
+15 −1
Original line number Diff line number Diff line
@@ -114,6 +114,7 @@ import com.android.server.LocalServices;
import com.android.server.am.ActivityManagerService;
import com.android.server.am.AppTimeTracker;
import com.android.server.am.UserState;
import com.android.server.policy.WindowManagerPolicy;

import java.io.FileDescriptor;
import java.io.PrintWriter;
@@ -345,6 +346,10 @@ class RootActivityContainer extends ConfigurationContainer
        }
    }

    boolean startHomeOnDisplay(int userId, String reason, int displayId) {
        return startHomeOnDisplay(userId, reason, displayId, false /*fromHomeKey*/);
    }

    /**
     * This starts home activity on displays that can have system decorations based on displayId -
     * Default display always use primary home component.
@@ -356,7 +361,12 @@ class RootActivityContainer extends ConfigurationContainer
     *    If there are multiple activities matched, use first one.
     *  - Use the secondary home defined in the config.
     */
    boolean startHomeOnDisplay(int userId, String reason, int displayId) {
    boolean startHomeOnDisplay(int userId, String reason, int displayId, boolean fromHomeKey) {
        // Fallback to top focused display if the displayId is invalid.
        if (displayId == INVALID_DISPLAY) {
            displayId = getTopDisplayFocusedStack().mDisplayId;
        }

        Intent homeIntent;
        ActivityInfo aInfo;
        if (displayId == DEFAULT_DISPLAY) {
@@ -380,6 +390,10 @@ class RootActivityContainer extends ConfigurationContainer
        // Updates the home component of the intent.
        homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
        homeIntent.setFlags(homeIntent.getFlags() | FLAG_ACTIVITY_NEW_TASK);
        // Updates the extra information of the intent.
        if (fromHomeKey) {
            homeIntent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, true);
        }
        // Update the reason for ANR debugging to verify if the user activity is the one that
        // actually launched.
        final String myReason = reason + ":" + userId + ":" + UserHandle.getUserId(