@Test public void testInsert() { Cursor cursor = queryAllApps(); assertNotNull(cursor); assertEquals(0, cursor.getCount()); cursor.close(); insertApp("org.fdroid.fdroid", "F-Droid"); cursor = queryAllApps(); assertNotNull(cursor); assertEquals(1, cursor.getCount()); cursor.moveToFirst(); App app = new App(cursor); cursor.close(); assertEquals("org.fdroid.fdroid", app.packageName); assertEquals("F-Droid", app.name); App otherApp = AppProvider.Helper.findSpecificApp(context.getContentResolver(), "org.fdroid.fdroid", 1, Cols.ALL); assertNotNull(otherApp); assertEquals("org.fdroid.fdroid", otherApp.packageName); assertEquals("F-Droid", otherApp.name); }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { long packageId = PackageProvider.Helper.ensureExists(getContext(), values.getAsString(Cols.Package.PACKAGE_NAME)); values.remove(Cols.Package.PACKAGE_NAME); values.put(Cols.PACKAGE_ID, packageId); if (!values.containsKey(Cols.DESCRIPTION) || values.getAsString(Cols.DESCRIPTION) == null) { values.put(Cols.DESCRIPTION, ""); } values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim()); values.put(Cols.NAME, values.getAsString(Cols.NAME).trim()); String[] categories = null; boolean saveCategories = false; if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) { saveCategories = true; categories = Utils.parseCommaSeparatedString(values.getAsString(Cols.ForWriting.Categories.CATEGORIES)); values.remove(Cols.ForWriting.Categories.CATEGORIES); } long appMetadataId = db().insertOrThrow(getTableName(), null, values); if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } if (saveCategories) { ensureCategories(categories, appMetadataId); } return getSpecificAppUri(values.getAsString(PackageTable.Cols.PACKAGE_NAME), values.getAsLong(Cols.REPO_ID)); }
AppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { long packageId = PackageProvider.Helper.ensureExists(getContext(), values.getAsString(Cols.Package.PACKAGE_NAME)); values.remove(Cols.Package.PACKAGE_NAME); values.put(Cols.PACKAGE_ID, packageId); if (!values.containsKey(Cols.DESCRIPTION) || values.getAsString(Cols.DESCRIPTION) == null) { values.put(Cols.DESCRIPTION, ""); } values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim()); values.put(Cols.NAME, values.getAsString(Cols.NAME).trim()); String[] categories = null; boolean saveCategories = false; if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) { saveCategories = true; categories = Utils.parseCommaSeparatedString(values.getAsString(Cols.ForWriting.Categories.CATEGORIES)); values.remove(Cols.ForWriting.Categories.CATEGORIES); } long appMetadataId = db().insertOrThrow(getTableName(), null, values); if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } if (saveCategories) { ensureCategories(categories, appMetadataId); } return getSpecificAppUri(values.getAsString(PackageTable.Cols.PACKAGE_NAME), values.getAsLong(Cols.REPO_ID)); } }
AppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { long packageId = PackageProvider.Helper.ensureExists(getContext(), values.getAsString(Cols.Package.PACKAGE_NAME)); values.remove(Cols.Package.PACKAGE_NAME); values.put(Cols.PACKAGE_ID, packageId); if (!values.containsKey(Cols.DESCRIPTION) || values.getAsString(Cols.DESCRIPTION) == null) { values.put(Cols.DESCRIPTION, ""); } values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim()); values.put(Cols.NAME, values.getAsString(Cols.NAME).trim()); String[] categories = null; boolean saveCategories = false; if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) { saveCategories = true; categories = Utils.parseCommaSeparatedString(values.getAsString(Cols.ForWriting.Categories.CATEGORIES)); values.remove(Cols.ForWriting.Categories.CATEGORIES); } long appMetadataId = db().insertOrThrow(getTableName(), null, values); if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } if (saveCategories) { ensureCategories(categories, appMetadataId); } return getSpecificAppUri(values.getAsString(PackageTable.Cols.PACKAGE_NAME), values.getAsLong(Cols.REPO_ID)); }  }
AppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { long packageId = PackageProvider.Helper.ensureExists(getContext(), values.getAsString(Cols.Package.PACKAGE_NAME)); values.remove(Cols.Package.PACKAGE_NAME); values.put(Cols.PACKAGE_ID, packageId); if (!values.containsKey(Cols.DESCRIPTION) || values.getAsString(Cols.DESCRIPTION) == null) { values.put(Cols.DESCRIPTION, ""); } values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim()); values.put(Cols.NAME, values.getAsString(Cols.NAME).trim()); String[] categories = null; boolean saveCategories = false; if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) { saveCategories = true; categories = Utils.parseCommaSeparatedString(values.getAsString(Cols.ForWriting.Categories.CATEGORIES)); values.remove(Cols.ForWriting.Categories.CATEGORIES); } long appMetadataId = db().insertOrThrow(getTableName(), null, values); if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } if (saveCategories) { ensureCategories(categories, appMetadataId); } return getSpecificAppUri(values.getAsString(PackageTable.Cols.PACKAGE_NAME), values.getAsLong(Cols.REPO_ID)); }  static Uri getContentUri(); static Uri getRecentlyUpdatedUri(); static Uri getCategoryUri(String category); static Uri getInstalledWithKnownVulnsUri(); static Uri getTopFromCategoryUri(String category, int limit); static Uri getInstalledUri(); static Uri getCanUpdateUri(); static Uri getRepoUri(Repo repo); static Uri getSpecificAppUri(String packageName, long repoId); static Uri getHighestPriorityMetadataUri(String packageName); static Uri getSearchUri(String query, @Nullable String category); static Uri getSearchUri(Repo repo, String query); static String getAuthority(); @Override Cursor query(@NonNull Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder); @Override int delete(@NonNull Uri uri, String where, String[] whereArgs); @Override Uri insert(@NonNull Uri uri, ContentValues values); @Override int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs); }
AppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { long packageId = PackageProvider.Helper.ensureExists(getContext(), values.getAsString(Cols.Package.PACKAGE_NAME)); values.remove(Cols.Package.PACKAGE_NAME); values.put(Cols.PACKAGE_ID, packageId); if (!values.containsKey(Cols.DESCRIPTION) || values.getAsString(Cols.DESCRIPTION) == null) { values.put(Cols.DESCRIPTION, ""); } values.put(Cols.SUMMARY, values.getAsString(Cols.SUMMARY).trim()); values.put(Cols.NAME, values.getAsString(Cols.NAME).trim()); String[] categories = null; boolean saveCategories = false; if (values.containsKey(Cols.ForWriting.Categories.CATEGORIES)) { saveCategories = true; categories = Utils.parseCommaSeparatedString(values.getAsString(Cols.ForWriting.Categories.CATEGORIES)); values.remove(Cols.ForWriting.Categories.CATEGORIES); } long appMetadataId = db().insertOrThrow(getTableName(), null, values); if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } if (saveCategories) { ensureCategories(categories, appMetadataId); } return getSpecificAppUri(values.getAsString(PackageTable.Cols.PACKAGE_NAME), values.getAsLong(Cols.REPO_ID)); }  static Uri getContentUri(); static Uri getRecentlyUpdatedUri(); static Uri getCategoryUri(String category); static Uri getInstalledWithKnownVulnsUri(); static Uri getTopFromCategoryUri(String category, int limit); static Uri getInstalledUri(); static Uri getCanUpdateUri(); static Uri getRepoUri(Repo repo); static Uri getSpecificAppUri(String packageName, long repoId); static Uri getHighestPriorityMetadataUri(String packageName); static Uri getSearchUri(String query, @Nullable String category); static Uri getSearchUri(Repo repo, String query); static String getAuthority(); @Override Cursor query(@NonNull Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder); @Override int delete(@NonNull Uri uri, String where, String[] whereArgs); @Override Uri insert(@NonNull Uri uri, ContentValues values); @Override int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs);  }