Added anti-feature table + join onto apk.

Not used yet, but will be used soon for known vulnerability anti
features.
This commit is contained in:
Peter Serwylo 2017-07-04 15:36:26 +10:00
parent 5d17676a01
commit caa1ead689
3 changed files with 87 additions and 13 deletions

View File

@ -241,7 +241,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
case Cols.Repo.ADDRESS:
repoAddress = cursor.getString(i);
break;
case Cols.ANTI_FEATURES:
case Cols.AntiFeatures.ANTI_FEATURES:
antiFeatures = Utils.parseCommaSeparatedString(cursor.getString(i));
break;
}
@ -348,7 +348,7 @@ public class Apk extends ValueObject implements Comparable<Apk>, Parcelable {
values.put(Cols.FEATURES, Utils.serializeCommaSeparatedString(features));
values.put(Cols.NATIVE_CODE, Utils.serializeCommaSeparatedString(nativecode));
values.put(Cols.INCOMPATIBLE_REASONS, Utils.serializeCommaSeparatedString(incompatibleReasons));
values.put(Cols.ANTI_FEATURES, Utils.serializeCommaSeparatedString(antiFeatures));
values.put(Cols.AntiFeatures.ANTI_FEATURES, Utils.serializeCommaSeparatedString(antiFeatures));
values.put(Cols.IS_COMPATIBLE, compatible ? 1 : 0);
return values;
}

View File

