Get and save app label before archiving the app
Test: manual Bug: 317125320 Change-Id: I34763106f669e3f2c0f349cdec977ceb57291e01
This commit is contained in:
@@ -54,6 +54,7 @@ class AppArchiveButton(
|
||||
private val packageName = packageInfoPresenter.packageName
|
||||
private val userHandle = UserHandle.of(packageInfoPresenter.userId)
|
||||
private var broadcastReceiverIsCreated = false
|
||||
private lateinit var appLabel: CharSequence
|
||||
|
||||
@Composable
|
||||
fun getActionButton(app: ApplicationInfo): ActionButton {
|
||||
@@ -61,11 +62,12 @@ class AppArchiveButton(
|
||||
val intentFilter = IntentFilter(INTENT_ACTION)
|
||||
DisposableBroadcastReceiverAsUser(intentFilter, userHandle) { intent ->
|
||||
if (app.packageName == intent.getStringExtra(PackageInstaller.EXTRA_PACKAGE_NAME)) {
|
||||
onReceive(intent, app)
|
||||
onReceive(intent)
|
||||
}
|
||||
}
|
||||
broadcastReceiverIsCreated = true
|
||||
}
|
||||
appLabel = userPackageManager.getApplicationLabel(app)
|
||||
return ActionButton(
|
||||
text = context.getString(R.string.archive),
|
||||
imageVector = Icons.Outlined.CloudUpload,
|
||||
@@ -113,10 +115,9 @@ class AppArchiveButton(
|
||||
}
|
||||
}
|
||||
|
||||
private fun onReceive(intent: Intent, app: ApplicationInfo) {
|
||||
private fun onReceive(intent: Intent) {
|
||||
when (val status = intent.getIntExtra(PackageInstaller.EXTRA_STATUS, Int.MIN_VALUE)) {
|
||||
PackageInstaller.STATUS_SUCCESS -> {
|
||||
val appLabel = userPackageManager.getApplicationLabel(app)
|
||||
Toast.makeText(
|
||||
context,
|
||||
context.getString(R.string.archiving_succeeded, appLabel),
|
||||
|
@@ -63,8 +63,10 @@ class AppArchiveButtonTest {
|
||||
whenever(packageInfoPresenter.context).thenReturn(context)
|
||||
whenever(packageInfoPresenter.userPackageManager).thenReturn(userPackageManager)
|
||||
whenever(userPackageManager.packageInstaller).thenReturn(packageInstaller)
|
||||
whenever(userPackageManager.getApplicationLabel(any())).thenReturn(APP_LABEL)
|
||||
whenever(packageInfoPresenter.packageName).thenReturn(PACKAGE_NAME)
|
||||
appArchiveButton = AppArchiveButton(packageInfoPresenter, isHibernationSwitchEnabledStateFlow)
|
||||
appArchiveButton =
|
||||
AppArchiveButton(packageInfoPresenter, isHibernationSwitchEnabledStateFlow)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,5 +152,6 @@ class AppArchiveButtonTest {
|
||||
|
||||
private companion object {
|
||||
const val PACKAGE_NAME = "package.name"
|
||||
const val APP_LABEL = "App label"
|
||||
}
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ import org.junit.runner.RunWith
|
||||
import org.mockito.Mock
|
||||
import org.mockito.MockitoSession
|
||||
import org.mockito.Spy
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.quality.Strictness
|
||||
import org.mockito.Mockito.`when` as whenever
|
||||
|
||||
@@ -80,6 +81,7 @@ class AppButtonsTest {
|
||||
whenever(packageInfoPresenter.context).thenReturn(context)
|
||||
whenever(packageInfoPresenter.packageName).thenReturn(PACKAGE_NAME)
|
||||
whenever(packageInfoPresenter.userPackageManager).thenReturn(packageManager)
|
||||
whenever(packageManager.getApplicationLabel(any())).thenReturn(APP_LABEL)
|
||||
whenever(packageManager.packageInstaller).thenReturn(packageInstaller)
|
||||
whenever(packageManager.getPackageInfo(PACKAGE_NAME, 0)).thenReturn(PACKAGE_INFO)
|
||||
whenever(AppUtils.isMainlineModule(packageManager, PACKAGE_NAME)).thenReturn(false)
|
||||
@@ -113,7 +115,8 @@ class AppButtonsTest {
|
||||
featureFlags.setFlag(Flags.FLAG_ARCHIVING, false)
|
||||
setContent()
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_instant_app)).assertIsDisplayed()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_instant_app))
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +125,8 @@ class AppButtonsTest {
|
||||
featureFlags.setFlag(Flags.FLAG_ARCHIVING, true)
|
||||
setContent()
|
||||
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_instant_app)).assertIsNotDisplayed()
|
||||
composeTestRule.onNodeWithText(context.getString(R.string.launch_instant_app))
|
||||
.assertIsNotDisplayed()
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -184,6 +188,7 @@ class AppButtonsTest {
|
||||
|
||||
private companion object {
|
||||
const val PACKAGE_NAME = "package.name"
|
||||
const val APP_LABEL = "App label"
|
||||
val PACKAGE_INFO = PackageInfo().apply {
|
||||
applicationInfo = ApplicationInfo().apply {
|
||||
packageName = PACKAGE_NAME
|
||||
|
Reference in New Issue
Block a user