646e4486be
This could help us determine whether our data model or UI is wrong if dots aren't appearing. Bug: 152435463 Change-Id: I46065b130b6b1cbb3b2d1db471654b3959332ff5
71 lines
2.1 KiB
Java
71 lines
2.1 KiB
Java
package com.android.launcher3.util;
|
|
|
|
import android.os.UserHandle;
|
|
import android.service.notification.StatusBarNotification;
|
|
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
|
|
import com.android.launcher3.model.data.ItemInfo;
|
|
|
|
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);
|
|
}
|
|
|
|
public 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);
|
|
}
|
|
|
|
@NonNull
|
|
@Override
|
|
public String toString() {
|
|
return mPackageName + "#" + mUser;
|
|
}
|
|
}
|