Fix NPE for where intent.package is null but targetpkg is not.
- Also update WorkspaceItemProcessorTest with a new test and to use real intent instead of mock Bug: 330250727 Test: unit tests Flag: N/A Change-Id: I77e17901f4754c301ca20b3c6f93bbe29bead59b
This commit is contained in:
1 parent
4d91e16589
commit
ce255ff6fd
2 files changed
+80
-35
No files matched your search
@@ -184,6 +184,9 @@ class WorkspaceItemProcessor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (intent.`package` == null) {
|
||||||
|
intent.`package` = targetPkg
|
||||||
|
}
|
||||||
// else if cn == null => can't infer much, leave it
|
// else if cn == null => can't infer much, leave it
|
||||||
// else if !validPkg => could be restored icon or missing sd-card
|
// else if !validPkg => could be restored icon or missing sd-card
|
||||||
when {
|
when {
|
||||||
@@ -329,8 +332,12 @@ class WorkspaceItemProcessor(
|
|||||||
}
|
}
|
||||||
val activityInfo = c.launcherActivityInfo
|
val activityInfo = c.launcherActivityInfo
|
||||||
if (activityInfo != null) {
|
if (activityInfo != null) {
|
||||||
AppInfo.updateRuntimeFlagsForActivityTarget(info, activityInfo,
|
AppInfo.updateRuntimeFlagsForActivityTarget(
|
||||||
userCache.getUserInfo(c.user), ApiWrapper.INSTANCE[app.context])
|
info,
|
||||||
|
activityInfo,
|
||||||
|
userCache.getUserInfo(c.user),
|
||||||
|
ApiWrapper.INSTANCE[app.context]
|
||||||
|
)
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
(c.restoreFlag != 0 ||
|
(c.restoreFlag != 0 ||
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ class WorkspaceItemProcessorTest {
|
|||||||
@Mock private lateinit var mockBgDataModel: BgDataModel
|
@Mock private lateinit var mockBgDataModel: BgDataModel
|
||||||
@Mock private lateinit var mockContext: Context
|
@Mock private lateinit var mockContext: Context
|
||||||
@Mock private lateinit var mockAppState: LauncherAppState
|
@Mock private lateinit var mockAppState: LauncherAppState
|
||||||
@Mock private lateinit var mockIntent: Intent
|
|
||||||
@Mock private lateinit var mockPmHelper: PackageManagerHelper
|
@Mock private lateinit var mockPmHelper: PackageManagerHelper
|
||||||
@Mock private lateinit var mockLauncherApps: LauncherApps
|
@Mock private lateinit var mockLauncherApps: LauncherApps
|
||||||
@Mock private lateinit var mockCursor: LoaderCursor
|
@Mock private lateinit var mockCursor: LoaderCursor
|
||||||
@@ -74,6 +73,7 @@ class WorkspaceItemProcessorTest {
|
|||||||
@Mock private lateinit var mockUserManagerState: UserManagerState
|
@Mock private lateinit var mockUserManagerState: UserManagerState
|
||||||
@Mock private lateinit var mockWidgetInflater: WidgetInflater
|
@Mock private lateinit var mockWidgetInflater: WidgetInflater
|
||||||
|
|
||||||
|
private lateinit var intent: Intent
|
||||||
private lateinit var userHandle: UserHandle
|
private lateinit var userHandle: UserHandle
|
||||||
private lateinit var iconRequestInfos: MutableList<IconRequestInfo<WorkspaceItemInfo>>
|
private lateinit var iconRequestInfos: MutableList<IconRequestInfo<WorkspaceItemInfo>>
|
||||||
private lateinit var componentName: ComponentName
|
private lateinit var componentName: ComponentName
|
||||||
@@ -93,11 +93,11 @@ class WorkspaceItemProcessorTest {
|
|||||||
mockBgDataModel = mock<BgDataModel>()
|
mockBgDataModel = mock<BgDataModel>()
|
||||||
componentName = ComponentName("package", "class")
|
componentName = ComponentName("package", "class")
|
||||||
unlockedUsersArray = LongSparseArray<Boolean>(1).apply { put(101, true) }
|
unlockedUsersArray = LongSparseArray<Boolean>(1).apply { put(101, true) }
|
||||||
mockIntent =
|
intent =
|
||||||
mock<Intent>().apply {
|
Intent().apply {
|
||||||
whenever(component).thenReturn(componentName)
|
component = componentName
|
||||||
whenever(`package`).thenReturn("pkg")
|
`package` = "pkg"
|
||||||
whenever(getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID)).thenReturn("")
|
putExtra(ShortcutKey.EXTRA_SHORTCUT_ID, "")
|
||||||
}
|
}
|
||||||
mockContext =
|
mockContext =
|
||||||
mock<Context>().apply {
|
mock<Context>().apply {
|
||||||
@@ -113,7 +113,7 @@ class WorkspaceItemProcessorTest {
|
|||||||
mockPmHelper =
|
mockPmHelper =
|
||||||
mock<PackageManagerHelper>().apply {
|
mock<PackageManagerHelper>().apply {
|
||||||
whenever(getAppLaunchIntent(componentName.packageName, userHandle))
|
whenever(getAppLaunchIntent(componentName.packageName, userHandle))
|
||||||
.thenReturn(mockIntent)
|
.thenReturn(intent)
|
||||||
}
|
}
|
||||||
mockLauncherApps =
|
mockLauncherApps =
|
||||||
mock<LauncherApps>().apply {
|
mock<LauncherApps>().apply {
|
||||||
@@ -127,19 +127,17 @@ class WorkspaceItemProcessorTest {
|
|||||||
id = 1
|
id = 1
|
||||||
restoreFlag = 1
|
restoreFlag = 1
|
||||||
serialNumber = 101
|
serialNumber = 101
|
||||||
whenever(parseIntent()).thenReturn(mockIntent)
|
whenever(parseIntent()).thenReturn(intent)
|
||||||
whenever(markRestored()).doAnswer { restoreFlag = 0 }
|
whenever(markRestored()).doAnswer { restoreFlag = 0 }
|
||||||
whenever(updater().put(Favorites.INTENT, mockIntent.toUri(0)).commit())
|
whenever(updater().put(Favorites.INTENT, intent.toUri(0)).commit()).thenReturn(1)
|
||||||
.thenReturn(1)
|
|
||||||
whenever(getAppShortcutInfo(any(), any(), any(), any()))
|
whenever(getAppShortcutInfo(any(), any(), any(), any()))
|
||||||
.thenReturn(mockWorkspaceInfo)
|
.thenReturn(mockWorkspaceInfo)
|
||||||
whenever(createIconRequestInfo(any(), any())).thenReturn(mockIconRequestInfo)
|
whenever(createIconRequestInfo(any(), any())).thenReturn(mockIconRequestInfo)
|
||||||
}
|
}
|
||||||
mockUserCache =
|
mockUserCache =
|
||||||
mock<UserCache>().apply {
|
mock<UserCache>().apply {
|
||||||
val userIconInfo = mock<UserIconInfo>().apply() {
|
val userIconInfo =
|
||||||
whenever(isPrivate).thenReturn(false)
|
mock<UserIconInfo>().apply() { whenever(isPrivate).thenReturn(false) }
|
||||||
}
|
|
||||||
whenever(getUserInfo(any())).thenReturn(userIconInfo)
|
whenever(getUserInfo(any())).thenReturn(userIconInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,9 +196,11 @@ class WorkspaceItemProcessorTest {
|
|||||||
fun `When user is null then mark item deleted`() {
|
fun `When user is null then mark item deleted`() {
|
||||||
// Given
|
// Given
|
||||||
mockCursor = mock<LoaderCursor>().apply { id = 1 }
|
mockCursor = mock<LoaderCursor>().apply { id = 1 }
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
verify(mockCursor).markDeleted("User has been deleted for item id=1", PROFILE_DELETED)
|
verify(mockCursor).markDeleted("User has been deleted for item id=1", PROFILE_DELETED)
|
||||||
verify(mockCursor, times(0)).checkAndAddItem(any(), any(), anyOrNull())
|
verify(mockCursor, times(0)).checkAndAddItem(any(), any(), anyOrNull())
|
||||||
@@ -210,8 +210,9 @@ class WorkspaceItemProcessorTest {
|
|||||||
fun `When app has null intent then mark deleted`() {
|
fun `When app has null intent then mark deleted`() {
|
||||||
// Given
|
// Given
|
||||||
mockCursor.apply { whenever(parseIntent()).thenReturn(null) }
|
mockCursor.apply { whenever(parseIntent()).thenReturn(null) }
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
// Then
|
// Then
|
||||||
verify(mockCursor).markDeleted("Null intent from db for item id=1", MISSING_INFO)
|
verify(mockCursor).markDeleted("Null intent from db for item id=1", MISSING_INFO)
|
||||||
@@ -222,13 +223,13 @@ class WorkspaceItemProcessorTest {
|
|||||||
fun `When app has null target package then mark deleted`() {
|
fun `When app has null target package then mark deleted`() {
|
||||||
|
|
||||||
// Given
|
// Given
|
||||||
mockIntent.apply {
|
intent.apply {
|
||||||
whenever(component).thenReturn(null)
|
component = null
|
||||||
whenever(`package`).thenReturn(null)
|
`package` = null
|
||||||
}
|
}
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -241,11 +242,11 @@ class WorkspaceItemProcessorTest {
|
|||||||
|
|
||||||
// Given
|
// Given
|
||||||
componentName = ComponentName("", "")
|
componentName = ComponentName("", "")
|
||||||
whenever(mockIntent.component).thenReturn(componentName)
|
intent.component = componentName
|
||||||
whenever(mockCursor.parseIntent()).thenReturn(mockIntent)
|
intent.`package` = ""
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -256,10 +257,8 @@ class WorkspaceItemProcessorTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `When valid app then mark restored`() {
|
fun `When valid app then mark restored`() {
|
||||||
|
|
||||||
// Given
|
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -284,18 +283,18 @@ class WorkspaceItemProcessorTest {
|
|||||||
mockPmHelper =
|
mockPmHelper =
|
||||||
mock<PackageManagerHelper>().apply {
|
mock<PackageManagerHelper>().apply {
|
||||||
whenever(getAppLaunchIntent(componentName.packageName, userHandle))
|
whenever(getAppLaunchIntent(componentName.packageName, userHandle))
|
||||||
.thenReturn(mockIntent)
|
.thenReturn(intent)
|
||||||
}
|
}
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
assertWithMessage("item restoreFlag should be set to 0")
|
assertWithMessage("item restoreFlag should be set to 0")
|
||||||
.that(mockCursor.restoreFlag)
|
.that(mockCursor.restoreFlag)
|
||||||
.isEqualTo(0)
|
.isEqualTo(0)
|
||||||
verify(mockCursor.updater().put(Favorites.INTENT, mockIntent.toUri(0))).commit()
|
verify(mockCursor.updater().put(Favorites.INTENT, intent.toUri(0))).commit()
|
||||||
assertThat(iconRequestInfos).containsExactly(mockIconRequestInfo)
|
assertThat(iconRequestInfos).containsExactly(mockIconRequestInfo)
|
||||||
verify(mockCursor).checkAndAddItem(mockWorkspaceInfo, mockBgDataModel, null)
|
verify(mockCursor).checkAndAddItem(mockWorkspaceInfo, mockBgDataModel, null)
|
||||||
}
|
}
|
||||||
@@ -313,9 +312,9 @@ class WorkspaceItemProcessorTest {
|
|||||||
mock<PackageManagerHelper>().apply {
|
mock<PackageManagerHelper>().apply {
|
||||||
whenever(getAppLaunchIntent(componentName.packageName, userHandle)).thenReturn(null)
|
whenever(getAppLaunchIntent(componentName.packageName, userHandle)).thenReturn(null)
|
||||||
}
|
}
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -349,13 +348,13 @@ class WorkspaceItemProcessorTest {
|
|||||||
whenever(disabledReason).thenReturn(0)
|
whenever(disabledReason).thenReturn(0)
|
||||||
whenever(persons).thenReturn(EMPTY_PERSON_ARRAY)
|
whenever(persons).thenReturn(EMPTY_PERSON_ARRAY)
|
||||||
}
|
}
|
||||||
val shortcutKey = ShortcutKey.fromIntent(mockIntent, mockCursor.user)
|
val shortcutKey = ShortcutKey.fromIntent(intent, mockCursor.user)
|
||||||
keyToPinnedShortcutsMap[shortcutKey] = expectedShortcutInfo
|
keyToPinnedShortcutsMap[shortcutKey] = expectedShortcutInfo
|
||||||
iconRequestInfos = mutableListOf()
|
iconRequestInfos = mutableListOf()
|
||||||
itemProcessorUnderTest =
|
|
||||||
createWorkspaceItemProcessorUnderTest(allDeepShortcuts = allDeepShortcuts)
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest =
|
||||||
|
createWorkspaceItemProcessorUnderTest(allDeepShortcuts = allDeepShortcuts)
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -375,9 +374,9 @@ class WorkspaceItemProcessorTest {
|
|||||||
mockCursor.itemType = ITEM_TYPE_DEEP_SHORTCUT
|
mockCursor.itemType = ITEM_TYPE_DEEP_SHORTCUT
|
||||||
iconRequestInfos = mutableListOf()
|
iconRequestInfos = mutableListOf()
|
||||||
keyToPinnedShortcutsMap = hashMapOf()
|
keyToPinnedShortcutsMap = hashMapOf()
|
||||||
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
|
itemProcessorUnderTest = createWorkspaceItemProcessorUnderTest()
|
||||||
itemProcessorUnderTest.processItem()
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
@@ -393,6 +392,45 @@ class WorkspaceItemProcessorTest {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `When valid Pinned Deep Shortcut with null intent package then use targetPkg`() {
|
||||||
|
|
||||||
|
// Given
|
||||||
|
mockCursor.itemType = ITEM_TYPE_DEEP_SHORTCUT
|
||||||
|
val expectedShortcutInfo =
|
||||||
|
mock<ShortcutInfo>().apply {
|
||||||
|
whenever(id).thenReturn("")
|
||||||
|
whenever(`package`).thenReturn("")
|
||||||
|
whenever(activity).thenReturn(mock())
|
||||||
|
whenever(longLabel).thenReturn("")
|
||||||
|
whenever(isEnabled).thenReturn(true)
|
||||||
|
whenever(disabledMessage).thenReturn("")
|
||||||
|
whenever(disabledReason).thenReturn(0)
|
||||||
|
whenever(persons).thenReturn(EMPTY_PERSON_ARRAY)
|
||||||
|
}
|
||||||
|
iconRequestInfos = mutableListOf()
|
||||||
|
// Make sure shortcuts map has expected key from expected package
|
||||||
|
intent.`package` = componentName.packageName
|
||||||
|
val shortcutKey = ShortcutKey.fromIntent(intent, mockCursor.user)
|
||||||
|
keyToPinnedShortcutsMap[shortcutKey] = expectedShortcutInfo
|
||||||
|
// set intent package back to null to test scenario
|
||||||
|
intent.`package` = null
|
||||||
|
|
||||||
|
// When
|
||||||
|
itemProcessorUnderTest =
|
||||||
|
createWorkspaceItemProcessorUnderTest(allDeepShortcuts = allDeepShortcuts)
|
||||||
|
itemProcessorUnderTest.processItem()
|
||||||
|
|
||||||
|
// Then
|
||||||
|
assertWithMessage("item restoreFlag should be set to 0")
|
||||||
|
.that(mockCursor.restoreFlag)
|
||||||
|
.isEqualTo(0)
|
||||||
|
assertThat(iconRequestInfos).isEmpty()
|
||||||
|
assertThat(allDeepShortcuts).containsExactly(expectedShortcutInfo)
|
||||||
|
verify(mockCursor).markRestored()
|
||||||
|
verify(mockCursor).checkAndAddItem(any(), any(), anyOrNull())
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `When processing Folder then create FolderInfo and mark restored`() {
|
fun `When processing Folder then create FolderInfo and mark restored`() {
|
||||||
val actualFolderInfo = FolderInfo()
|
val actualFolderInfo = FolderInfo()
|
||||||
|
|||||||
Reference in new issue
Block a user