Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
c1423ca9
Commit
c1423ca9
authored
Feb 18, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix F2FS crashes on SQLite 3.21.0
parent
74379150
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
42 deletions
+57
-42
SuDatabaseHelper.java
.../java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
+43
-38
Utils.java
src/main/java/com/topjohnwu/magisk/utils/Utils.java
+0
-1
sudb.sh
src/main/res/raw/sudb.sh
+14
-3
No files found.
src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
View file @
c1423ca9
...
@@ -7,6 +7,7 @@ import android.database.Cursor;
...
@@ -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;
...
@@ -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 {
...
@@ -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 {
...
@@ -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 {
...
@@ -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,7 +116,6 @@ public class SuDatabaseHelper {
...
@@ -106,7 +116,6 @@ 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
;
...
@@ -139,10 +148,6 @@ public class SuDatabaseHelper {
...
@@ -139,10 +148,6 @@ public class SuDatabaseHelper {
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
);
}
}
}
// Remove everything, we do not support downgrade
// Remove everything, we do not support downgrade
...
...
src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
c1423ca9
...
@@ -27,7 +27,6 @@ import com.topjohnwu.magisk.MagiskManager;
...
@@ -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
;
...
...
src/main/res/raw/sudb.sh
View file @
c1423ca9
...
@@ -3,17 +3,28 @@ sudb_clean() {
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment