Support new module specification

This commit is contained in:
topjohnwu 2017-11-17 23:34:38 +08:00
parent 1a32aaea6f
commit 97bf388471
5 changed files with 30 additions and 25 deletions

View File

@ -10,7 +10,7 @@ import java.util.List;
public abstract class BaseModule implements Comparable<BaseModule> { public abstract class BaseModule implements Comparable<BaseModule> {
private String mId = null, mName, mVersion, mAuthor, mDescription; private String mId = null, mName, mVersion, mAuthor, mDescription;
private int mVersionCode = -1, templateVersion = -1; private int mVersionCode = -1, minMagiskVersion = -1;
protected BaseModule() {} protected BaseModule() {}
@ -21,7 +21,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
mVersionCode = c.getInt(c.getColumnIndex("versionCode")); mVersionCode = c.getInt(c.getColumnIndex("versionCode"));
mAuthor = c.getString(c.getColumnIndex("author")); mAuthor = c.getString(c.getColumnIndex("author"));
mDescription = c.getString(c.getColumnIndex("description")); mDescription = c.getString(c.getColumnIndex("description"));
templateVersion = c.getInt(c.getColumnIndex("template")); minMagiskVersion = c.getInt(c.getColumnIndex("minMagisk"));
} }
public ContentValues getContentValues() { public ContentValues getContentValues() {
@ -32,7 +32,7 @@ public abstract class BaseModule implements Comparable<BaseModule> {
values.put("versionCode", mVersionCode); values.put("versionCode", mVersionCode);
values.put("author", mAuthor); values.put("author", mAuthor);
values.put("description", mDescription); values.put("description", mDescription);
values.put("template", templateVersion); values.put("minMagisk", minMagiskVersion);
return values; return values;
} }
@ -67,8 +67,9 @@ public abstract class BaseModule implements Comparable<BaseModule> {
case "description": case "description":
mDescription = prop[1]; mDescription = prop[1];
break; break;
case "minMagisk":
case "template": case "template":
templateVersion = Integer.parseInt(prop[1]); minMagiskVersion = Integer.parseInt(prop[1]);
break; break;
default: default:
break; break;
@ -108,8 +109,8 @@ public abstract class BaseModule implements Comparable<BaseModule> {
return mVersionCode; return mVersionCode;
} }
public int getTemplateVersion() { public int getMinMagiskVersion() {
return templateVersion; return minMagiskVersion;
} }
@Override @Override

View File

@ -40,7 +40,7 @@ public class Repo extends BaseModule {
if (getVersionCode() < 0) { if (getVersionCode() < 0) {
throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode"); throw new IllegalRepoException("Repo [" + repoName + "] does not contain versionCode");
} }
if (getTemplateVersion() < Const.Value.MIN_TEMPLATE_VER) { if (getMinMagiskVersion() < Const.Value.MIN_MODULE_VER) {
throw new IllegalRepoException("Repo [" + repoName + "] is outdated"); throw new IllegalRepoException("Repo [" + repoName + "] is outdated");
} }
} }
@ -54,6 +54,7 @@ public class Repo extends BaseModule {
return false; return false;
} }
@Override
public ContentValues getContentValues() { public ContentValues getContentValues() {
ContentValues values = super.getContentValues(); ContentValues values = super.getContentValues();
values.put("repo_name", repoName); values.put("repo_name", repoName);

View File

@ -15,7 +15,7 @@ import java.util.List;
public class RepoDatabaseHelper extends SQLiteOpenHelper { public class RepoDatabaseHelper extends SQLiteOpenHelper {
private static final int DATABASE_VER = 2; private static final int DATABASE_VER = 3;
private static final String TABLE_NAME = "repos"; private static final String TABLE_NAME = "repos";
private SQLiteDatabase mDb; private SQLiteDatabase mDb;
@ -23,12 +23,12 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
public RepoDatabaseHelper(Context context) { public RepoDatabaseHelper(Context context) {
super(context, "repo.db", null, DATABASE_VER); super(context, "repo.db", null, DATABASE_VER);
mDb = getWritableDatabase();
mm = Utils.getMagiskManager(context); mm = Utils.getMagiskManager(context);
mDb = getWritableDatabase();
// Clear bad repos // Clear bad repos
mDb.delete(TABLE_NAME, "template<?", mDb.delete(TABLE_NAME, "minMagisk<?",
new String[] { String.valueOf(Const.Value.MIN_TEMPLATE_VER) }); new String[] { String.valueOf(Const.Value.MIN_MODULE_VER) });
} }
@Override @Override
@ -38,20 +38,23 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
@Override @Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion == 0) { if (oldVersion < 3) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
db.execSQL( db.execSQL(
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " + "CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " +
"(id TEXT, name TEXT, version TEXT, versionCode INT, " + "(id TEXT, name TEXT, version TEXT, versionCode INT, minMagisk INT, " +
"author TEXT, description TEXT, repo_name TEXT, last_update INT, " + "author TEXT, description TEXT, repo_name TEXT, last_update INT, " +
"PRIMARY KEY(id))"); "PRIMARY KEY(id))");
oldVersion++; mm.prefs.edit().remove(Const.Key.ETAG_KEY).apply();
} oldVersion = 3;
if (oldVersion == 1) {
db.execSQL("ALTER TABLE " + TABLE_NAME + " ADD template INT");
oldVersion++;
} }
} }
@Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, 0, DATABASE_VER);
}
public void clearRepo() { public void clearRepo() {
mDb.delete(TABLE_NAME, null, null); mDb.delete(TABLE_NAME, null, null);
} }
@ -86,7 +89,7 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
} }
public Cursor getRepoCursor() { public Cursor getRepoCursor() {
return mDb.query(TABLE_NAME, null, "template<=?", return mDb.query(TABLE_NAME, null, "minMagisk<=?",
new String[] { String.valueOf(mm.magiskVersionCode) }, new String[] { String.valueOf(mm.magiskVersionCode) },
null, null, "name COLLATE NOCASE"); null, null, "name COLLATE NOCASE");
} }

