add null check when accessing target component from iteminfo

Bug: 139540363
Change-Id: I25d0100077de67b085c27b5ef91e22c6ac1ad959
This commit is contained in:
Pinyao Ting
2019-08-16 13:28:24 -07:00
parent b00a1e2a0a
commit 2f9019e56c
4 changed files with 13 additions and 2 deletions
+3
View File
@@ -22,6 +22,8 @@ import android.content.Intent;
import android.os.Process;
import android.os.UserHandle;
import androidx.annotation.Nullable;
import com.android.launcher3.util.ContentWriter;
/**
@@ -134,6 +136,7 @@ public class ItemInfo {
return null;
}
@Nullable
public ComponentName getTargetComponent() {
Intent intent = getIntent();
if (intent != null) {
@@ -135,6 +135,7 @@ public abstract class SystemShortcut<T extends BaseDraggingActivity>
@Override
public View.OnClickListener getOnClickListener(final Launcher launcher,
final ItemInfo itemInfo) {
if (itemInfo.getTargetComponent() == null) return null;
final List<WidgetItem> widgets =
launcher.getPopupDataProvider().getWidgetsForPackageUser(new PackageUserKey(
itemInfo.getTargetComponent().getPackageName(), itemInfo.user));
@@ -3,8 +3,9 @@ package com.android.launcher3.util;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import androidx.annotation.Nullable;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.shortcuts.DeepShortcutManager;
import java.util.Arrays;
@@ -15,7 +16,9 @@ public class PackageUserKey {
public UserHandle mUser;
private int mHashCode;
@Nullable
public static PackageUserKey fromItemInfo(ItemInfo info) {
if (info.getTargetComponent() == null) return null;
return new PackageUserKey(info.getTargetComponent().getPackageName(), info.user);
}
@@ -38,6 +41,7 @@ public class PackageUserKey {
* @return Whether this PackageUserKey was successfully updated - it shouldn't be used if not.
*/
public boolean updateFromItemInfo(ItemInfo info) {
if (info.getTargetComponent() == null) return false;
if (ShortcutUtil.supportsShortcuts(info)) {
update(info.getTargetComponent().getPackageName(), info.user);
return true;
@@ -27,6 +27,8 @@ import android.os.Bundle;
import android.os.UserHandle;
import android.util.Log;
import androidx.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -70,8 +72,9 @@ public class DeepShortcutManager {
* Gets all the manifest and dynamic shortcuts associated with the given package and user,
* to be displayed in the shortcuts container on long press.
*/
public QueryResult queryForShortcutsContainer(ComponentName activity,
public QueryResult queryForShortcutsContainer(@Nullable ComponentName activity,
UserHandle user) {
if (activity == null) return QueryResult.FAILURE;
return query(ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_DYNAMIC,
activity.getPackageName(), activity, null, user);
}