@Test @SmallTest @SdkSuppress(minSdkVersion = 26) public void testIsRequestPinShortcutSupported_v26() throws Throwable { ShortcutManager mockShortcutManager = mock(ShortcutManager.class); doReturn(mockShortcutManager).when(mContext).getSystemService(eq(Context.SHORTCUT_SERVICE)); when(mockShortcutManager.isRequestPinShortcutSupported()).thenReturn(true, false, true); assertTrue(ShortcutManagerCompat.isRequestPinShortcutSupported(mContext)); assertFalse(ShortcutManagerCompat.isRequestPinShortcutSupported(mContext)); assertTrue(ShortcutManagerCompat.isRequestPinShortcutSupported(mContext)); verify(mockShortcutManager, times(3)).isRequestPinShortcutSupported(); }
public static boolean isRequestPinShortcutSupported(@NonNull Context context) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported(); } if (ContextCompat.checkSelfPermission(context, INSTALL_SHORTCUT_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; } for (ResolveInfo info : context.getPackageManager().queryBroadcastReceivers( new Intent(ACTION_INSTALL_SHORTCUT), 0)) { String permission = info.activityInfo.permission; if (TextUtils.isEmpty(permission) || INSTALL_SHORTCUT_PERMISSION.equals(permission)) { return true; } } return false; }
ShortcutManagerCompat { public static boolean isRequestPinShortcutSupported(@NonNull Context context) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported(); } if (ContextCompat.checkSelfPermission(context, INSTALL_SHORTCUT_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; } for (ResolveInfo info : context.getPackageManager().queryBroadcastReceivers( new Intent(ACTION_INSTALL_SHORTCUT), 0)) { String permission = info.activityInfo.permission; if (TextUtils.isEmpty(permission) || INSTALL_SHORTCUT_PERMISSION.equals(permission)) { return true; } } return false; } }
ShortcutManagerCompat { public static boolean isRequestPinShortcutSupported(@NonNull Context context) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported(); } if (ContextCompat.checkSelfPermission(context, INSTALL_SHORTCUT_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; } for (ResolveInfo info : context.getPackageManager().queryBroadcastReceivers( new Intent(ACTION_INSTALL_SHORTCUT), 0)) { String permission = info.activityInfo.permission; if (TextUtils.isEmpty(permission) || INSTALL_SHORTCUT_PERMISSION.equals(permission)) { return true; } } return false; } private  ShortcutManagerCompat(); }
ShortcutManagerCompat { public static boolean isRequestPinShortcutSupported(@NonNull Context context) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported(); } if (ContextCompat.checkSelfPermission(context, INSTALL_SHORTCUT_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; } for (ResolveInfo info : context.getPackageManager().queryBroadcastReceivers( new Intent(ACTION_INSTALL_SHORTCUT), 0)) { String permission = info.activityInfo.permission; if (TextUtils.isEmpty(permission) || INSTALL_SHORTCUT_PERMISSION.equals(permission)) { return true; } } return false; } private  ShortcutManagerCompat(); static boolean isRequestPinShortcutSupported(@NonNull Context context); static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback); @NonNull static Intent createShortcutResultIntent(@NonNull Context context,
            @NonNull ShortcutInfoCompat shortcut); }
ShortcutManagerCompat { public static boolean isRequestPinShortcutSupported(@NonNull Context context) { if (Build.VERSION.SDK_INT >= 26) { return context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported(); } if (ContextCompat.checkSelfPermission(context, INSTALL_SHORTCUT_PERMISSION) != PackageManager.PERMISSION_GRANTED) { return false; } for (ResolveInfo info : context.getPackageManager().queryBroadcastReceivers( new Intent(ACTION_INSTALL_SHORTCUT), 0)) { String permission = info.activityInfo.permission; if (TextUtils.isEmpty(permission) || INSTALL_SHORTCUT_PERMISSION.equals(permission)) { return true; } } return false; } private  ShortcutManagerCompat(); static boolean isRequestPinShortcutSupported(@NonNull Context context); static boolean requestPinShortcut(@NonNull final Context context,
            @NonNull ShortcutInfoCompat shortcut, @Nullable final IntentSender callback); @NonNull static Intent createShortcutResultIntent(@NonNull Context context,
            @NonNull ShortcutInfoCompat shortcut);  }