View File

@ -163,10 +163,11 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
@Override @Override
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Remove everything, we do not support downgrade // Remove everything, we do not support downgrade
db.delete(POLICY_TABLE, null, null); db.execSQL("DROP TABLE IF EXISTS " + POLICY_TABLE);
db.delete(LOG_TABLE, null, null); db.execSQL("DROP TABLE IF EXISTS " + LOG_TABLE);
db.delete(SETTINGS_TABLE, null, null); db.execSQL("DROP TABLE IF EXISTS " + SETTINGS_TABLE);
db.delete(STRINGS_TABLE, null, null); db.execSQL("DROP TABLE IF EXISTS " + STRINGS_TABLE);
onUpgrade(db, 0, DATABASE_VER);
} }
public File getDbFile() { public File getDbFile() {

View File

@ -9,7 +9,6 @@ public class Const {
public static final String ORIG_PKG_NAME = "com.topjohnwu.magisk"; public static final String ORIG_PKG_NAME = "com.topjohnwu.magisk";
public static final String SNET_PKG = "com.topjohnwu.snet"; public static final String SNET_PKG = "com.topjohnwu.snet";
public static final String MAGISKHIDE_PROP = "persist.magisk.hide"; public static final String MAGISKHIDE_PROP = "persist.magisk.hide";
public static final String DISABLE_INDICATION_PROP = "ro.magisk.disable";
// APK content // APK content
public static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem"; public static final String PUBLIC_KEY_NAME = "public.certificate.x509.pem";
@ -142,6 +141,6 @@ public class Const {
public static final int[] timeoutList = {0, -1, 10, 20, 30, 60}; public static final int[] timeoutList = {0, -1, 10, 20, 30, 60};
public static final int UPDATE_SERVICE_VER = 1; public static final int UPDATE_SERVICE_VER = 1;
public static final int SNET_VER = 3; public static final int SNET_VER = 3;
public static final int MIN_TEMPLATE_VER = 4; public static final int MIN_MODULE_VER = 1400;
} }
} }