/** Returns whether <em>apps</em> contains <em>component</em>. */
 private static boolean findActivity(
     List<LauncherActivityInfoCompat> apps, ComponentName component) {
   for (LauncherActivityInfoCompat info : apps) {
     if (info.getComponentName().equals(component)) {
       return true;
     }
   }
   return false;
 }
  /** Add and remove icons for this package which has been updated. */
  public void updatePackage(Context context, String packageName, UserHandleCompat user) {
    final LauncherAppsCompat launcherApps = LauncherAppsCompat.getInstance(context);
    final List<LauncherActivityInfoCompat> matches =
        launcherApps.getActivityList(packageName, user);
    if (matches.size() > 0) {
      // Find disabled/removed activities and remove them from data and add them
      // to the removed list.
      for (int i = data.size() - 1; i >= 0; i--) {
        final AppInfo applicationInfo = data.get(i);
        final ComponentName component = applicationInfo.intent.getComponent();
        if (user.equals(applicationInfo.user) && packageName.equals(component.getPackageName())) {
          if (!findActivity(matches, component)) {
            removed.add(applicationInfo);
            data.remove(i);
          }
        }
      }

      // Find enabled activities and add them to the adapter
      // Also updates existing activities with new labels/icons
      for (final LauncherActivityInfoCompat info : matches) {
        AppInfo applicationInfo =
            findApplicationInfoLocked(
                info.getComponentName().getPackageName(),
                user,
                info.getComponentName().getClassName());
        if (applicationInfo == null) {
          add(new AppInfo(context, info, user, mIconCache));
        } else {
          mIconCache.getTitleAndIcon(applicationInfo, info, true /* useLowResIcon */);
          modified.add(applicationInfo);
        }
      }
    } else {
      // Remove all data for this package.
      for (int i = data.size() - 1; i >= 0; i--) {
        final AppInfo applicationInfo = data.get(i);
        final ComponentName component = applicationInfo.intent.getComponent();
        if (user.equals(applicationInfo.user) && packageName.equals(component.getPackageName())) {
          removed.add(applicationInfo);
          mIconCache.remove(component, user);
          data.remove(i);
        }
      }
    }
  }