Beispiel #1
0
  /**
   * Finds all apks from the repo we are currently updating, that belong to the specified app, and
   * delete them as they are no longer provided by that repo.
   */
  @Nullable
  private ContentProviderOperation deleteOrphanedApks(
      List<App> apps, Map<String, List<Apk>> packages) {
    String[] projection =
        new String[] {ApkProvider.DataColumns.PACKAGE_NAME, ApkProvider.DataColumns.VERSION_CODE};
    List<Apk> existing = ApkProvider.Helper.find(context, repo, apps, projection);
    List<Apk> toDelete = new ArrayList<>();

    for (Apk existingApk : existing) {
      boolean shouldStay = false;

      if (packages.containsKey(existingApk.packageName)) {
        for (Apk newApk : packages.get(existingApk.packageName)) {
          if (newApk.vercode == existingApk.vercode) {
            shouldStay = true;
            break;
          }
        }
      }

      if (!shouldStay) {
        toDelete.add(existingApk);
      }
    }

    if (toDelete.size() == 0) {
      return null;
    }
    Uri uri = TempApkProvider.getApksUri(repo, toDelete);
    return ContentProviderOperation.newDelete(uri).build();
  }
Beispiel #2
0
  /**
   * Depending on whether the .apks have been added to the database previously, this will queue up
   * an update or an insert {@link ContentProviderOperation} for each package.
   */
  private ArrayList<ContentProviderOperation> insertOrUpdateApks(List<Apk> packages) {
    String[] projection =
        new String[] {
          ApkProvider.DataColumns.PACKAGE_NAME, ApkProvider.DataColumns.VERSION_CODE,
        };
    List<Apk> existingApks = ApkProvider.Helper.knownApks(context, packages, projection);
    ArrayList<ContentProviderOperation> operations = new ArrayList<>(packages.size());
    for (Apk apk : packages) {
      boolean exists = false;
      for (Apk existing : existingApks) {
        if (existing.packageName.equals(apk.packageName) && existing.vercode == apk.vercode) {
          exists = true;
          break;
        }
      }

      if (exists) {
        operations.add(updateExistingApk(apk));
      } else {
        operations.add(insertNewApk(apk));
      }
    }

    return operations;
  }