2021-06-27 20:44:35 +00:00
|
|
|
package androidx.core.content.pm;
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
import android.annotation.SuppressLint;
|
2021-06-27 20:44:35 +00:00
|
|
|
import android.content.ComponentName;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.Intent;
|
|
|
|
import android.content.pm.PackageManager;
|
|
|
|
import android.content.pm.ShortcutInfo;
|
|
|
|
import android.graphics.drawable.Drawable;
|
2021-09-29 00:45:08 +00:00
|
|
|
import android.net.Uri;
|
2021-06-27 20:44:35 +00:00
|
|
|
import android.os.Build;
|
|
|
|
import android.os.PersistableBundle;
|
2021-09-29 00:45:08 +00:00
|
|
|
import android.os.UserHandle;
|
2021-06-27 20:44:35 +00:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
|
import androidx.annotation.Nullable;
|
|
|
|
import androidx.annotation.RequiresApi;
|
|
|
|
import androidx.annotation.RestrictTo;
|
|
|
|
import androidx.annotation.VisibleForTesting;
|
|
|
|
import androidx.core.app.Person;
|
2021-09-29 00:45:08 +00:00
|
|
|
import androidx.core.content.LocusIdCompat;
|
2021-06-27 20:44:35 +00:00
|
|
|
import androidx.core.graphics.drawable.IconCompat;
|
2021-09-29 00:45:08 +00:00
|
|
|
import androidx.core.net.UriCompat;
|
2021-12-21 23:37:30 +00:00
|
|
|
import b.d.b.a.a;
|
2021-09-29 00:45:08 +00:00
|
|
|
import com.discord.widgets.chat.input.autocomplete.AutocompleteViewModel;
|
|
|
|
import java.util.ArrayList;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.Arrays;
|
2021-09-29 00:45:08 +00:00
|
|
|
import java.util.HashMap;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.HashSet;
|
2021-09-29 00:45:08 +00:00
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
2021-06-27 20:44:35 +00:00
|
|
|
import java.util.Set;
|
|
|
|
public class ShortcutInfoCompat {
|
2021-09-29 00:45:08 +00:00
|
|
|
private static final String EXTRA_LOCUS_ID = "extraLocusId";
|
2021-06-27 20:44:35 +00:00
|
|
|
private static final String EXTRA_LONG_LIVED = "extraLongLived";
|
|
|
|
private static final String EXTRA_PERSON_ = "extraPerson_";
|
|
|
|
private static final String EXTRA_PERSON_COUNT = "extraPersonCount";
|
2021-09-29 00:45:08 +00:00
|
|
|
private static final String EXTRA_SLICE_URI = "extraSliceUri";
|
2021-06-27 20:44:35 +00:00
|
|
|
public ComponentName mActivity;
|
|
|
|
public Set<String> mCategories;
|
|
|
|
public Context mContext;
|
|
|
|
public CharSequence mDisabledMessage;
|
2021-09-29 00:45:08 +00:00
|
|
|
public int mDisabledReason;
|
|
|
|
public PersistableBundle mExtras;
|
|
|
|
public boolean mHasKeyFieldsOnly;
|
2021-06-27 20:44:35 +00:00
|
|
|
public IconCompat mIcon;
|
|
|
|
public String mId;
|
|
|
|
public Intent[] mIntents;
|
|
|
|
public boolean mIsAlwaysBadged;
|
2021-09-29 00:45:08 +00:00
|
|
|
public boolean mIsCached;
|
|
|
|
public boolean mIsDeclaredInManifest;
|
|
|
|
public boolean mIsDynamic;
|
|
|
|
public boolean mIsEnabled = true;
|
|
|
|
public boolean mIsImmutable;
|
2021-06-27 20:44:35 +00:00
|
|
|
public boolean mIsLongLived;
|
2021-09-29 00:45:08 +00:00
|
|
|
public boolean mIsPinned;
|
2021-06-27 20:44:35 +00:00
|
|
|
public CharSequence mLabel;
|
2021-09-29 00:45:08 +00:00
|
|
|
public long mLastChangedTimestamp;
|
|
|
|
@Nullable
|
|
|
|
public LocusIdCompat mLocusId;
|
2021-06-27 20:44:35 +00:00
|
|
|
public CharSequence mLongLabel;
|
2021-09-29 00:45:08 +00:00
|
|
|
public String mPackageName;
|
2021-06-27 20:44:35 +00:00
|
|
|
public Person[] mPersons;
|
|
|
|
public int mRank;
|
2021-09-29 00:45:08 +00:00
|
|
|
public UserHandle mUser;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
public static class Builder {
|
2021-09-29 00:45:08 +00:00
|
|
|
private Map<String, Map<String, List<String>>> mCapabilityBindingParams;
|
|
|
|
private Set<String> mCapabilityBindings;
|
2021-06-27 20:44:35 +00:00
|
|
|
private final ShortcutInfoCompat mInfo;
|
2021-09-29 00:45:08 +00:00
|
|
|
private boolean mIsConversation;
|
|
|
|
private Uri mSliceUri;
|
2021-06-27 20:44:35 +00:00
|
|
|
|
|
|
|
@RequiresApi(25)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
public Builder(@NonNull Context context, @NonNull ShortcutInfo shortcutInfo) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat();
|
|
|
|
this.mInfo = shortcutInfoCompat;
|
|
|
|
shortcutInfoCompat.mContext = context;
|
|
|
|
shortcutInfoCompat.mId = shortcutInfo.getId();
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat.mPackageName = shortcutInfo.getPackage();
|
2021-06-27 20:44:35 +00:00
|
|
|
Intent[] intents = shortcutInfo.getIntents();
|
|
|
|
shortcutInfoCompat.mIntents = (Intent[]) Arrays.copyOf(intents, intents.length);
|
|
|
|
shortcutInfoCompat.mActivity = shortcutInfo.getActivity();
|
|
|
|
shortcutInfoCompat.mLabel = shortcutInfo.getShortLabel();
|
|
|
|
shortcutInfoCompat.mLongLabel = shortcutInfo.getLongLabel();
|
|
|
|
shortcutInfoCompat.mDisabledMessage = shortcutInfo.getDisabledMessage();
|
2021-09-29 00:45:08 +00:00
|
|
|
int i = Build.VERSION.SDK_INT;
|
|
|
|
if (i >= 28) {
|
|
|
|
shortcutInfoCompat.mDisabledReason = shortcutInfo.getDisabledReason();
|
|
|
|
} else {
|
|
|
|
shortcutInfoCompat.mDisabledReason = shortcutInfo.isEnabled() ? 0 : 3;
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
shortcutInfoCompat.mCategories = shortcutInfo.getCategories();
|
|
|
|
shortcutInfoCompat.mPersons = ShortcutInfoCompat.getPersonsFromExtra(shortcutInfo.getExtras());
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat.mUser = shortcutInfo.getUserHandle();
|
|
|
|
shortcutInfoCompat.mLastChangedTimestamp = shortcutInfo.getLastChangedTimestamp();
|
|
|
|
if (i >= 30) {
|
|
|
|
shortcutInfoCompat.mIsCached = shortcutInfo.isCached();
|
|
|
|
}
|
|
|
|
shortcutInfoCompat.mIsDynamic = shortcutInfo.isDynamic();
|
|
|
|
shortcutInfoCompat.mIsPinned = shortcutInfo.isPinned();
|
|
|
|
shortcutInfoCompat.mIsDeclaredInManifest = shortcutInfo.isDeclaredInManifest();
|
|
|
|
shortcutInfoCompat.mIsImmutable = shortcutInfo.isImmutable();
|
|
|
|
shortcutInfoCompat.mIsEnabled = shortcutInfo.isEnabled();
|
|
|
|
shortcutInfoCompat.mHasKeyFieldsOnly = shortcutInfo.hasKeyFieldsOnly();
|
|
|
|
shortcutInfoCompat.mLocusId = ShortcutInfoCompat.getLocusId(shortcutInfo);
|
2021-06-27 20:44:35 +00:00
|
|
|
shortcutInfoCompat.mRank = shortcutInfo.getRank();
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat.mExtras = shortcutInfo.getExtras();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public Builder(@NonNull Context context, @NonNull String str) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat();
|
|
|
|
this.mInfo = shortcutInfoCompat;
|
|
|
|
shortcutInfoCompat.mContext = context;
|
|
|
|
shortcutInfoCompat.mId = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
public Builder(@NonNull ShortcutInfoCompat shortcutInfoCompat) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat2 = new ShortcutInfoCompat();
|
|
|
|
this.mInfo = shortcutInfoCompat2;
|
|
|
|
shortcutInfoCompat2.mContext = shortcutInfoCompat.mContext;
|
|
|
|
shortcutInfoCompat2.mId = shortcutInfoCompat.mId;
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat2.mPackageName = shortcutInfoCompat.mPackageName;
|
2021-06-27 20:44:35 +00:00
|
|
|
Intent[] intentArr = shortcutInfoCompat.mIntents;
|
|
|
|
shortcutInfoCompat2.mIntents = (Intent[]) Arrays.copyOf(intentArr, intentArr.length);
|
|
|
|
shortcutInfoCompat2.mActivity = shortcutInfoCompat.mActivity;
|
|
|
|
shortcutInfoCompat2.mLabel = shortcutInfoCompat.mLabel;
|
|
|
|
shortcutInfoCompat2.mLongLabel = shortcutInfoCompat.mLongLabel;
|
|
|
|
shortcutInfoCompat2.mDisabledMessage = shortcutInfoCompat.mDisabledMessage;
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat2.mDisabledReason = shortcutInfoCompat.mDisabledReason;
|
2021-06-27 20:44:35 +00:00
|
|
|
shortcutInfoCompat2.mIcon = shortcutInfoCompat.mIcon;
|
|
|
|
shortcutInfoCompat2.mIsAlwaysBadged = shortcutInfoCompat.mIsAlwaysBadged;
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat2.mUser = shortcutInfoCompat.mUser;
|
|
|
|
shortcutInfoCompat2.mLastChangedTimestamp = shortcutInfoCompat.mLastChangedTimestamp;
|
|
|
|
shortcutInfoCompat2.mIsCached = shortcutInfoCompat.mIsCached;
|
|
|
|
shortcutInfoCompat2.mIsDynamic = shortcutInfoCompat.mIsDynamic;
|
|
|
|
shortcutInfoCompat2.mIsPinned = shortcutInfoCompat.mIsPinned;
|
|
|
|
shortcutInfoCompat2.mIsDeclaredInManifest = shortcutInfoCompat.mIsDeclaredInManifest;
|
|
|
|
shortcutInfoCompat2.mIsImmutable = shortcutInfoCompat.mIsImmutable;
|
|
|
|
shortcutInfoCompat2.mIsEnabled = shortcutInfoCompat.mIsEnabled;
|
|
|
|
shortcutInfoCompat2.mLocusId = shortcutInfoCompat.mLocusId;
|
2021-06-27 20:44:35 +00:00
|
|
|
shortcutInfoCompat2.mIsLongLived = shortcutInfoCompat.mIsLongLived;
|
2021-09-29 00:45:08 +00:00
|
|
|
shortcutInfoCompat2.mHasKeyFieldsOnly = shortcutInfoCompat.mHasKeyFieldsOnly;
|
2021-06-27 20:44:35 +00:00
|
|
|
shortcutInfoCompat2.mRank = shortcutInfoCompat.mRank;
|
|
|
|
Person[] personArr = shortcutInfoCompat.mPersons;
|
|
|
|
if (personArr != null) {
|
|
|
|
shortcutInfoCompat2.mPersons = (Person[]) Arrays.copyOf(personArr, personArr.length);
|
|
|
|
}
|
|
|
|
if (shortcutInfoCompat.mCategories != null) {
|
|
|
|
shortcutInfoCompat2.mCategories = new HashSet(shortcutInfoCompat.mCategories);
|
|
|
|
}
|
2021-09-29 00:45:08 +00:00
|
|
|
PersistableBundle persistableBundle = shortcutInfoCompat.mExtras;
|
|
|
|
if (persistableBundle != null) {
|
|
|
|
shortcutInfoCompat2.mExtras = persistableBundle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@SuppressLint({"MissingGetterMatchingBuilder"})
|
|
|
|
public Builder addCapabilityBinding(@NonNull String str) {
|
|
|
|
if (this.mCapabilityBindings == null) {
|
|
|
|
this.mCapabilityBindings = new HashSet();
|
|
|
|
}
|
|
|
|
this.mCapabilityBindings.add(str);
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@SuppressLint({"MissingGetterMatchingBuilder"})
|
|
|
|
public Builder addCapabilityBinding(@NonNull String str, @NonNull String str2, @NonNull List<String> list) {
|
|
|
|
addCapabilityBinding(str);
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
if (this.mCapabilityBindingParams == null) {
|
|
|
|
this.mCapabilityBindingParams = new HashMap();
|
|
|
|
}
|
|
|
|
if (this.mCapabilityBindingParams.get(str) == null) {
|
|
|
|
this.mCapabilityBindingParams.put(str, new HashMap());
|
|
|
|
}
|
|
|
|
this.mCapabilityBindingParams.get(str).put(str2, list);
|
|
|
|
}
|
|
|
|
return this;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
2021-09-29 00:45:08 +00:00
|
|
|
@SuppressLint({"UnsafeNewApiCall"})
|
2021-06-27 20:44:35 +00:00
|
|
|
public ShortcutInfoCompat build() {
|
|
|
|
if (!TextUtils.isEmpty(this.mInfo.mLabel)) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat = this.mInfo;
|
|
|
|
Intent[] intentArr = shortcutInfoCompat.mIntents;
|
2021-09-29 00:45:08 +00:00
|
|
|
if (intentArr == null || intentArr.length == 0) {
|
|
|
|
throw new IllegalArgumentException("Shortcut must have an intent");
|
|
|
|
}
|
|
|
|
if (this.mIsConversation) {
|
|
|
|
if (shortcutInfoCompat.mLocusId == null) {
|
|
|
|
shortcutInfoCompat.mLocusId = new LocusIdCompat(shortcutInfoCompat.mId);
|
|
|
|
}
|
|
|
|
this.mInfo.mIsLongLived = true;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-09-29 00:45:08 +00:00
|
|
|
if (this.mCapabilityBindings != null) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat2 = this.mInfo;
|
|
|
|
if (shortcutInfoCompat2.mCategories == null) {
|
|
|
|
shortcutInfoCompat2.mCategories = new HashSet();
|
|
|
|
}
|
|
|
|
this.mInfo.mCategories.addAll(this.mCapabilityBindings);
|
|
|
|
}
|
|
|
|
if (this.mCapabilityBindingParams != null) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat3 = this.mInfo;
|
|
|
|
if (shortcutInfoCompat3.mExtras == null) {
|
|
|
|
shortcutInfoCompat3.mExtras = new PersistableBundle();
|
|
|
|
}
|
|
|
|
for (String str : this.mCapabilityBindingParams.keySet()) {
|
|
|
|
Map<String, List<String>> map = this.mCapabilityBindingParams.get(str);
|
|
|
|
this.mInfo.mExtras.putStringArray(str, (String[]) map.keySet().toArray(new String[0]));
|
|
|
|
for (String str2 : map.keySet()) {
|
|
|
|
List<String> list = map.get(str2);
|
2021-11-08 18:25:28 +00:00
|
|
|
this.mInfo.mExtras.putStringArray(a.w(str, AutocompleteViewModel.COMMAND_DISCOVER_TOKEN, str2), list == null ? new String[0] : (String[]) list.toArray(new String[0]));
|
2021-09-29 00:45:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.mSliceUri != null) {
|
|
|
|
ShortcutInfoCompat shortcutInfoCompat4 = this.mInfo;
|
|
|
|
if (shortcutInfoCompat4.mExtras == null) {
|
|
|
|
shortcutInfoCompat4.mExtras = new PersistableBundle();
|
|
|
|
}
|
|
|
|
this.mInfo.mExtras.putString(ShortcutInfoCompat.EXTRA_SLICE_URI, UriCompat.toSafeString(this.mSliceUri));
|
|
|
|
}
|
|
|
|
return this.mInfo;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
throw new IllegalArgumentException("Shortcut must have a non-empty label");
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setActivity(@NonNull ComponentName componentName) {
|
|
|
|
this.mInfo.mActivity = componentName;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setAlwaysBadged() {
|
|
|
|
this.mInfo.mIsAlwaysBadged = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setCategories(@NonNull Set<String> set) {
|
|
|
|
this.mInfo.mCategories = set;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setDisabledMessage(@NonNull CharSequence charSequence) {
|
|
|
|
this.mInfo.mDisabledMessage = charSequence;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
@NonNull
|
|
|
|
public Builder setExtras(@NonNull PersistableBundle persistableBundle) {
|
|
|
|
this.mInfo.mExtras = persistableBundle;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@NonNull
|
|
|
|
public Builder setIcon(IconCompat iconCompat) {
|
|
|
|
this.mInfo.mIcon = iconCompat;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setIntent(@NonNull Intent intent) {
|
|
|
|
return setIntents(new Intent[]{intent});
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setIntents(@NonNull Intent[] intentArr) {
|
|
|
|
this.mInfo.mIntents = intentArr;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
@NonNull
|
|
|
|
public Builder setIsConversation() {
|
|
|
|
this.mIsConversation = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setLocusId(@Nullable LocusIdCompat locusIdCompat) {
|
|
|
|
this.mInfo.mLocusId = locusIdCompat;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@NonNull
|
|
|
|
public Builder setLongLabel(@NonNull CharSequence charSequence) {
|
|
|
|
this.mInfo.mLongLabel = charSequence;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@Deprecated
|
|
|
|
public Builder setLongLived() {
|
|
|
|
this.mInfo.mIsLongLived = true;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setLongLived(boolean z2) {
|
|
|
|
this.mInfo.mIsLongLived = z2;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setPerson(@NonNull Person person) {
|
|
|
|
return setPersons(new Person[]{person});
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setPersons(@NonNull Person[] personArr) {
|
|
|
|
this.mInfo.mPersons = personArr;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setRank(int i) {
|
|
|
|
this.mInfo.mRank = i;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Builder setShortLabel(@NonNull CharSequence charSequence) {
|
|
|
|
this.mInfo.mLabel = charSequence;
|
|
|
|
return this;
|
|
|
|
}
|
2021-09-29 00:45:08 +00:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
@SuppressLint({"MissingGetterMatchingBuilder"})
|
|
|
|
public Builder setSliceUri(@NonNull Uri uri) {
|
|
|
|
this.mSliceUri = uri;
|
|
|
|
return this;
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequiresApi(22)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
private PersistableBundle buildLegacyExtrasBundle() {
|
2021-09-29 00:45:08 +00:00
|
|
|
if (this.mExtras == null) {
|
|
|
|
this.mExtras = new PersistableBundle();
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
Person[] personArr = this.mPersons;
|
|
|
|
if (personArr != null && personArr.length > 0) {
|
2021-09-29 00:45:08 +00:00
|
|
|
this.mExtras.putInt(EXTRA_PERSON_COUNT, personArr.length);
|
2021-06-27 20:44:35 +00:00
|
|
|
int i = 0;
|
|
|
|
while (i < this.mPersons.length) {
|
2021-09-29 00:45:08 +00:00
|
|
|
PersistableBundle persistableBundle = this.mExtras;
|
2021-11-08 18:25:28 +00:00
|
|
|
StringBuilder R = a.R(EXTRA_PERSON_);
|
2021-06-27 20:44:35 +00:00
|
|
|
int i2 = i + 1;
|
2021-11-08 18:25:28 +00:00
|
|
|
R.append(i2);
|
|
|
|
persistableBundle.putPersistableBundle(R.toString(), this.mPersons[i].toPersistableBundle());
|
2021-06-27 20:44:35 +00:00
|
|
|
i = i2;
|
|
|
|
}
|
|
|
|
}
|
2021-09-29 00:45:08 +00:00
|
|
|
LocusIdCompat locusIdCompat = this.mLocusId;
|
|
|
|
if (locusIdCompat != null) {
|
|
|
|
this.mExtras.putString(EXTRA_LOCUS_ID, locusIdCompat.getId());
|
|
|
|
}
|
|
|
|
this.mExtras.putBoolean(EXTRA_LONG_LIVED, this.mIsLongLived);
|
|
|
|
return this.mExtras;
|
|
|
|
}
|
|
|
|
|
|
|
|
@RequiresApi(25)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
public static List<ShortcutInfoCompat> fromShortcuts(@NonNull Context context, @NonNull List<ShortcutInfo> list) {
|
|
|
|
ArrayList arrayList = new ArrayList(list.size());
|
|
|
|
for (ShortcutInfo shortcutInfo : list) {
|
|
|
|
arrayList.add(new Builder(context, shortcutInfo).build());
|
|
|
|
}
|
|
|
|
return arrayList;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@RequiresApi(25)
|
|
|
|
public static LocusIdCompat getLocusId(@NonNull ShortcutInfo shortcutInfo) {
|
|
|
|
if (Build.VERSION.SDK_INT < 29) {
|
|
|
|
return getLocusIdFromExtra(shortcutInfo.getExtras());
|
|
|
|
}
|
|
|
|
if (shortcutInfo.getLocusId() == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return LocusIdCompat.toLocusIdCompat(shortcutInfo.getLocusId());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@RequiresApi(25)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
private static LocusIdCompat getLocusIdFromExtra(@Nullable PersistableBundle persistableBundle) {
|
|
|
|
String string;
|
|
|
|
if (persistableBundle == null || (string = persistableBundle.getString(EXTRA_LOCUS_ID)) == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return new LocusIdCompat(string);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@RequiresApi(25)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
@VisibleForTesting
|
2021-09-29 00:45:08 +00:00
|
|
|
public static boolean getLongLivedFromExtra(@Nullable PersistableBundle persistableBundle) {
|
2021-08-09 22:50:01 +00:00
|
|
|
if (persistableBundle == null || !persistableBundle.containsKey(EXTRA_LONG_LIVED)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-08-09 22:50:01 +00:00
|
|
|
return persistableBundle.getBoolean(EXTRA_LONG_LIVED);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@VisibleForTesting
|
|
|
|
@Nullable
|
|
|
|
@RequiresApi(25)
|
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
public static Person[] getPersonsFromExtra(@NonNull PersistableBundle persistableBundle) {
|
2021-08-09 22:50:01 +00:00
|
|
|
if (persistableBundle == null || !persistableBundle.containsKey(EXTRA_PERSON_COUNT)) {
|
2021-06-27 20:44:35 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-08-09 22:50:01 +00:00
|
|
|
int i = persistableBundle.getInt(EXTRA_PERSON_COUNT);
|
2021-06-27 20:44:35 +00:00
|
|
|
Person[] personArr = new Person[i];
|
|
|
|
int i2 = 0;
|
|
|
|
while (i2 < i) {
|
2021-11-08 18:25:28 +00:00
|
|
|
StringBuilder R = a.R(EXTRA_PERSON_);
|
2021-06-27 20:44:35 +00:00
|
|
|
int i3 = i2 + 1;
|
2021-11-08 18:25:28 +00:00
|
|
|
R.append(i3);
|
|
|
|
personArr[i2] = Person.fromPersistableBundle(persistableBundle.getPersistableBundle(R.toString()));
|
2021-06-27 20:44:35 +00:00
|
|
|
i2 = i3;
|
|
|
|
}
|
|
|
|
return personArr;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Intent addToIntent(Intent intent) {
|
|
|
|
Intent[] intentArr = this.mIntents;
|
|
|
|
intent.putExtra("android.intent.extra.shortcut.INTENT", intentArr[intentArr.length - 1]).putExtra("android.intent.extra.shortcut.NAME", this.mLabel.toString());
|
|
|
|
if (this.mIcon != null) {
|
|
|
|
Drawable drawable = null;
|
|
|
|
if (this.mIsAlwaysBadged) {
|
|
|
|
PackageManager packageManager = this.mContext.getPackageManager();
|
|
|
|
ComponentName componentName = this.mActivity;
|
|
|
|
if (componentName != null) {
|
|
|
|
try {
|
|
|
|
drawable = packageManager.getActivityIcon(componentName);
|
|
|
|
} catch (PackageManager.NameNotFoundException unused) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drawable == null) {
|
|
|
|
drawable = this.mContext.getApplicationInfo().loadIcon(packageManager);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.mIcon.addToShortcutIntent(intent, drawable, this.mContext);
|
|
|
|
}
|
|
|
|
return intent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public ComponentName getActivity() {
|
|
|
|
return this.mActivity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public Set<String> getCategories() {
|
|
|
|
return this.mCategories;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public CharSequence getDisabledMessage() {
|
|
|
|
return this.mDisabledMessage;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
public int getDisabledReason() {
|
|
|
|
return this.mDisabledReason;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public PersistableBundle getExtras() {
|
|
|
|
return this.mExtras;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
|
|
|
public IconCompat getIcon() {
|
|
|
|
return this.mIcon;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public String getId() {
|
|
|
|
return this.mId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Intent getIntent() {
|
|
|
|
Intent[] intentArr = this.mIntents;
|
|
|
|
return intentArr[intentArr.length - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Intent[] getIntents() {
|
|
|
|
Intent[] intentArr = this.mIntents;
|
|
|
|
return (Intent[]) Arrays.copyOf(intentArr, intentArr.length);
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
public long getLastChangedTimestamp() {
|
|
|
|
return this.mLastChangedTimestamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
public LocusIdCompat getLocusId() {
|
|
|
|
return this.mLocusId;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@Nullable
|
|
|
|
public CharSequence getLongLabel() {
|
|
|
|
return this.mLongLabel;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
@NonNull
|
|
|
|
public String getPackage() {
|
|
|
|
return this.mPackageName;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
public int getRank() {
|
|
|
|
return this.mRank;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public CharSequence getShortLabel() {
|
|
|
|
return this.mLabel;
|
|
|
|
}
|
|
|
|
|
2021-09-29 00:45:08 +00:00
|
|
|
@Nullable
|
|
|
|
public UserHandle getUserHandle() {
|
|
|
|
return this.mUser;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasKeyFieldsOnly() {
|
|
|
|
return this.mHasKeyFieldsOnly;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCached() {
|
|
|
|
return this.mIsCached;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDeclaredInManifest() {
|
|
|
|
return this.mIsDeclaredInManifest;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isDynamic() {
|
|
|
|
return this.mIsDynamic;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isEnabled() {
|
|
|
|
return this.mIsEnabled;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isImmutable() {
|
|
|
|
return this.mIsImmutable;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isPinned() {
|
|
|
|
return this.mIsPinned;
|
|
|
|
}
|
|
|
|
|
2021-06-27 20:44:35 +00:00
|
|
|
@RequiresApi(25)
|
|
|
|
public ShortcutInfo toShortcutInfo() {
|
|
|
|
ShortcutInfo.Builder intents = new ShortcutInfo.Builder(this.mContext, this.mId).setShortLabel(this.mLabel).setIntents(this.mIntents);
|
|
|
|
IconCompat iconCompat = this.mIcon;
|
|
|
|
if (iconCompat != null) {
|
|
|
|
intents.setIcon(iconCompat.toIcon(this.mContext));
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(this.mLongLabel)) {
|
|
|
|
intents.setLongLabel(this.mLongLabel);
|
|
|
|
}
|
|
|
|
if (!TextUtils.isEmpty(this.mDisabledMessage)) {
|
|
|
|
intents.setDisabledMessage(this.mDisabledMessage);
|
|
|
|
}
|
|
|
|
ComponentName componentName = this.mActivity;
|
|
|
|
if (componentName != null) {
|
|
|
|
intents.setActivity(componentName);
|
|
|
|
}
|
|
|
|
Set<String> set = this.mCategories;
|
|
|
|
if (set != null) {
|
|
|
|
intents.setCategories(set);
|
|
|
|
}
|
|
|
|
intents.setRank(this.mRank);
|
2021-09-29 00:45:08 +00:00
|
|
|
PersistableBundle persistableBundle = this.mExtras;
|
|
|
|
if (persistableBundle != null) {
|
|
|
|
intents.setExtras(persistableBundle);
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= 29) {
|
|
|
|
Person[] personArr = this.mPersons;
|
|
|
|
if (personArr != null && personArr.length > 0) {
|
|
|
|
int length = personArr.length;
|
|
|
|
android.app.Person[] personArr2 = new android.app.Person[length];
|
|
|
|
for (int i = 0; i < length; i++) {
|
|
|
|
personArr2[i] = this.mPersons[i].toAndroidPerson();
|
|
|
|
}
|
|
|
|
intents.setPersons(personArr2);
|
|
|
|
}
|
2021-09-29 00:45:08 +00:00
|
|
|
LocusIdCompat locusIdCompat = this.mLocusId;
|
|
|
|
if (locusIdCompat != null) {
|
|
|
|
intents.setLocusId(locusIdCompat.toLocusId());
|
|
|
|
}
|
2021-06-27 20:44:35 +00:00
|
|
|
intents.setLongLived(this.mIsLongLived);
|
|
|
|
} else {
|
|
|
|
intents.setExtras(buildLegacyExtrasBundle());
|
|
|
|
}
|
|
|
|
return intents.build();
|
|
|
|
}
|
|
|
|
}
|