ApkProvider extends FDroidProvider { @Override public int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs) { if (MATCHER.match(uri) != CODE_APK_FROM_REPO) { throw new UnsupportedOperationException("Cannot update anything other than a single apk."); } boolean saveAntiFeatures = false; String[] antiFeatures = null; if (values.containsKey(Cols.AntiFeatures.ANTI_FEATURES)) { saveAntiFeatures = true; String antiFeaturesString = values.getAsString(Cols.AntiFeatures.ANTI_FEATURES); antiFeatures = Utils.parseCommaSeparatedString(antiFeaturesString); values.remove(Cols.AntiFeatures.ANTI_FEATURES); } validateFields(Cols.ALL, values); removeFieldsFromOtherTables(values); QuerySelection query = new QuerySelection(where, whereArgs); query = query.add(querySingleWithAppId(uri)); int numRows = db().update(getTableName(), values, query.getSelection(), query.getArgs()); if (saveAntiFeatures) { Cursor result = db().query(getTableName(), new String[]{Cols.ROW_ID}, query.getSelection(), query.getArgs(), null, null, null); if (result != null) { result.moveToFirst(); long apkId = result.getLong(0); ensureAntiFeatures(antiFeatures, apkId); result.close(); } } if (!isApplyingBatch()) { getContext().getContentResolver().notifyChange(uri, null); } return numRows; }  static String getAuthority(); static Uri getContentUri(); static Uri getAppUri(String packageName); static Uri getRepoUri(long repoId); static Uri getRepoUri(long repoId, String packageName); static Uri getApkFromAnyRepoUri(Apk apk); static Uri getApkFromAnyRepoUri(String packageName, int versionCode, @Nullable String signature); @Override Cursor query(@NonNull Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder); @Override Uri insert(@NonNull Uri uri, ContentValues values); @Override int delete(@NonNull Uri uri, String where, String[] whereArgs); @Override int update(@NonNull Uri uri, ContentValues values, String where, String[] whereArgs);  }
@Test public void testUpdate() { Uri apkUri = Assert.insertApk(context, "com.example", 10); String[] allFields = Cols.ALL; Cursor cursor = contentResolver.query(apkUri, allFields, null, null, null); assertResultCount(1, cursor); cursor.moveToFirst(); Apk apk = new Apk(cursor); cursor.close(); assertEquals("com.example", apk.packageName); assertEquals(10, apk.versionCode); assertNull(apk.antiFeatures); assertNull(apk.features); assertNull(apk.added); assertNull(apk.hashType); apk.antiFeatures = new String[]{"KnownVuln", "Other anti feature"}; apk.features = new String[]{"one", "two", "three"}; apk.hashType = "i'm a hash type"; Date testTime = Utils.parseDate(Utils.formatTime(new Date(System.currentTimeMillis()), null), null); apk.added = testTime; ApkProvider.Helper.update(context, apk); Cursor allCursor = contentResolver.query(ApkProvider.getContentUri(), allFields, null, null, null); assertResultCount(1, allCursor); allCursor.close(); Cursor updatedCursor = contentResolver.query(apkUri, allFields, null, null, null); assertResultCount(1, updatedCursor); updatedCursor.moveToFirst(); Apk updatedApk = new Apk(updatedCursor); updatedCursor.close(); assertEquals("com.example", updatedApk.packageName); assertEquals(10, updatedApk.versionCode); assertArrayEquals(new String[]{"KnownVuln", "Other anti feature"}, updatedApk.antiFeatures); assertArrayEquals(new String[]{"one", "two", "three"}, updatedApk.features); assertEquals(testTime.getYear(), updatedApk.added.getYear()); assertEquals(testTime.getYear(), updatedApk.added.getYear()); assertEquals(testTime.getMonth(), updatedApk.added.getMonth()); assertEquals(testTime.getDay(), updatedApk.added.getDay()); assertEquals("i'm a hash type", updatedApk.hashType); }