173 lines
7.7 KiB
Java
173 lines
7.7 KiB
Java
|
package androidx.core.content.pm;
|
||
|
|
||
|
import android.content.BroadcastReceiver;
|
||
|
import android.content.Context;
|
||
|
import android.content.Intent;
|
||
|
import android.content.IntentSender;
|
||
|
import android.content.pm.ResolveInfo;
|
||
|
import android.content.pm.ShortcutInfo;
|
||
|
import android.content.pm.ShortcutManager;
|
||
|
import android.os.Build;
|
||
|
import android.text.TextUtils;
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.annotation.Nullable;
|
||
|
import androidx.annotation.VisibleForTesting;
|
||
|
import androidx.core.content.ContextCompat;
|
||
|
import androidx.core.content.pm.ShortcutInfoCompat;
|
||
|
import androidx.core.content.pm.ShortcutInfoCompatSaver;
|
||
|
import java.util.ArrayList;
|
||
|
import java.util.List;
|
||
|
public class ShortcutManagerCompat {
|
||
|
@VisibleForTesting
|
||
|
public static final String ACTION_INSTALL_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT";
|
||
|
public static final String EXTRA_SHORTCUT_ID = "android.intent.extra.shortcut.ID";
|
||
|
@VisibleForTesting
|
||
|
public static final String INSTALL_SHORTCUT_PERMISSION = "com.android.launcher.permission.INSTALL_SHORTCUT";
|
||
|
private static volatile ShortcutInfoCompatSaver<?> sShortcutInfoCompatSaver;
|
||
|
|
||
|
/* renamed from: androidx.core.content.pm.ShortcutManagerCompat$1 reason: invalid class name */
|
||
|
public class AnonymousClass1 extends BroadcastReceiver {
|
||
|
public final /* synthetic */ IntentSender val$callback;
|
||
|
|
||
|
public AnonymousClass1(IntentSender intentSender) {
|
||
|
this.val$callback = intentSender;
|
||
|
}
|
||
|
|
||
|
@Override // android.content.BroadcastReceiver
|
||
|
public void onReceive(Context context, Intent intent) {
|
||
|
try {
|
||
|
this.val$callback.sendIntent(context, 0, null, null, null);
|
||
|
} catch (IntentSender.SendIntentException unused) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private ShortcutManagerCompat() {
|
||
|
}
|
||
|
|
||
|
public static boolean addDynamicShortcuts(@NonNull Context context, @NonNull List<ShortcutInfoCompat> list) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
for (ShortcutInfoCompat shortcutInfoCompat : list) {
|
||
|
arrayList.add(shortcutInfoCompat.toShortcutInfo());
|
||
|
}
|
||
|
if (!((ShortcutManager) context.getSystemService(ShortcutManager.class)).addDynamicShortcuts(arrayList)) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
getShortcutInfoSaverInstance(context).addShortcuts(list);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public static Intent createShortcutResultIntent(@NonNull Context context, @NonNull ShortcutInfoCompat shortcutInfoCompat) {
|
||
|
Intent createShortcutResultIntent = Build.VERSION.SDK_INT >= 26 ? ((ShortcutManager) context.getSystemService(ShortcutManager.class)).createShortcutResultIntent(shortcutInfoCompat.toShortcutInfo()) : null;
|
||
|
if (createShortcutResultIntent == null) {
|
||
|
createShortcutResultIntent = new Intent();
|
||
|
}
|
||
|
return shortcutInfoCompat.addToIntent(createShortcutResultIntent);
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public static List<ShortcutInfoCompat> getDynamicShortcuts(@NonNull Context context) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
List<ShortcutInfo> dynamicShortcuts = ((ShortcutManager) context.getSystemService(ShortcutManager.class)).getDynamicShortcuts();
|
||
|
ArrayList arrayList = new ArrayList(dynamicShortcuts.size());
|
||
|
for (ShortcutInfo shortcutInfo : dynamicShortcuts) {
|
||
|
arrayList.add(new ShortcutInfoCompat.Builder(context, shortcutInfo).build());
|
||
|
}
|
||
|
return arrayList;
|
||
|
}
|
||
|
try {
|
||
|
return getShortcutInfoSaverInstance(context).getShortcuts();
|
||
|
} catch (Exception unused) {
|
||
|
return new ArrayList();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static int getMaxShortcutCountPerActivity(@NonNull Context context) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
return ((ShortcutManager) context.getSystemService(ShortcutManager.class)).getMaxShortcutCountPerActivity();
|
||
|
}
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
private static ShortcutInfoCompatSaver<?> getShortcutInfoSaverInstance(Context context) {
|
||
|
if (sShortcutInfoCompatSaver == null) {
|
||
|
if (Build.VERSION.SDK_INT >= 23) {
|
||
|
try {
|
||
|
sShortcutInfoCompatSaver = (ShortcutInfoCompatSaver) Class.forName("androidx.sharetarget.ShortcutInfoCompatSaverImpl", false, ShortcutManagerCompat.class.getClassLoader()).getMethod("getInstance", Context.class).invoke(null, context);
|
||
|
} catch (Exception unused) {
|
||
|
}
|
||
|
}
|
||
|
if (sShortcutInfoCompatSaver == null) {
|
||
|
sShortcutInfoCompatSaver = new ShortcutInfoCompatSaver.NoopImpl();
|
||
|
}
|
||
|
}
|
||
|
return sShortcutInfoCompatSaver;
|
||
|
}
|
||
|
|
||
|
/* JADX WARNING: Removed duplicated region for block: B:10:0x0036 */
|
||
|
public static boolean isRequestPinShortcutSupported(@NonNull Context context) {
|
||
|
if (Build.VERSION.SDK_INT >= 26) {
|
||
|
return ((ShortcutManager) context.getSystemService(ShortcutManager.class)).isRequestPinShortcutSupported();
|
||
|
}
|
||
|
if (ContextCompat.checkSelfPermission(context, "com.android.launcher.permission.INSTALL_SHORTCUT") != 0) {
|
||
|
return false;
|
||
|
}
|
||
|
for (ResolveInfo resolveInfo : context.getPackageManager().queryBroadcastReceivers(new Intent("com.android.launcher.action.INSTALL_SHORTCUT"), 0)) {
|
||
|
String str = resolveInfo.activityInfo.permission;
|
||
|
if (TextUtils.isEmpty(str) || "com.android.launcher.permission.INSTALL_SHORTCUT".equals(str)) {
|
||
|
return true;
|
||
|
}
|
||
|
while (r4.hasNext()) {
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
public static void removeAllDynamicShortcuts(@NonNull Context context) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
((ShortcutManager) context.getSystemService(ShortcutManager.class)).removeAllDynamicShortcuts();
|
||
|
}
|
||
|
getShortcutInfoSaverInstance(context).removeAllShortcuts();
|
||
|
}
|
||
|
|
||
|
public static void removeDynamicShortcuts(@NonNull Context context, @NonNull List<String> list) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
((ShortcutManager) context.getSystemService(ShortcutManager.class)).removeDynamicShortcuts(list);
|
||
|
}
|
||
|
getShortcutInfoSaverInstance(context).removeShortcuts(list);
|
||
|
}
|
||
|
|
||
|
public static boolean requestPinShortcut(@NonNull Context context, @NonNull ShortcutInfoCompat shortcutInfoCompat, @Nullable IntentSender intentSender) {
|
||
|
if (Build.VERSION.SDK_INT >= 26) {
|
||
|
return ((ShortcutManager) context.getSystemService(ShortcutManager.class)).requestPinShortcut(shortcutInfoCompat.toShortcutInfo(), intentSender);
|
||
|
}
|
||
|
if (!isRequestPinShortcutSupported(context)) {
|
||
|
return false;
|
||
|
}
|
||
|
Intent addToIntent = shortcutInfoCompat.addToIntent(new Intent("com.android.launcher.action.INSTALL_SHORTCUT"));
|
||
|
if (intentSender == null) {
|
||
|
context.sendBroadcast(addToIntent);
|
||
|
return true;
|
||
|
}
|
||
|
context.sendOrderedBroadcast(addToIntent, null, new AnonymousClass1(intentSender), null, -1, null, null);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
public static boolean updateShortcuts(@NonNull Context context, @NonNull List<ShortcutInfoCompat> list) {
|
||
|
if (Build.VERSION.SDK_INT >= 25) {
|
||
|
ArrayList arrayList = new ArrayList();
|
||
|
for (ShortcutInfoCompat shortcutInfoCompat : list) {
|
||
|
arrayList.add(shortcutInfoCompat.toShortcutInfo());
|
||
|
}
|
||
|
if (!((ShortcutManager) context.getSystemService(ShortcutManager.class)).updateShortcuts(arrayList)) {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
getShortcutInfoSaverInstance(context).addShortcuts(list);
|
||
|
return true;
|
||
|
}
|
||
|
}
|