@Test public void testInsert() { assertResultCount(contentResolver, 0, InstalledAppProvider.getContentUri()); insertInstalledApp("com.example.com1", 1, "v1"); insertInstalledApp("com.example.com2", 2, "v2"); insertInstalledApp("com.example.com3", 3, "v3"); assertResultCount(contentResolver, 3, InstalledAppProvider.getContentUri()); assertIsInstalledVersionInDb(contentResolver, "com.example.com1", 1, "v1"); assertIsInstalledVersionInDb(contentResolver, "com.example.com2", 2, "v2"); assertIsInstalledVersionInDb(contentResolver, "com.example.com3", 3, "v3"); App[] apps = InstalledAppProvider.Helper.all(context); assertEquals(3, apps.length); }
@Override public Uri insert(@NonNull Uri uri, ContentValues values) { if (MATCHER.match(uri) != CODE_LIST) { throw new UnsupportedOperationException("Insert not supported for " + uri + "."); } if (!values.containsKey(Cols.Package.NAME)) { throw new IllegalStateException("Package name not provided to InstalledAppProvider"); } String packageName = values.getAsString(Cols.Package.NAME); long packageId = PackageProvider.Helper.ensureExists(getContext(), packageName); values.remove(Cols.Package.NAME); values.put(Cols.PACKAGE_ID, packageId); verifyVersionNameNotNull(values); db().replaceOrThrow(getTableName(), null, values); AppProvider.Helper.calcSuggestedApk(getContext(), packageName); return getAppUri(values.getAsString(Cols.Package.NAME)); }
InstalledAppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { if (MATCHER.match(uri) != CODE_LIST) { throw new UnsupportedOperationException("Insert not supported for " + uri + "."); } if (!values.containsKey(Cols.Package.NAME)) { throw new IllegalStateException("Package name not provided to InstalledAppProvider"); } String packageName = values.getAsString(Cols.Package.NAME); long packageId = PackageProvider.Helper.ensureExists(getContext(), packageName); values.remove(Cols.Package.NAME); values.put(Cols.PACKAGE_ID, packageId); verifyVersionNameNotNull(values); db().replaceOrThrow(getTableName(), null, values); AppProvider.Helper.calcSuggestedApk(getContext(), packageName); return getAppUri(values.getAsString(Cols.Package.NAME)); } }
InstalledAppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { if (MATCHER.match(uri) != CODE_LIST) { throw new UnsupportedOperationException("Insert not supported for " + uri + "."); } if (!values.containsKey(Cols.Package.NAME)) { throw new IllegalStateException("Package name not provided to InstalledAppProvider"); } String packageName = values.getAsString(Cols.Package.NAME); long packageId = PackageProvider.Helper.ensureExists(getContext(), packageName); values.remove(Cols.Package.NAME); values.put(Cols.PACKAGE_ID, packageId); verifyVersionNameNotNull(values); db().replaceOrThrow(getTableName(), null, values); AppProvider.Helper.calcSuggestedApk(getContext(), packageName); return getAppUri(values.getAsString(Cols.Package.NAME)); }  }
InstalledAppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { if (MATCHER.match(uri) != CODE_LIST) { throw new UnsupportedOperationException("Insert not supported for " + uri + "."); } if (!values.containsKey(Cols.Package.NAME)) { throw new IllegalStateException("Package name not provided to InstalledAppProvider"); } String packageName = values.getAsString(Cols.Package.NAME); long packageId = PackageProvider.Helper.ensureExists(getContext(), packageName); values.remove(Cols.Package.NAME); values.put(Cols.PACKAGE_ID, packageId); verifyVersionNameNotNull(values); db().replaceOrThrow(getTableName(), null, values); AppProvider.Helper.calcSuggestedApk(getContext(), packageName); return getAppUri(values.getAsString(Cols.Package.NAME)); }  static Uri getContentUri(); static Uri getAllAppsUri(); static Uri getAppUri(String packageName); static Uri getSearchUri(String keywords); static String getApplicationLabel(Context context, String packageName); 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); }
InstalledAppProvider extends FDroidProvider { @Override public Uri insert(@NonNull Uri uri, ContentValues values) { if (MATCHER.match(uri) != CODE_LIST) { throw new UnsupportedOperationException("Insert not supported for " + uri + "."); } if (!values.containsKey(Cols.Package.NAME)) { throw new IllegalStateException("Package name not provided to InstalledAppProvider"); } String packageName = values.getAsString(Cols.Package.NAME); long packageId = PackageProvider.Helper.ensureExists(getContext(), packageName); values.remove(Cols.Package.NAME); values.put(Cols.PACKAGE_ID, packageId); verifyVersionNameNotNull(values); db().replaceOrThrow(getTableName(), null, values); AppProvider.Helper.calcSuggestedApk(getContext(), packageName); return getAppUri(values.getAsString(Cols.Package.NAME)); }  static Uri getContentUri(); static Uri getAllAppsUri(); static Uri getAppUri(String packageName); static Uri getSearchUri(String keywords); static String getApplicationLabel(Context context, String packageName); 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);  }