mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-28 04:25:27 +00:00
Fix F2FS crashes on SQLite 3.21.0
This commit is contained in:
parent
74379150a1
commit
c1423ca9ad
@ -7,6 +7,7 @@ import android.database.Cursor;
|
|||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Process;
|
import android.os.Process;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ import com.topjohnwu.magisk.container.SuLogEntry;
|
|||||||
import com.topjohnwu.magisk.utils.Const;
|
import com.topjohnwu.magisk.utils.Const;
|
||||||
import com.topjohnwu.magisk.utils.Utils;
|
import com.topjohnwu.magisk.utils.Utils;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
|
import com.topjohnwu.superuser.io.SuFile;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
@ -37,6 +39,7 @@ public class SuDatabaseHelper {
|
|||||||
private SQLiteDatabase mDb;
|
private SQLiteDatabase mDb;
|
||||||
private File DB_FILE;
|
private File DB_FILE;
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public static SuDatabaseHelper getInstance(MagiskManager mm) {
|
public static SuDatabaseHelper getInstance(MagiskManager mm) {
|
||||||
try {
|
try {
|
||||||
return new SuDatabaseHelper(mm);
|
return new SuDatabaseHelper(mm);
|
||||||
@ -61,7 +64,7 @@ public class SuDatabaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private SQLiteDatabase openDatabase(MagiskManager mm) {
|
private SQLiteDatabase openDatabase(MagiskManager mm) {
|
||||||
String GLOBAL_DB = "/data/adb/magisk.db";
|
final SuFile GLOBAL_DB = new SuFile("/data/adb/magisk.db", true);
|
||||||
DB_FILE = new File(Utils.fmt("/sbin/.core/db-%d/magisk.db", Const.USER_ID));
|
DB_FILE = new File(Utils.fmt("/sbin/.core/db-%d/magisk.db", Const.USER_ID));
|
||||||
Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
Context de = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N
|
||||||
? mm.createDeviceProtectedStorageContext() : mm;
|
? mm.createDeviceProtectedStorageContext() : mm;
|
||||||
@ -89,16 +92,23 @@ public class SuDatabaseHelper {
|
|||||||
mm.deleteDatabase("su.db");
|
mm.deleteDatabase("su.db");
|
||||||
de.deleteDatabase("su.db");
|
de.deleteDatabase("su.db");
|
||||||
if (mm.magiskVersionCode < 1460) {
|
if (mm.magiskVersionCode < 1460) {
|
||||||
// v14.5 global DB location
|
// Link to new path
|
||||||
GLOBAL_DB = new File(de.getFilesDir().getParentFile().getParentFile(),
|
File oldDB = new File(de.getFilesDir().getParentFile().getParentFile(),
|
||||||
"magisk.db").getPath();
|
"magisk.db");
|
||||||
|
Shell.Sync.su(Utils.fmt("mv -f %s %s; ln -s %s %s",
|
||||||
|
oldDB, GLOBAL_DB, GLOBAL_DB, oldDB));
|
||||||
}
|
}
|
||||||
if (mm.magiskVersionCode < 1550) {
|
if (mm.magiskVersionCode < 1550) {
|
||||||
// We need some additional policies on old versions
|
// We need some additional policies on old versions
|
||||||
Shell.Sync.su("magiskpolicy --live " +
|
Shell.Sync.su("magiskpolicy --live " +
|
||||||
"'create su_file' 'allow * su_file file *' 'allow * su_file dir *'");
|
"'create su_file' 'allow * su_file file *' 'allow * su_file dir *'");
|
||||||
}
|
}
|
||||||
Shell.Sync.su("sudb_setup " + Process.myUid() + " " + GLOBAL_DB);
|
if (!GLOBAL_DB.exists()) {
|
||||||
|
Shell.Sync.su("sudb_init");
|
||||||
|
SQLiteDatabase.openOrCreateDatabase(GLOBAL_DB, null).close();
|
||||||
|
Shell.Sync.su("sudb_restore");
|
||||||
|
}
|
||||||
|
Shell.Sync.su("sudb_setup " + Process.myUid());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Not using legacy mode, open the mounted global DB
|
// Not using legacy mode, open the mounted global DB
|
||||||
@ -106,42 +116,37 @@ public class SuDatabaseHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion) {
|
public void onUpgrade(SQLiteDatabase db, int oldVersion) {
|
||||||
try {
|
if (oldVersion == 0) {
|
||||||
if (oldVersion == 0) {
|
createTables(db);
|
||||||
createTables(db);
|
oldVersion = 3;
|
||||||
oldVersion = 3;
|
}
|
||||||
}
|
if (oldVersion == 1) {
|
||||||
if (oldVersion == 1) {
|
// We're dropping column app_name, rename and re-construct table
|
||||||
// We're dropping column app_name, rename and re-construct table
|
db.execSQL(Utils.fmt("ALTER TABLE %s RENAME TO %s_old", POLICY_TABLE));
|
||||||
db.execSQL(Utils.fmt("ALTER TABLE %s RENAME TO %s_old", POLICY_TABLE));
|
|
||||||
|
|
||||||
// Create the new tables
|
// Create the new tables
|
||||||
createTables(db);
|
createTables(db);
|
||||||
|
|
||||||
// Migrate old data to new tables
|
// Migrate old data to new tables
|
||||||
db.execSQL(Utils.fmt("INSERT INTO %s SELECT " +
|
db.execSQL(Utils.fmt("INSERT INTO %s SELECT " +
|
||||||
"uid, package_name, policy, until, logging, notification FROM %s_old",
|
"uid, package_name, policy, until, logging, notification FROM %s_old",
|
||||||
POLICY_TABLE, POLICY_TABLE));
|
POLICY_TABLE, POLICY_TABLE));
|
||||||
db.execSQL(Utils.fmt("DROP TABLE %s_old", POLICY_TABLE));
|
db.execSQL(Utils.fmt("DROP TABLE %s_old", POLICY_TABLE));
|
||||||
|
|
||||||
MagiskManager.get().deleteDatabase("sulog.db");
|
MagiskManager.get().deleteDatabase("sulog.db");
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
}
|
||||||
if (oldVersion == 2) {
|
if (oldVersion == 2) {
|
||||||
db.execSQL(Utils.fmt("UPDATE %s SET time=time*1000", LOG_TABLE));
|
db.execSQL(Utils.fmt("UPDATE %s SET time=time*1000", LOG_TABLE));
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
}
|
||||||
if (oldVersion == 3) {
|
if (oldVersion == 3) {
|
||||||
db.execSQL(Utils.fmt("CREATE TABLE IF NOT EXISTS %s (key TEXT, value TEXT, PRIMARY KEY(key))", STRINGS_TABLE));
|
db.execSQL(Utils.fmt("CREATE TABLE IF NOT EXISTS %s (key TEXT, value TEXT, PRIMARY KEY(key))", STRINGS_TABLE));
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
}
|
||||||
if (oldVersion == 4) {
|
if (oldVersion == 4) {
|
||||||
db.execSQL(Utils.fmt("UPDATE %s SET uid=uid%%100000", POLICY_TABLE));
|
db.execSQL(Utils.fmt("UPDATE %s SET uid=uid%%100000", POLICY_TABLE));
|
||||||
++oldVersion;
|
++oldVersion;
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
onDowngrade(db);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import com.topjohnwu.magisk.MagiskManager;
|
|||||||
import com.topjohnwu.magisk.R;
|
import com.topjohnwu.magisk.R;
|
||||||
import com.topjohnwu.magisk.SplashActivity;
|
import com.topjohnwu.magisk.SplashActivity;
|
||||||
import com.topjohnwu.magisk.components.SnackbarMaker;
|
import com.topjohnwu.magisk.components.SnackbarMaker;
|
||||||
import com.topjohnwu.magisk.database.SuDatabaseHelper;
|
|
||||||
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
import com.topjohnwu.magisk.receivers.DownloadReceiver;
|
||||||
import com.topjohnwu.superuser.Shell;
|
import com.topjohnwu.superuser.Shell;
|
||||||
import com.topjohnwu.superuser.ShellUtils;
|
import com.topjohnwu.superuser.ShellUtils;
|
||||||
|
@ -3,17 +3,28 @@ sudb_clean() {
|
|||||||
local DIR="/sbin/.core/db-${USERID}"
|
local DIR="/sbin/.core/db-${USERID}"
|
||||||
umount -l /data/user*/*/*/databases/su.db $DIR $DIR/*
|
umount -l /data/user*/*/*/databases/su.db $DIR $DIR/*
|
||||||
rm -rf $DIR
|
rm -rf $DIR
|
||||||
|
[ "$USERID" = "*" ] && rm -f /data/adb/magisk.db
|
||||||
|
}
|
||||||
|
|
||||||
|
sudb_init() {
|
||||||
|
ADB_CONTEXT=`/system/bin/ls -dZ /data/adb | awk '{print $1}'`
|
||||||
|
chcon u:object_r:su_file:s0 /data/adb
|
||||||
|
chmod 777 /data/adb
|
||||||
|
}
|
||||||
|
|
||||||
|
sudb_restore() {
|
||||||
|
chcon $ADB_CONTEXT /data/adb
|
||||||
|
chmod 700 /data/adb
|
||||||
}
|
}
|
||||||
|
|
||||||
sudb_setup() {
|
sudb_setup() {
|
||||||
local USER=$1
|
local USER=$1
|
||||||
local GLOBAL_DB=$2
|
|
||||||
local USERID=$(($USER / 100000))
|
local USERID=$(($USER / 100000))
|
||||||
local DIR=/sbin/.core/db-${USERID}
|
local DIR=/sbin/.core/db-${USERID}
|
||||||
touch $GLOBAL_DB
|
|
||||||
mkdir -p $DIR
|
mkdir -p $DIR
|
||||||
touch $DIR/magisk.db
|
touch $DIR/magisk.db
|
||||||
mount -o bind $GLOBAL_DB $DIR/magisk.db
|
mount -o bind /data/adb/magisk.db $DIR/magisk.db
|
||||||
|
rm -f /data/adb/magisk.db-journal
|
||||||
chcon u:object_r:su_file:s0 $DIR $DIR/*
|
chcon u:object_r:su_file:s0 $DIR $DIR/*
|
||||||
chmod 700 $DIR
|
chmod 700 $DIR
|
||||||
chown $USER.$USER $DIR
|
chown $USER.$USER $DIR
|
||||||
|
Loading…
Reference in New Issue
Block a user