Fix crash of PictureInPicture
This follows change I3115cf1b99a305efef192a0dcf3e809eb7903d0a PackageManager.getPackageInfoAsUser() will throw exceptions when the package is too large which is a known issue to PackageManager but very low priority given resourcing constraints. As per the PackageManager team suggestion, catch the exception on the app side to alleviate the impact to the PictureInPicture & App info page. Fix: 283076353 Fix: 283354211 Test: Unit test Change-Id: Iad2bf9fbfca6ee7f604fec1c4afa1b9382f6ec7e
This commit is contained in:
@@ -23,6 +23,7 @@ import android.content.pm.ApplicationInfo
|
||||
import android.content.pm.PackageInfo
|
||||
import android.content.pm.PackageManager
|
||||
import android.content.pm.PackageManager.PackageInfoFlags
|
||||
import android.os.DeadSystemRuntimeException
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import com.android.settings.R
|
||||
@@ -100,6 +101,23 @@ class PictureInPictureTest {
|
||||
assertThat(record.isSupport).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transform_getInstalledPackagesAsUserThrowsException_treatAsNotSupported() = runTest {
|
||||
whenever(packageManager.getInstalledPackagesAsUser(any<PackageInfoFlags>(), anyInt()))
|
||||
.thenThrow(DeadSystemRuntimeException())
|
||||
|
||||
val recordListFlow = listModel.transform(
|
||||
userIdFlow = flowOf(USER_ID),
|
||||
appListFlow = flowOf(listOf(PICTURE_IN_PICTURE_APP)),
|
||||
)
|
||||
|
||||
val recordList = recordListFlow.first()
|
||||
assertThat(recordList).hasSize(1)
|
||||
val record = recordList[0]
|
||||
assertThat(record.app).isSameInstanceAs(PICTURE_IN_PICTURE_APP)
|
||||
assertThat(record.isSupport).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transformItem() {
|
||||
whenever(
|
||||
@@ -114,6 +132,20 @@ class PictureInPictureTest {
|
||||
assertThat(record.isSupport).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transformItem_getPackageInfoAsUserThrowsException_treatAsNotSupported() {
|
||||
whenever(
|
||||
packageManager.getPackageInfoAsUser(
|
||||
eq(PICTURE_IN_PICTURE_PACKAGE_NAME), any<PackageInfoFlags>(), eq(USER_ID)
|
||||
)
|
||||
).thenThrow(DeadSystemRuntimeException())
|
||||
|
||||
val record = listModel.transformItem(PICTURE_IN_PICTURE_APP)
|
||||
|
||||
assertThat(record.app).isSameInstanceAs(PICTURE_IN_PICTURE_APP)
|
||||
assertThat(record.isSupport).isFalse()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun filter_isSupport() = runTest {
|
||||
val record = createRecord(isSupport = true)
|
||||
|
||||
Reference in New Issue
Block a user