2017-01-20 08:15:28 -08:00
|
|
|
package com.android.launcher3.util;
|
|
|
|
|
|
|
|
|
|
import android.os.UserHandle;
|
|
|
|
|
import android.service.notification.StatusBarNotification;
|
|
|
|
|
|
2019-08-16 13:28:24 -07:00
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
|
|
2020-04-06 15:11:17 -07:00
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
2017-01-20 08:15:28 -08:00
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
|
|
/** Creates a hash key based on package name and user. */
|
|
|
|
|
public class PackageUserKey {
|
|
|
|
|
|
2017-03-20 17:12:24 -07:00
|
|
|
public String mPackageName;
|
|
|
|
|
public UserHandle mUser;
|
2017-01-20 08:15:28 -08:00
|
|
|
private int mHashCode;
|
|
|
|
|
|
2019-08-16 13:28:24 -07:00
|
|
|
@Nullable
|
2017-01-20 08:15:28 -08:00
|
|
|
public static PackageUserKey fromItemInfo(ItemInfo info) {
|
2019-08-16 13:28:24 -07:00
|
|
|
if (info.getTargetComponent() == null) return null;
|
2017-01-20 08:15:28 -08:00
|
|
|
return new PackageUserKey(info.getTargetComponent().getPackageName(), info.user);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PackageUserKey fromNotification(StatusBarNotification notification) {
|
|
|
|
|
return new PackageUserKey(notification.getPackageName(), notification.getUser());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PackageUserKey(String packageName, UserHandle user) {
|
|
|
|
|
update(packageName, user);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-16 21:38:28 -07:00
|
|
|
public void update(String packageName, UserHandle user) {
|
2017-01-20 08:15:28 -08:00
|
|
|
mPackageName = packageName;
|
|
|
|
|
mUser = user;
|
|
|
|
|
mHashCode = Arrays.hashCode(new Object[] {packageName, user});
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 13:58:33 -08:00
|
|
|
/**
|
|
|
|
|
* This should only be called to avoid new object creations in a loop.
|
|
|
|
|
* @return Whether this PackageUserKey was successfully updated - it shouldn't be used if not.
|
|
|
|
|
*/
|
|
|
|
|
public boolean updateFromItemInfo(ItemInfo info) {
|
2019-08-16 13:28:24 -07:00
|
|
|
if (info.getTargetComponent() == null) return false;
|
2019-07-26 12:28:38 -07:00
|
|
|
if (ShortcutUtil.supportsShortcuts(info)) {
|
2017-02-02 13:58:33 -08:00
|
|
|
update(info.getTargetComponent().getPackageName(), info.user);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
2017-01-20 08:15:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int hashCode() {
|
|
|
|
|
return mHashCode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean equals(Object obj) {
|
|
|
|
|
if (!(obj instanceof PackageUserKey)) return false;
|
|
|
|
|
PackageUserKey otherKey = (PackageUserKey) obj;
|
|
|
|
|
return mPackageName.equals(otherKey.mPackageName) && mUser.equals(otherKey.mUser);
|
|
|
|
|
}
|
|
|
|
|
}
|