From bc1eef7749589e5b450bd90505cf5bfa1621bd9b Mon Sep 17 00:00:00 2001 From: Louis Chang Date: Thu, 1 Nov 2018 17:31:52 +0800 Subject: [PATCH] Avoid starting home that targeted before Q on secondary display Some launchers don't explicitly request for single instance. Since these launchers could be launched on secondary displays and having multiple instances at the same time, the applications may not work properly if they were implemented based on a single display/instance assumption. Bug: 111363427 Test: atest ActivityStackSupervisorTests Test: atest ActivityManagerMultiDisplayTests Change-Id: Ib1de00c6bca89c0e588dd2a5883bceb8887b3f76 --- .../server/wm/ActivityStackSupervisor.java | 9 ++++++-- .../wm/ActivityStackSupervisorTests.java | 22 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java index 7b7598e9b39df..1e1b4d827feaf 100644 --- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java @@ -145,6 +145,7 @@ import android.hardware.display.DisplayManager.DisplayListener; import android.hardware.display.DisplayManagerInternal; import android.hardware.power.V1_0.PowerHint; import android.os.Binder; +import android.os.Build; import android.os.Bundle; import android.os.Debug; import android.os.FactoryTest; @@ -825,9 +826,13 @@ public class ActivityStackSupervisor extends ConfigurationContainer implements D } final boolean supportMultipleInstance = homeInfo.launchMode != LAUNCH_SINGLE_TASK - && homeInfo.launchMode != LAUNCH_SINGLE_INSTANCE; + && homeInfo.launchMode != LAUNCH_SINGLE_INSTANCE + && homeInfo.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.Q; if (!supportMultipleInstance) { - // Can't launch home on other displays if it requested to be single instance. + // Can't launch home on other displays if it requested to be single instance. Also we + // don't allow home applications that target before Q to have multiple home activity + // instances because they may not be expected to have multiple home scenario and + // haven't explicitly request for single instance. return false; } diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java index f692a571b0193..16dd92f5f6c3e 100644 --- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java +++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java @@ -25,6 +25,7 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN_OR_SPLIT import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED; import static android.app.WindowConfiguration.WINDOWING_MODE_SPLIT_SCREEN_PRIMARY; import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE; +import static android.content.pm.ActivityInfo.LAUNCH_MULTIPLE; import static android.view.Display.DEFAULT_DISPLAY; import static com.android.server.wm.ActivityDisplay.POSITION_TOP; @@ -57,6 +58,7 @@ import android.app.WaitResult; import android.content.pm.ActivityInfo; import android.content.pm.ApplicationInfo; import android.graphics.Rect; +import android.os.Build; import android.platform.test.annotations.Presubmit; import androidx.test.filters.MediumTest; @@ -433,6 +435,26 @@ public class ActivityStackSupervisorTests extends ActivityTestsBase { eq(activity), eq(null /* targetOptions */)); } + /** + * Tests home activities that targeted sdk before Q cannot start on secondary display. + */ + @Test + public void testStartHomeTargetSdkBeforeQ() throws Exception { + final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay()); + mSupervisor.addChild(secondDisplay, POSITION_TOP); + doReturn(true).when(secondDisplay).supportsSystemDecorations(); + + final ActivityInfo info = new ActivityInfo(); + info.launchMode = LAUNCH_MULTIPLE; + info.applicationInfo = new ApplicationInfo(); + info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.Q; + assertTrue(mSupervisor.canStartHomeOnDisplay(info, secondDisplay.mDisplayId, + false /* allowInstrumenting */)); + + info.applicationInfo.targetSdkVersion = Build.VERSION_CODES.P; + assertFalse(mSupervisor.canStartHomeOnDisplay(info, secondDisplay.mDisplayId, + false /* allowInstrumenting */)); + } /** * Tests that home activities can be started on the displays that supports system decorations.