1 package com.android.launcher3.util; 2 3 import android.os.UserHandle; 4 import android.service.notification.StatusBarNotification; 5 6 import com.android.launcher3.ItemInfo; 7 import com.android.launcher3.shortcuts.DeepShortcutManager; 8 9 import java.util.Arrays; 10 11 /** Creates a hash key based on package name and user. */ 12 public class PackageUserKey { 13 14 public String mPackageName; 15 public UserHandle mUser; 16 private int mHashCode; 17 18 public static PackageUserKey fromItemInfo(ItemInfo info) { 19 return new PackageUserKey(info.getTargetComponent().getPackageName(), info.user); 20 } 21 22 public static PackageUserKey fromNotification(StatusBarNotification notification) { 23 return new PackageUserKey(notification.getPackageName(), notification.getUser()); 24 } 25 26 public PackageUserKey(String packageName, UserHandle user) { 27 update(packageName, user); 28 } 29 30 private void update(String packageName, UserHandle user) { 31 mPackageName = packageName; 32 mUser = user; 33 mHashCode = Arrays.hashCode(new Object[] {packageName, user}); 34 } 35 36 /** 37 * This should only be called to avoid new object creations in a loop. 38 * @return Whether this PackageUserKey was successfully updated - it shouldn't be used if not. 39 */ 40 public boolean updateFromItemInfo(ItemInfo info) { 41 if (DeepShortcutManager.supportsShortcuts(info)) { 42 update(info.getTargetComponent().getPackageName(), info.user); 43 return true; 44 } 45 return false; 46 } 47 48 @Override 49 public int hashCode() { 50 return mHashCode; 51 } 52 53 @Override 54 public boolean equals(Object obj) { 55 if (!(obj instanceof PackageUserKey)) return false; 56 PackageUserKey otherKey = (PackageUserKey) obj; 57 return mPackageName.equals(otherKey.mPackageName) && mUser.equals(otherKey.mUser); 58 } 59 } 60