/** 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);
        }
      }
    }
  }
 /** Find an ApplicationInfo object for the given packageName and className. */
 private AppInfo findApplicationInfoLocked(
     String packageName, UserHandleCompat user, String className) {
   for (AppInfo info : data) {
     final ComponentName component = info.intent.getComponent();
     if (user.equals(info.user)
         && packageName.equals(component.getPackageName())
         && className.equals(component.getClassName())) {
       return info;
     }
   }
   return null;
 }