Merge "Fix crash of PictureInPicture" into udc-dev am: 5b042e2feb am: 2c4c75ebc6

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/23408018

Change-Id: Ida03b8db306928177905957266b147166e43c55b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Chaohui Wang
2023-05-25 07:27:17 +00:00
committed by Automerger Merge Worker
2 changed files with 71 additions and 20 deletions

View File

@@ -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)