Added 'ignore vuln' preference for apps
This commit is contained in:
parent
4e544e61fb
commit
5f64985b34
@ -3,37 +3,44 @@ package org.fdroid.fdroid.data;
|
||||
public class AppPrefs extends ValueObject {
|
||||
|
||||
/**
|
||||
* True if all updates for this app are to be ignored
|
||||
* True if all updates for this app are to be ignored.
|
||||
*/
|
||||
public boolean ignoreAllUpdates;
|
||||
|
||||
/**
|
||||
* True if the current update for this app is to be ignored
|
||||
* The version code of the app for which the update should be ignored.
|
||||
*/
|
||||
public int ignoreThisUpdate;
|
||||
|
||||
public AppPrefs(int ignoreThis, boolean ignoreAll) {
|
||||
/**
|
||||
* Don't notify of vulnerabilities in this app.
|
||||
*/
|
||||
public boolean ignoreVulnerabilities;
|
||||
|
||||
public AppPrefs(int ignoreThis, boolean ignoreAll, boolean ignoreVulns) {
|
||||
ignoreThisUpdate = ignoreThis;
|
||||
ignoreAllUpdates = ignoreAll;
|
||||
ignoreVulnerabilities = ignoreVulns;
|
||||
}
|
||||
|
||||
public static AppPrefs createDefault() {
|
||||
return new AppPrefs(0, false);
|
||||
return new AppPrefs(0, false, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
return o != null && o instanceof AppPrefs &&
|
||||
((AppPrefs) o).ignoreAllUpdates == ignoreAllUpdates &&
|
||||
((AppPrefs) o).ignoreThisUpdate == ignoreThisUpdate;
|
||||
((AppPrefs) o).ignoreThisUpdate == ignoreThisUpdate &&
|
||||
((AppPrefs) o).ignoreVulnerabilities == ignoreVulnerabilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return (ignoreThisUpdate + "-" + ignoreAllUpdates).hashCode();
|
||||
return (ignoreThisUpdate + "-" + ignoreAllUpdates + "-" + ignoreVulnerabilities).hashCode();
|
||||
}
|
||||
|
||||
public AppPrefs createClone() {
|
||||
return new AppPrefs(ignoreThisUpdate, ignoreAllUpdates);
|
||||
return new AppPrefs(ignoreThisUpdate, ignoreAllUpdates, ignoreVulnerabilities);
|
||||
}
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ public class AppPrefsProvider extends FDroidProvider {
|
||||
ContentValues values = new ContentValues(3);
|
||||
values.put(Cols.IGNORE_ALL_UPDATES, prefs.ignoreAllUpdates);
|
||||
values.put(Cols.IGNORE_THIS_UPDATE, prefs.ignoreThisUpdate);
|
||||
values.put(Cols.IGNORE_VULNERABILITIES, prefs.ignoreVulnerabilities);
|
||||
|
||||
if (getPrefsOrNull(context, app) == null) {
|
||||
values.put(Cols.PACKAGE_NAME, app.packageName);
|
||||
@ -51,7 +52,8 @@ public class AppPrefsProvider extends FDroidProvider {
|
||||
cursor.moveToFirst();
|
||||
return new AppPrefs(
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_THIS_UPDATE)),
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_ALL_UPDATES)) > 0);
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_ALL_UPDATES)) > 0,
|
||||
cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_VULNERABILITIES)) > 0);
|
||||
} finally {
|
||||
cursor.close();
|
||||
}
|
||||
|
@ -158,8 +158,9 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
private static final String CREATE_TABLE_APP_PREFS = "CREATE TABLE " + AppPrefsTable.NAME
|
||||
+ " ( "
|
||||
+ AppPrefsTable.Cols.PACKAGE_NAME + " TEXT, "
|
||||
+ AppPrefsTable.Cols.IGNORE_THIS_UPDATE + " INT BOOLEAN NOT NULL, "
|
||||
+ AppPrefsTable.Cols.IGNORE_ALL_UPDATES + " INT NOT NULL "
|
||||
+ AppPrefsTable.Cols.IGNORE_THIS_UPDATE + " INT NOT NULL, "
|
||||
+ AppPrefsTable.Cols.IGNORE_ALL_UPDATES + " INT BOOLEAN NOT NULL, "
|
||||
+ AppPrefsTable.Cols.IGNORE_VULNERABILITIES + " INT BOOLEAN NOT NULL "
|
||||
+ " );";
|
||||
|
||||
private static final String CREATE_TABLE_CATEGORY = "CREATE TABLE " + Schema.CategoryTable.NAME
|
||||
@ -299,6 +300,18 @@ class DBHelper extends SQLiteOpenHelper {
|
||||
updatePreferredSignerIfEmpty(db, oldVersion);
|
||||
addIsAppToApp(db, oldVersion);
|
||||
addApkAntiFeatures(db, oldVersion);
|
||||
addIgnoreVulnPref(db, oldVersion);
|
||||
}
|
||||
|
||||
private void addIgnoreVulnPref(SQLiteDatabase db, int oldVersion) {
|
||||
if (oldVersion >= 74) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!columnExists(db, AppPrefsTable.NAME, AppPrefsTable.Cols.IGNORE_VULNERABILITIES)) {
|
||||
Utils.debugLog(TAG, "Adding " + AppPrefsTable.Cols.IGNORE_VULNERABILITIES + " field to " + AppPrefsTable.NAME + " table in db.");
|
||||
db.execSQL("alter table " + AppPrefsTable.NAME + " add column " + AppPrefsTable.Cols.IGNORE_VULNERABILITIES + " boolean;");
|
||||
}
|
||||
}
|
||||
|
||||
private void addApkAntiFeatures(SQLiteDatabase db, int oldVersion) {
|
||||
|
@ -54,8 +54,9 @@ public interface Schema {
|
||||
|
||||
String IGNORE_ALL_UPDATES = "ignoreAllUpdates";
|
||||
String IGNORE_THIS_UPDATE = "ignoreThisUpdate";
|
||||
String IGNORE_VULNERABILITIES = "ignoreVulnerabilities";
|
||||
|
||||
String[] ALL = {PACKAGE_NAME, IGNORE_ALL_UPDATES, IGNORE_THIS_UPDATE};
|
||||
String[] ALL = {PACKAGE_NAME, IGNORE_ALL_UPDATES, IGNORE_THIS_UPDATE, IGNORE_VULNERABILITIES};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,16 +28,19 @@ public class AppPrefsProviderTest extends FDroidProviderTest {
|
||||
@SuppressWarnings({"PMD.EqualsNull", "EqualsWithItself", "EqualsBetweenInconvertibleTypes", "ObjectEqualsNull"})
|
||||
@Test
|
||||
public void prefEquality() {
|
||||
AppPrefs original = new AppPrefs(101, true);
|
||||
AppPrefs original = new AppPrefs(101, true, true);
|
||||
|
||||
assertTrue(original.equals(new AppPrefs(101, true)));
|
||||
assertTrue(original.equals(new AppPrefs(101, true, true)));
|
||||
assertTrue(original.equals(original));
|
||||
|
||||
assertFalse(original.equals(null));
|
||||
assertFalse(original.equals("String"));
|
||||
assertFalse(original.equals(new AppPrefs(102, true)));
|
||||
assertFalse(original.equals(new AppPrefs(101, false)));
|
||||
assertFalse(original.equals(new AppPrefs(100, false)));
|
||||
assertFalse(original.equals(new AppPrefs(102, true, true)));
|
||||
assertFalse(original.equals(new AppPrefs(101, false, true)));
|
||||
assertFalse(original.equals(new AppPrefs(100, false, true)));
|
||||
assertFalse(original.equals(new AppPrefs(102, true, false)));
|
||||
assertFalse(original.equals(new AppPrefs(101, false, false)));
|
||||
assertFalse(original.equals(new AppPrefs(100, false, false)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -51,16 +54,19 @@ public class AppPrefsProviderTest extends FDroidProviderTest {
|
||||
AppPrefs defaultPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||
assertEquals(0, defaultPrefs.ignoreThisUpdate);
|
||||
assertFalse(defaultPrefs.ignoreAllUpdates);
|
||||
assertFalse(defaultPrefs.ignoreVulnerabilities);
|
||||
|
||||
AppPrefsProvider.Helper.update(context, withPrefs, new AppPrefs(12, false));
|
||||
AppPrefsProvider.Helper.update(context, withPrefs, new AppPrefs(12, false, false));
|
||||
AppPrefs newPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||
assertEquals(12, newPrefs.ignoreThisUpdate);
|
||||
assertFalse(newPrefs.ignoreAllUpdates);
|
||||
assertFalse(newPrefs.ignoreVulnerabilities);
|
||||
|
||||
AppPrefsProvider.Helper.update(context, withPrefs, new AppPrefs(14, true));
|
||||
AppPrefsProvider.Helper.update(context, withPrefs, new AppPrefs(14, true, true));
|
||||
AppPrefs evenNewerPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||
assertEquals(14, evenNewerPrefs.ignoreThisUpdate);
|
||||
assertTrue(evenNewerPrefs.ignoreAllUpdates);
|
||||
assertTrue(evenNewerPrefs.ignoreVulnerabilities);
|
||||
|
||||
assertNull(AppPrefsProvider.Helper.getPrefsOrNull(context, withoutPrefs));
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ public class AppProviderTest extends FDroidProviderTest {
|
||||
String packageName, int installedVercode, int suggestedVercode,
|
||||
boolean ignoreAll, int ignoreVercode) {
|
||||
App app = insertApp(contentResolver, context, packageName, "App: " + packageName, new ContentValues());
|
||||
AppPrefsProvider.Helper.update(context, app, new AppPrefs(ignoreVercode, ignoreAll));
|
||||
AppPrefsProvider.Helper.update(context, app, new AppPrefs(ignoreVercode, ignoreAll, false));
|
||||
|
||||
ContentValues certValue = new ContentValues(1);
|
||||
certValue.put(Schema.ApkTable.Cols.SIGNATURE, TestUtils.FDROID_SIG);
|
||||
|
Loading…
x
Reference in New Issue
Block a user