@ -34,6 +34,8 @@ import android.util.Log;
import org.fdroid.fdroid.R;
import org.fdroid.fdroid.Utils;
import org.fdroid.fdroid.data.Schema.AntiFeatureTable;
import org.fdroid.fdroid.data.Schema.ApkAntiFeatureJoinTable;
import org.fdroid.fdroid.data.Schema.ApkTable;
import org.fdroid.fdroid.data.Schema.CatJoinTable;
import org.fdroid.fdroid.data.Schema.PackageTable;
@ -107,8 +109,7 @@ class DBHelper extends SQLiteOpenHelper {
+ ApkTable.Cols.HASH_TYPE + " string, "
+ ApkTable.Cols.ADDED_DATE + " string, "
+ ApkTable.Cols.IS_COMPATIBLE + " int not null, "
+ ApkTable.Cols.INCOMPATIBLE_REASONS + " text, "
+ ApkTable.Cols.ANTI_FEATURES + " string"
+ ApkTable.Cols.INCOMPATIBLE_REASONS + " text"
+ ");";
static final String CREATE_TABLE_APP_METADATA = "CREATE TABLE " + AppMetadataTable.NAME
@ -194,7 +195,19 @@ class DBHelper extends SQLiteOpenHelper {
+ InstalledAppTable.Cols.HASH + " TEXT NOT NULL"
+ " );";
protected static final int DB_VERSION = 74;
private static final String CREATE_TABLE_ANTI_FEATURE = "CREATE TABLE " + AntiFeatureTable.NAME
+ " ( "
+ AntiFeatureTable.Cols.NAME + " TEXT NOT NULL "
+ " );";
private static final String CREATE_TABLE_APK_ANTI_FEATURE_JOIN = "CREATE TABLE " + ApkAntiFeatureJoinTable.NAME
+ " ( "
+ ApkAntiFeatureJoinTable.Cols.APK_ID + " INT NOT NULL, "
+ ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + " INT NOT NULL, "
+ "primary key(" + ApkAntiFeatureJoinTable.Cols.APK_ID + ", " + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + ") "
+ " );";
protected static final int DB_VERSION = 75;
private final Context context;
@ -214,6 +227,8 @@ class DBHelper extends SQLiteOpenHelper {
db.execSQL(CREATE_TABLE_INSTALLED_APP);
db.execSQL(CREATE_TABLE_REPO);
db.execSQL(CREATE_TABLE_APP_PREFS);
db.execSQL(CREATE_TABLE_ANTI_FEATURE);
db.execSQL(CREATE_TABLE_APK_ANTI_FEATURE_JOIN);
ensureIndexes(db);
String[] defaultRepos = context.getResources().getStringArray(R.array.default_repos);
@ -283,6 +298,16 @@ class DBHelper extends SQLiteOpenHelper {
addPreferredSignerToApp(db, oldVersion);
updatePreferredSignerIfEmpty(db, oldVersion);
addIsAppToApp(db, oldVersion);
addApkAntiFeatures(db, oldVersion);
}
private void addApkAntiFeatures(SQLiteDatabase db, int oldVersion) {
if (oldVersion >= 74) {
return;
}
Log.i(TAG, "Adding anti features on a per-apk basis.");
resetTransient(db);
}
private void addIsAppToApp(SQLiteDatabase db, int oldVersion) {
@ -436,11 +461,6 @@ class DBHelper extends SQLiteOpenHelper {
Utils.debugLog(TAG, "Adding " + RepoTable.Cols.MIRRORS + " field to " + RepoTable.NAME + " table in db.");
db.execSQL("alter table " + RepoTable.NAME + " add column " + RepoTable.Cols.MIRRORS + " string;");
}
if (!columnExists(db, ApkTable.NAME, ApkTable.Cols.ANTI_FEATURES)) {
Utils.debugLog(TAG, "Adding " + ApkTable.Cols.ANTI_FEATURES + " field to " + ApkTable.NAME + " table in db.");
db.execSQL("alter table " + ApkTable.NAME + " add column " + ApkTable.Cols.ANTI_FEATURES + " string;");
}
}
/**
@ -1059,6 +1079,14 @@ class DBHelper extends SQLiteOpenHelper {
db.execSQL("DROP TABLE " + PackageTable.NAME);
}
if (tableExists(db, AntiFeatureTable.NAME)) {
db.execSQL("DROP TABLE " + AntiFeatureTable.NAME);
}
if (tableExists(db, ApkAntiFeatureJoinTable.NAME)) {
db.execSQL("DROP TABLE " + ApkAntiFeatureJoinTable.NAME);
}
db.execSQL("DROP TABLE " + AppMetadataTable.NAME);
db.execSQL("DROP TABLE " + ApkTable.NAME);
@ -1067,6 +1095,8 @@ class DBHelper extends SQLiteOpenHelper {
db.execSQL(CREATE_TABLE_APK);
db.execSQL(CREATE_TABLE_CATEGORY);
db.execSQL(CREATE_TABLE_CAT_JOIN);
db.execSQL(CREATE_TABLE_ANTI_FEATURE);
db.execSQL(CREATE_TABLE_APK_ANTI_FEATURE_JOIN);
clearRepoEtags(db);
ensureIndexes(db);
db.setTransactionSuccessful();

View File

@ -106,6 +106,47 @@ public interface Schema {
}
}
interface AntiFeatureTable {
String NAME = "fdroid_antiFeature";
interface Cols {
String ROW_ID = "rowid";
String NAME = "name";
String[] ALL = {ROW_ID, NAME};
}
}
/**
* An entry in this table signifies that an apk has a particular anti feature.
* @see AntiFeatureTable
* @see ApkTable
*/
interface ApkAntiFeatureJoinTable {
String NAME = "fdroid_apkAntiFeatureJoin";
interface Cols {
/**
* Foreign key to {@link ApkTable}.
* @see ApkTable
*/
String APK_ID = "apkId";
/**
* Foreign key to {@link AntiFeatureTable}.
* @see AntiFeatureTable
*/
String ANTI_FEATURE_ID = "antiFeatureId";
/**
* @see AppMetadataTable.Cols#ALL_COLS
*/
String[] ALL_COLS = {APK_ID, ANTI_FEATURE_ID};
}
}
interface AppMetadataTable {
String NAME = "fdroid_app";
@ -258,7 +299,6 @@ public interface Schema {
String ADDED_DATE = "added";
String IS_COMPATIBLE = "compatible";
String INCOMPATIBLE_REASONS = "incompatibleReasons";
String ANTI_FEATURES = "antiFeatures";
interface Repo {
String VERSION = "repoVersion";
@ -269,6 +309,10 @@ public interface Schema {
String PACKAGE_NAME = "package_packageName";
}
interface AntiFeatures {
String ANTI_FEATURES = "antiFeatures_commaSeparated";
}
/**
* @see AppMetadataTable.Cols#ALL_COLS
*/
@ -277,7 +321,7 @@ public interface Schema {
SIZE, SIGNATURE, SOURCE_NAME, MIN_SDK_VERSION, TARGET_SDK_VERSION, MAX_SDK_VERSION,
OBB_MAIN_FILE, OBB_MAIN_FILE_SHA256, OBB_PATCH_FILE, OBB_PATCH_FILE_SHA256,
REQUESTED_PERMISSIONS, FEATURES, NATIVE_CODE, HASH_TYPE, ADDED_DATE,
IS_COMPATIBLE, INCOMPATIBLE_REASONS, ANTI_FEATURES,
IS_COMPATIBLE, INCOMPATIBLE_REASONS,
};
/**
@ -289,7 +333,7 @@ public interface Schema {
OBB_MAIN_FILE, OBB_MAIN_FILE_SHA256, OBB_PATCH_FILE, OBB_PATCH_FILE_SHA256,
REQUESTED_PERMISSIONS, FEATURES, NATIVE_CODE, HASH_TYPE, ADDED_DATE,
IS_COMPATIBLE, Repo.VERSION, Repo.ADDRESS, INCOMPATIBLE_REASONS,
ANTI_FEATURES,
AntiFeatures.ANTI_FEATURES,
};
}
}