From ff3dad245721c7d01f2c4772c700dafbc6ba9ef9 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Sat, 1 Sep 2018 10:46:13 -0400 Subject: [PATCH] Prevent upgrading database before upgrading to v17.0 --- app/src/full/java/com/topjohnwu/magisk/Const.java | 1 + .../magisk/database/MagiskDatabaseHelper.java | 13 ++++++++----- app/src/full/res/raw/changelog.md | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/Const.java b/app/src/full/java/com/topjohnwu/magisk/Const.java index 38bab71bc327..fe49b1d8e94e 100644 --- a/app/src/full/java/com/topjohnwu/magisk/Const.java +++ b/app/src/full/java/com/topjohnwu/magisk/Const.java @@ -57,6 +57,7 @@ public static final class MAGISK_VER { public static final int REMOVE_LEGACY_LINK = 1630; public static final int SEPOL_REFACTOR = 1640; public static final int FIX_ENV = 1650; + public static final int DBVER_SIX = 17000; } public static class ID { diff --git a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java index 60f62e436d33..be224c2ba379 100644 --- a/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java +++ b/app/src/full/java/com/topjohnwu/magisk/database/MagiskDatabaseHelper.java @@ -32,6 +32,7 @@ public class MagiskDatabaseHelper { private static final int DATABASE_VER = 6; + private static final int OLD_DATABASE_VER = 5; private static final String POLICY_TABLE = "policies"; private static final String LOG_TABLE = "logs"; private static final String SETTINGS_TABLE = "settings"; @@ -57,13 +58,15 @@ private MagiskDatabaseHelper(MagiskManager context) { pm = mm.getPackageManager(); db = openDatabase(mm); db.disableWriteAheadLogging(); - int version = db.getVersion(); - if (version < DATABASE_VER) { - onUpgrade(db, version); - } else if (version > DATABASE_VER) { + int version = Data.magiskVersionCode >= Const.MAGISK_VER.DBVER_SIX ? DATABASE_VER : OLD_DATABASE_VER; + int curVersion = db.getVersion(); + if (curVersion < version) { + onUpgrade(db, curVersion); + } else if (curVersion > DATABASE_VER) { + /* Higher than we can possibly support */ onDowngrade(db); } - db.setVersion(DATABASE_VER); + db.setVersion(version); clearOutdated(); } diff --git a/app/src/full/res/raw/changelog.md b/app/src/full/res/raw/changelog.md index 152707411eb9..b826b26e627c 100644 --- a/app/src/full/res/raw/changelog.md +++ b/app/src/full/res/raw/changelog.md @@ -1,3 +1,6 @@ +### 5.9.1 +- Prevent upgrading database before upgrading to v17.0 + ### v5.9.0 - No more on boot notifications - Support new mechanism for installing to inactive slot for OTAs on A/B devices