Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/MultiInstanceHelper.kt +7 −3 Original line number Diff line number Diff line Loading @@ -21,11 +21,9 @@ import android.content.Context import android.content.pm.LauncherApps import android.content.pm.PackageManager import android.os.UserHandle import android.view.WindowManager import android.view.WindowManager.PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI import com.android.internal.annotations.VisibleForTesting import com.android.wm.shell.R import com.android.wm.shell.protolog.ShellProtoLogGroup import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL import com.android.wm.shell.util.KtProtoLog import java.util.Arrays Loading @@ -37,7 +35,8 @@ class MultiInstanceHelper @JvmOverloads constructor( private val context: Context, private val packageManager: PackageManager, private val staticAppsSupportingMultiInstance: Array<String> = context.resources .getStringArray(R.array.config_appsSupportMultiInstancesSplit)) { .getStringArray(R.array.config_appsSupportMultiInstancesSplit), private val supportsMultiInstanceProperty: Boolean) { /** * Returns whether a specific component desires to be launched in multiple instances. Loading @@ -59,6 +58,11 @@ class MultiInstanceHelper @JvmOverloads constructor( } } if (!supportsMultiInstanceProperty) { // If not checking the multi-instance properties, then return early return false; } // Check the activity property first try { val activityProp = packageManager.getProperty( Loading libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +3 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.window.SystemPerformanceHinter; import com.android.internal.logging.UiEventLogger; import com.android.launcher3.icons.IconProvider; import com.android.window.flags.Flags; import com.android.wm.shell.ProtoLogController; import com.android.wm.shell.R; import com.android.wm.shell.RootDisplayAreaOrganizer; Loading Loading @@ -326,7 +327,8 @@ public abstract class WMShellBaseModule { @WMSingleton @Provides static MultiInstanceHelper provideMultiInstanceHelper(Context context) { return new MultiInstanceHelper(context, context.getPackageManager()); return new MultiInstanceHelper(context, context.getPackageManager(), Flags.supportsMultiInstanceSystemUi()); } // Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/MultiInstanceHelperTest.kt +29 −6 Original line number Diff line number Diff line Loading @@ -32,9 +32,12 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers.eq import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) Loading Loading @@ -77,7 +80,7 @@ class MultiInstanceHelperTest : ShellTestCase() { @Test fun supportsMultiInstanceSplit_inStaticAllowList() { val allowList = arrayOf(TEST_PACKAGE) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList, true) val component = ComponentName(TEST_PACKAGE, TEST_ACTIVITY) assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -85,7 +88,7 @@ class MultiInstanceHelperTest : ShellTestCase() { @Test fun supportsMultiInstanceSplit_notInStaticAllowList() { val allowList = arrayOf(TEST_PACKAGE) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList, true) val component = ComponentName(TEST_NOT_ALLOWED_PACKAGE, TEST_ACTIVITY) assertEquals(false, helper.supportsMultiInstanceSplit(component)) } Loading @@ -104,7 +107,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect activity property to override application property assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -123,7 +126,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect activity property to override application property assertEquals(false, helper.supportsMultiInstanceSplit(component)) } Loading @@ -141,7 +144,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect fall through to app property assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -158,10 +161,30 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenThrow(PackageManager.NameNotFoundException()) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) assertEquals(false, helper.supportsMultiInstanceSplit(component)) } @Test @Throws(PackageManager.NameNotFoundException::class) fun checkNoMultiInstancePropertyFlag_ignoreProperty() { val component = ComponentName(TEST_PACKAGE, TEST_ACTIVITY) val pm = mock<PackageManager>() val activityProp = PackageManager.Property("", true, "", "") whenever(pm.getProperty(eq(PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI), eq(component))) .thenReturn(activityProp) val appProp = PackageManager.Property("", true, "", "") whenever(pm.getProperty(eq(PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI), eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), false) // Expect we only check the static list and not the property assertEquals(false, helper.supportsMultiInstanceSplit(component)) verify(pm, never()).getProperty(any(), any<ComponentName>()) } companion object { val TEST_PACKAGE = "com.android.wm.shell.common" val TEST_NOT_ALLOWED_PACKAGE = "com.android.wm.shell.common.fake"; Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/MultiInstanceHelper.kt +7 −3 Original line number Diff line number Diff line Loading @@ -21,11 +21,9 @@ import android.content.Context import android.content.pm.LauncherApps import android.content.pm.PackageManager import android.os.UserHandle import android.view.WindowManager import android.view.WindowManager.PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI import com.android.internal.annotations.VisibleForTesting import com.android.wm.shell.R import com.android.wm.shell.protolog.ShellProtoLogGroup import com.android.wm.shell.protolog.ShellProtoLogGroup.WM_SHELL import com.android.wm.shell.util.KtProtoLog import java.util.Arrays Loading @@ -37,7 +35,8 @@ class MultiInstanceHelper @JvmOverloads constructor( private val context: Context, private val packageManager: PackageManager, private val staticAppsSupportingMultiInstance: Array<String> = context.resources .getStringArray(R.array.config_appsSupportMultiInstancesSplit)) { .getStringArray(R.array.config_appsSupportMultiInstancesSplit), private val supportsMultiInstanceProperty: Boolean) { /** * Returns whether a specific component desires to be launched in multiple instances. Loading @@ -59,6 +58,11 @@ class MultiInstanceHelper @JvmOverloads constructor( } } if (!supportsMultiInstanceProperty) { // If not checking the multi-instance properties, then return early return false; } // Check the activity property first try { val activityProp = packageManager.getProperty( Loading
libs/WindowManager/Shell/src/com/android/wm/shell/dagger/WMShellBaseModule.java +3 −1 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.window.SystemPerformanceHinter; import com.android.internal.logging.UiEventLogger; import com.android.launcher3.icons.IconProvider; import com.android.window.flags.Flags; import com.android.wm.shell.ProtoLogController; import com.android.wm.shell.R; import com.android.wm.shell.RootDisplayAreaOrganizer; Loading Loading @@ -326,7 +327,8 @@ public abstract class WMShellBaseModule { @WMSingleton @Provides static MultiInstanceHelper provideMultiInstanceHelper(Context context) { return new MultiInstanceHelper(context, context.getPackageManager()); return new MultiInstanceHelper(context, context.getPackageManager(), Flags.supportsMultiInstanceSystemUi()); } // Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/MultiInstanceHelperTest.kt +29 −6 Original line number Diff line number Diff line Loading @@ -32,9 +32,12 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers import org.mockito.ArgumentMatchers.eq import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.doThrow import org.mockito.kotlin.mock import org.mockito.kotlin.never import org.mockito.kotlin.verify import org.mockito.kotlin.whenever @RunWith(AndroidJUnit4::class) Loading Loading @@ -77,7 +80,7 @@ class MultiInstanceHelperTest : ShellTestCase() { @Test fun supportsMultiInstanceSplit_inStaticAllowList() { val allowList = arrayOf(TEST_PACKAGE) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList, true) val component = ComponentName(TEST_PACKAGE, TEST_ACTIVITY) assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -85,7 +88,7 @@ class MultiInstanceHelperTest : ShellTestCase() { @Test fun supportsMultiInstanceSplit_notInStaticAllowList() { val allowList = arrayOf(TEST_PACKAGE) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList) val helper = MultiInstanceHelper(mContext, context.packageManager, allowList, true) val component = ComponentName(TEST_NOT_ALLOWED_PACKAGE, TEST_ACTIVITY) assertEquals(false, helper.supportsMultiInstanceSplit(component)) } Loading @@ -104,7 +107,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect activity property to override application property assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -123,7 +126,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect activity property to override application property assertEquals(false, helper.supportsMultiInstanceSplit(component)) } Loading @@ -141,7 +144,7 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) // Expect fall through to app property assertEquals(true, helper.supportsMultiInstanceSplit(component)) } Loading @@ -158,10 +161,30 @@ class MultiInstanceHelperTest : ShellTestCase() { eq(component.packageName))) .thenThrow(PackageManager.NameNotFoundException()) val helper = MultiInstanceHelper(mContext, pm, emptyArray()) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), true) assertEquals(false, helper.supportsMultiInstanceSplit(component)) } @Test @Throws(PackageManager.NameNotFoundException::class) fun checkNoMultiInstancePropertyFlag_ignoreProperty() { val component = ComponentName(TEST_PACKAGE, TEST_ACTIVITY) val pm = mock<PackageManager>() val activityProp = PackageManager.Property("", true, "", "") whenever(pm.getProperty(eq(PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI), eq(component))) .thenReturn(activityProp) val appProp = PackageManager.Property("", true, "", "") whenever(pm.getProperty(eq(PROPERTY_SUPPORTS_MULTI_INSTANCE_SYSTEM_UI), eq(component.packageName))) .thenReturn(appProp) val helper = MultiInstanceHelper(mContext, pm, emptyArray(), false) // Expect we only check the static list and not the property assertEquals(false, helper.supportsMultiInstanceSplit(component)) verify(pm, never()).getProperty(any(), any<ComponentName>()) } companion object { val TEST_PACKAGE = "com.android.wm.shell.common" val TEST_NOT_ALLOWED_PACKAGE = "com.android.wm.shell.common.fake"; Loading