mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 03:08:19 +00:00
Bug: 139540363 Change-Id: I25d0100077de67b085c27b5ef91e22c6ac1ad959 Merged-In: I25d0100077de67b085c27b5ef91e22c6ac1ad959
65 lines
2.0 KiB
Java
65 lines
2.0 KiB
Java
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;
|
|
|
|
/** Creates a hash key based on package name and user. */
|
|
public class PackageUserKey {
|
|
|
|
public String mPackageName;
|
|
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);
|
|
}
|
|
|
|
public static PackageUserKey fromNotification(StatusBarNotification notification) {
|
|
return new PackageUserKey(notification.getPackageName(), notification.getUser());
|
|
}
|
|
|
|
public PackageUserKey(String packageName, UserHandle user) {
|
|
update(packageName, user);
|
|
}
|
|
|
|
private void update(String packageName, UserHandle user) {
|
|
mPackageName = packageName;
|
|
mUser = user;
|
|
mHashCode = Arrays.hashCode(new Object[] {packageName, user});
|
|
}
|
|
|
|
/**
|
|
* 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) {
|
|
if (info.getTargetComponent() == null) return false;
|
|
if (ShortcutUtil.supportsShortcuts(info)) {
|
|
update(info.getTargetComponent().getPackageName(), info.user);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@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);
|
|
}
|
|
}
|