diff options
4 files changed, 18 insertions, 64 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt index 82181788e1be..179ba2256442 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt @@ -20,9 +20,7 @@ import android.appwidget.AppWidgetProviderInfo import android.content.ActivityNotFoundException import android.content.ComponentName import android.content.Intent -import android.content.pm.ActivityInfo import android.content.pm.PackageManager -import android.content.pm.ResolveInfo import android.content.pm.UserInfo import android.provider.Settings import android.view.accessibility.AccessibilityEvent @@ -72,7 +70,6 @@ import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith -import org.mockito.ArgumentMatchers.anyInt import org.mockito.Mock import org.mockito.Mockito import org.mockito.Mockito.never @@ -141,6 +138,7 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { context, accessibilityManager, packageManager, + WIDGET_PICKER_PACKAGE_NAME, ) } @@ -259,18 +257,8 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { @Test fun onOpenWidgetPicker_launchesWidgetPickerActivity() { testScope.runTest { - whenever(packageManager.resolveActivity(any(), anyInt())).then { - ResolveInfo().apply { - activityInfo = ActivityInfo().apply { packageName = WIDGET_PICKER_PACKAGE_NAME } - } - } - val success = - underTest.onOpenWidgetPicker( - testableResources.resources, - packageManager, - activityResultLauncher - ) + underTest.onOpenWidgetPicker(testableResources.resources, activityResultLauncher) verify(activityResultLauncher).launch(any()) assertTrue(success) @@ -278,38 +266,14 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { } @Test - fun onOpenWidgetPicker_launcherActivityNotResolved_doesNotLaunchWidgetPickerActivity() { - testScope.runTest { - whenever(packageManager.resolveActivity(any(), anyInt())).thenReturn(null) - - val success = - underTest.onOpenWidgetPicker( - testableResources.resources, - packageManager, - activityResultLauncher - ) - - verify(activityResultLauncher, never()).launch(any()) - assertFalse(success) - } - } - - @Test fun onOpenWidgetPicker_activityLaunchThrowsException_failure() { testScope.runTest { - whenever(packageManager.resolveActivity(any(), anyInt())).then { - ResolveInfo().apply { - activityInfo = ActivityInfo().apply { packageName = WIDGET_PICKER_PACKAGE_NAME } - } - } - whenever(activityResultLauncher.launch(any())) .thenThrow(ActivityNotFoundException::class.java) val success = underTest.onOpenWidgetPicker( testableResources.resources, - packageManager, activityResultLauncher, ) diff --git a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt index ba2b7bf96a30..a33e0ac0b33a 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/dagger/CommunalModule.kt @@ -17,6 +17,7 @@ package com.android.systemui.communal.dagger import android.content.Context +import android.content.res.Resources import com.android.systemui.CoreStartable import com.android.systemui.communal.data.backup.CommunalBackupUtils import com.android.systemui.communal.data.db.CommunalDatabaseModule @@ -38,6 +39,8 @@ import com.android.systemui.communal.widgets.EditWidgetsActivityStarter import com.android.systemui.communal.widgets.EditWidgetsActivityStarterImpl import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Application +import com.android.systemui.dagger.qualifiers.Main +import com.android.systemui.res.R import com.android.systemui.scene.shared.model.SceneContainerConfig import com.android.systemui.scene.shared.model.SceneDataSource import com.android.systemui.scene.shared.model.SceneDataSourceDelegator @@ -90,6 +93,7 @@ interface CommunalModule { companion object { const val LOGGABLE_PREFIXES = "loggable_prefixes" + const val LAUNCHER_PACKAGE = "launcher_package" @Provides @Communal @@ -126,5 +130,12 @@ interface CommunalModule { .getStringArray(com.android.internal.R.array.config_loggable_dream_prefixes) .toList() } + + /** The package name of the launcher */ + @Provides + @Named(LAUNCHER_PACKAGE) + fun provideLauncherPackage(@Main resources: Resources): String { + return resources.getString(R.string.launcher_overlayable_package) + } } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt index 16788d15b269..65f0679c4266 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt @@ -29,6 +29,7 @@ import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityManager import androidx.activity.result.ActivityResultLauncher import com.android.internal.logging.UiEventLogger +import com.android.systemui.communal.dagger.CommunalModule.Companion.LAUNCHER_PACKAGE import com.android.systemui.communal.data.model.CommunalWidgetCategories import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor @@ -81,6 +82,7 @@ constructor( @Application private val context: Context, private val accessibilityManager: AccessibilityManager, private val packageManager: PackageManager, + @Named(LAUNCHER_PACKAGE) private val launcherPackage: String, ) : BaseCommunalViewModel(communalSceneInteractor, communalInteractor, mediaHost) { private val logger = Logger(logBuffer, "CommunalEditModeViewModel") @@ -185,7 +187,6 @@ constructor( /** Launch the widget picker activity using the given {@link ActivityResultLauncher}. */ suspend fun onOpenWidgetPicker( resources: Resources, - packageManager: PackageManager, activityLauncher: ActivityResultLauncher<Intent> ): Boolean = withContext(backgroundDispatcher) { @@ -196,7 +197,7 @@ constructor( ) { it.providerInfo } - getWidgetPickerActivityIntent(resources, packageManager, excludeList)?.let { + getWidgetPickerActivityIntent(resources, excludeList)?.let { try { activityLauncher.launch(it) return@withContext true @@ -209,18 +210,10 @@ constructor( private fun getWidgetPickerActivityIntent( resources: Resources, - packageManager: PackageManager, excludeList: ArrayList<AppWidgetProviderInfo> ): Intent? { - val packageName = - getLauncherPackageName(packageManager) - ?: run { - Log.e(TAG, "Couldn't resolve launcher package name") - return@getWidgetPickerActivityIntent null - } - return Intent(Intent.ACTION_PICK).apply { - setPackage(packageName) + setPackage(launcherPackage) putExtra( EXTRA_DESIRED_WIDGET_WIDTH, resources.getDimensionPixelSize(R.dimen.communal_widget_picker_desired_width) @@ -247,16 +240,6 @@ constructor( } } - private fun getLauncherPackageName(packageManager: PackageManager): String? { - return packageManager - .resolveActivity( - Intent(Intent.ACTION_MAIN).also { it.addCategory(Intent.CATEGORY_HOME) }, - PackageManager.MATCH_DEFAULT_ONLY - ) - ?.activityInfo - ?.packageName - } - /** Sets whether edit mode is currently open */ fun setEditModeOpen(isOpen: Boolean) = communalInteractor.setEditModeOpen(isOpen) diff --git a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt index 55a24d0f595a..d84dc209196e 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/widgets/EditWidgetsActivity.kt @@ -270,11 +270,7 @@ constructor( private fun onOpenWidgetPicker() { lifecycleScope.launch { - communalViewModel.onOpenWidgetPicker( - resources, - packageManager, - addWidgetActivityLauncher - ) + communalViewModel.onOpenWidgetPicker(resources, addWidgetActivityLauncher) } } |