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 {
|
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;
|
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 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;
|
ignoreThisUpdate = ignoreThis;
|
||||||
ignoreAllUpdates = ignoreAll;
|
ignoreAllUpdates = ignoreAll;
|
||||||
|
ignoreVulnerabilities = ignoreVulns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AppPrefs createDefault() {
|
public static AppPrefs createDefault() {
|
||||||
return new AppPrefs(0, false);
|
return new AppPrefs(0, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
return o != null && o instanceof AppPrefs &&
|
return o != null && o instanceof AppPrefs &&
|
||||||
((AppPrefs) o).ignoreAllUpdates == ignoreAllUpdates &&
|
((AppPrefs) o).ignoreAllUpdates == ignoreAllUpdates &&
|
||||||
((AppPrefs) o).ignoreThisUpdate == ignoreThisUpdate;
|
((AppPrefs) o).ignoreThisUpdate == ignoreThisUpdate &&
|
||||||
|
((AppPrefs) o).ignoreVulnerabilities == ignoreVulnerabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (ignoreThisUpdate + "-" + ignoreAllUpdates).hashCode();
|
return (ignoreThisUpdate + "-" + ignoreAllUpdates + "-" + ignoreVulnerabilities).hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public AppPrefs createClone() {
|
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);
|
ContentValues values = new ContentValues(3);
|
||||||
values.put(Cols.IGNORE_ALL_UPDATES, prefs.ignoreAllUpdates);
|
values.put(Cols.IGNORE_ALL_UPDATES, prefs.ignoreAllUpdates);
|
||||||
values.put(Cols.IGNORE_THIS_UPDATE, prefs.ignoreThisUpdate);
|
values.put(Cols.IGNORE_THIS_UPDATE, prefs.ignoreThisUpdate);
|
||||||
|
values.put(Cols.IGNORE_VULNERABILITIES, prefs.ignoreVulnerabilities);
|
||||||
|
|
||||||
if (getPrefsOrNull(context, app) == null) {
|
if (getPrefsOrNull(context, app) == null) {
|
||||||
values.put(Cols.PACKAGE_NAME, app.packageName);
|
values.put(Cols.PACKAGE_NAME, app.packageName);
|
||||||
@ -51,7 +52,8 @@ public class AppPrefsProvider extends FDroidProvider {
|
|||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
return new AppPrefs(
|
return new AppPrefs(
|
||||||
cursor.getInt(cursor.getColumnIndexOrThrow(Cols.IGNORE_THIS_UPDATE)),
|
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 {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
@ -158,8 +158,9 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
private static final String CREATE_TABLE_APP_PREFS = "CREATE TABLE " + AppPrefsTable.NAME
|
private static final String CREATE_TABLE_APP_PREFS = "CREATE TABLE " + AppPrefsTable.NAME
|
||||||
+ " ( "
|
+ " ( "
|
||||||
+ AppPrefsTable.Cols.PACKAGE_NAME + " TEXT, "
|
+ AppPrefsTable.Cols.PACKAGE_NAME + " TEXT, "
|
||||||
+ AppPrefsTable.Cols.IGNORE_THIS_UPDATE + " INT BOOLEAN NOT NULL, "
|
+ AppPrefsTable.Cols.IGNORE_THIS_UPDATE + " INT NOT NULL, "
|
||||||
+ AppPrefsTable.Cols.IGNORE_ALL_UPDATES + " 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
|
private static final String CREATE_TABLE_CATEGORY = "CREATE TABLE " + Schema.CategoryTable.NAME
|
||||||
@ -299,6 +300,18 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
updatePreferredSignerIfEmpty(db, oldVersion);
|
updatePreferredSignerIfEmpty(db, oldVersion);
|
||||||
addIsAppToApp(db, oldVersion);
|
addIsAppToApp(db, oldVersion);
|
||||||
addApkAntiFeatures(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) {
|
private void addApkAntiFeatures(SQLiteDatabase db, int oldVersion) {
|
||||||
|
@ -54,8 +54,9 @@ public interface Schema {
|
|||||||
|
|
||||||
String IGNORE_ALL_UPDATES = "ignoreAllUpdates";
|
String IGNORE_ALL_UPDATES = "ignoreAllUpdates";
|
||||||
String IGNORE_THIS_UPDATE = "ignoreThisUpdate";
|
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"})
|
@SuppressWarnings({"PMD.EqualsNull", "EqualsWithItself", "EqualsBetweenInconvertibleTypes", "ObjectEqualsNull"})
|
||||||
@Test
|
@Test
|
||||||
public void prefEquality() {
|
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));
|
assertTrue(original.equals(original));
|
||||||
|
|
||||||
assertFalse(original.equals(null));
|
assertFalse(original.equals(null));
|
||||||
assertFalse(original.equals("String"));
|
assertFalse(original.equals("String"));
|
||||||
assertFalse(original.equals(new AppPrefs(102, true)));
|
assertFalse(original.equals(new AppPrefs(102, true, true)));
|
||||||
assertFalse(original.equals(new AppPrefs(101, false)));
|
assertFalse(original.equals(new AppPrefs(101, false, true)));
|
||||||
assertFalse(original.equals(new AppPrefs(100, false)));
|
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
|
@Test
|
||||||
@ -51,16 +54,19 @@ public class AppPrefsProviderTest extends FDroidProviderTest {
|
|||||||
AppPrefs defaultPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
AppPrefs defaultPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||||
assertEquals(0, defaultPrefs.ignoreThisUpdate);
|
assertEquals(0, defaultPrefs.ignoreThisUpdate);
|
||||||
assertFalse(defaultPrefs.ignoreAllUpdates);
|
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);
|
AppPrefs newPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||||
assertEquals(12, newPrefs.ignoreThisUpdate);
|
assertEquals(12, newPrefs.ignoreThisUpdate);
|
||||||
assertFalse(newPrefs.ignoreAllUpdates);
|
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);
|
AppPrefs evenNewerPrefs = AppPrefsProvider.Helper.getPrefsOrDefault(context, withPrefs);
|
||||||
assertEquals(14, evenNewerPrefs.ignoreThisUpdate);
|
assertEquals(14, evenNewerPrefs.ignoreThisUpdate);
|
||||||
assertTrue(evenNewerPrefs.ignoreAllUpdates);
|
assertTrue(evenNewerPrefs.ignoreAllUpdates);
|
||||||
|
assertTrue(evenNewerPrefs.ignoreVulnerabilities);
|
||||||
|
|
||||||
assertNull(AppPrefsProvider.Helper.getPrefsOrNull(context, withoutPrefs));
|
assertNull(AppPrefsProvider.Helper.getPrefsOrNull(context, withoutPrefs));
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ public class AppProviderTest extends FDroidProviderTest {
|
|||||||
String packageName, int installedVercode, int suggestedVercode,
|
String packageName, int installedVercode, int suggestedVercode,
|
||||||
boolean ignoreAll, int ignoreVercode) {
|
boolean ignoreAll, int ignoreVercode) {
|
||||||
App app = insertApp(contentResolver, context, packageName, "App: " + packageName, new ContentValues());
|
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);
|
ContentValues certValue = new ContentValues(1);
|
||||||
certValue.put(Schema.ApkTable.Cols.SIGNATURE, TestUtils.FDROID_SIG);
|
certValue.put(Schema.ApkTable.Cols.SIGNATURE, TestUtils.FDROID_SIG);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user