public static void removeFromInstallQueue(
     Context context, ArrayList<String> packageNames, UserHandleCompat user) {
   if (packageNames.isEmpty()) {
     return;
   }
   String spKey = LauncherAppState.getSharedPreferencesKey();
   SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
   synchronized (sLock) {
     Set<String> strings = sp.getStringSet(APPS_PENDING_INSTALL, null);
     if (DBG) {
       Log.d(TAG, "APPS_PENDING_INSTALL: " + strings + ", removing packages: " + packageNames);
     }
     if (strings != null) {
       Set<String> newStrings = new HashSet<String>(strings);
       Iterator<String> newStringsIter = newStrings.iterator();
       while (newStringsIter.hasNext()) {
         String encoded = newStringsIter.next();
         PendingInstallShortcutInfo info = decode(encoded, context);
         if (info == null
             || (packageNames.contains(info.getTargetPackage()) && user.equals(info.user))) {
           newStringsIter.remove();
         }
       }
       sp.edit().putStringSet(APPS_PENDING_INSTALL, newStrings).commit();
     }
   }
 }
  static void flushInstallQueue(Context context) {
    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    ArrayList<PendingInstallShortcutInfo> installQueue = getAndClearInstallQueue(sp, context);
    if (!installQueue.isEmpty()) {
      Iterator<PendingInstallShortcutInfo> iter = installQueue.iterator();
      ArrayList<ItemInfo> addShortcuts = new ArrayList<ItemInfo>();
      while (iter.hasNext()) {
        final PendingInstallShortcutInfo pendingInfo = iter.next();
        final Intent intent = pendingInfo.launchIntent;

        if (LauncherAppState.isDisableAllApps() && !isValidShortcutLaunchIntent(intent)) {
          if (DBG) Log.d(TAG, "Ignoring shortcut with launchIntent:" + intent);
          continue;
        }

        // If the intent specifies a package, make sure the package exists
        String packageName = pendingInfo.getTargetPackage();
        if (!TextUtils.isEmpty(packageName)) {
          UserHandleCompat myUserHandle = UserHandleCompat.myUserHandle();
          if (!LauncherModel.isValidPackage(context, packageName, myUserHandle)) {
            if (DBG) Log.d(TAG, "Ignoring shortcut for absent package:" + intent);
            continue;
          }
        }

        final boolean exists =
            LauncherModel.shortcutExists(context, pendingInfo.label, intent, pendingInfo.user);
        if (!exists) {
          // Generate a shortcut info to add into the model
          addShortcuts.add(pendingInfo.getShortcutInfo());
        }
      }

      // Add the new apps to the model and bind them
      if (!addShortcuts.isEmpty()) {
        LauncherAppState app = LauncherAppState.getInstance();
        app.getModel().addAndBindAddedWorkspaceApps(context, addShortcuts);
      }
    }
  }
 private static void addToInstallQueue(
     SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) {
   synchronized (sLock) {
     String encoded = info.encodeToString();
     if (encoded != null) {
       Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
       if (strings == null) {
         strings = new HashSet<String>(1);
       } else {
         strings = new HashSet<String>(strings);
       }
       strings.add(encoded);
       sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, strings).commit();
     }
   }
 }