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
e518f4ce
Commit
e518f4ce
authored
Nov 17, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Crash proof database: reset if error occurs
parent
c8fd5da2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
50 deletions
+61
-50
RepoDatabaseHelper.java
...ava/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
+15
-9
SuDatabaseHelper.java
.../java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
+46
-41
No files found.
app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
View file @
e518f4ce
...
...
@@ -38,15 +38,21 @@ public class RepoDatabaseHelper extends SQLiteOpenHelper {
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
if
(
oldVersion
<
3
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
TABLE_NAME
);
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS "
+
TABLE_NAME
+
" "
+
"(id TEXT, name TEXT, version TEXT, versionCode INT, minMagisk INT, "
+
"author TEXT, description TEXT, repo_name TEXT, last_update INT, "
+
"PRIMARY KEY(id))"
);
mm
.
prefs
.
edit
().
remove
(
Const
.
Key
.
ETAG_KEY
).
apply
();
oldVersion
=
3
;
try
{
if
(
oldVersion
<
3
)
{
db
.
execSQL
(
"DROP TABLE IF EXISTS "
+
TABLE_NAME
);
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS "
+
TABLE_NAME
+
" "
+
"(id TEXT, name TEXT, version TEXT, versionCode INT, minMagisk INT, "
+
"author TEXT, description TEXT, repo_name TEXT, last_update INT, "
+
"PRIMARY KEY(id))"
);
mm
.
prefs
.
edit
().
remove
(
Const
.
Key
.
ETAG_KEY
).
apply
();
oldVersion
=
3
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
// Reset database
onDowngrade
(
db
,
DATABASE_VER
,
0
);
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
View file @
e518f4ce
...
...
@@ -114,49 +114,54 @@ public class SuDatabaseHelper extends SQLiteOpenHelper {
@Override
public
void
onUpgrade
(
SQLiteDatabase
db
,
int
oldVersion
,
int
newVersion
)
{
if
(
oldVersion
==
0
)
{
createTables
(
db
);
oldVersion
=
3
;
}
if
(
oldVersion
==
1
)
{
// We're dropping column app_name, rename and re-construct table
db
.
execSQL
(
"ALTER TABLE "
+
POLICY_TABLE
+
" RENAME TO "
+
POLICY_TABLE
+
"_old"
);
// Create the new tables
createTables
(
db
);
// Migrate old data to new tables
db
.
execSQL
(
"INSERT INTO "
+
POLICY_TABLE
+
" SELECT "
+
"uid, package_name, policy, until, logging, notification "
+
"FROM "
+
POLICY_TABLE
+
"_old"
);
db
.
execSQL
(
"DROP TABLE "
+
POLICY_TABLE
+
"_old"
);
File
oldDB
=
Utils
.
getDatabasePath
(
MagiskManager
.
get
(),
"sulog.db"
);
if
(
oldDB
.
exists
())
{
migrateLegacyLogList
(
oldDB
,
db
);
MagiskManager
.
get
().
deleteDatabase
(
"sulog.db"
);
try
{
if
(
oldVersion
==
0
)
{
createTables
(
db
);
oldVersion
=
3
;
}
if
(
oldVersion
==
1
)
{
// We're dropping column app_name, rename and re-construct table
db
.
execSQL
(
"ALTER TABLE "
+
POLICY_TABLE
+
" RENAME TO "
+
POLICY_TABLE
+
"_old"
);
// Create the new tables
createTables
(
db
);
// Migrate old data to new tables
db
.
execSQL
(
"INSERT INTO "
+
POLICY_TABLE
+
" SELECT "
+
"uid, package_name, policy, until, logging, notification "
+
"FROM "
+
POLICY_TABLE
+
"_old"
);
db
.
execSQL
(
"DROP TABLE "
+
POLICY_TABLE
+
"_old"
);
File
oldDB
=
Utils
.
getDatabasePath
(
MagiskManager
.
get
(),
"sulog.db"
);
if
(
oldDB
.
exists
())
{
migrateLegacyLogList
(
oldDB
,
db
);
MagiskManager
.
get
().
deleteDatabase
(
"sulog.db"
);
}
++
oldVersion
;
}
if
(
oldVersion
==
2
)
{
db
.
execSQL
(
"UPDATE "
+
LOG_TABLE
+
" SET time=time*1000"
);
++
oldVersion
;
}
if
(
oldVersion
==
3
)
{
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS "
+
STRINGS_TABLE
+
" "
+
"(key TEXT, value TEXT, PRIMARY KEY(key))"
);
++
oldVersion
;
}
if
(
oldVersion
==
4
)
{
db
.
execSQL
(
"UPDATE "
+
POLICY_TABLE
+
" SET uid=uid%100000"
);
++
oldVersion
;
}
++
oldVersion
;
}
if
(
oldVersion
==
2
)
{
db
.
execSQL
(
"UPDATE "
+
LOG_TABLE
+
" SET time=time*1000"
);
++
oldVersion
;
}
if
(
oldVersion
==
3
)
{
db
.
execSQL
(
"CREATE TABLE IF NOT EXISTS "
+
STRINGS_TABLE
+
" "
+
"(key TEXT, value TEXT, PRIMARY KEY(key))"
);
++
oldVersion
;
}
if
(
oldVersion
==
4
)
{
db
.
execSQL
(
"UPDATE "
+
POLICY_TABLE
+
" SET uid=uid%100000"
);
++
oldVersion
;
}
if
(!
Utils
.
itemExist
(
GLOBAL_DB
))
{
// Hard link our DB globally
Shell
.
su_raw
(
"ln "
+
getDbFile
()
+
" "
+
GLOBAL_DB
);
if
(!
Utils
.
itemExist
(
GLOBAL_DB
))
{
// Hard link our DB globally
Shell
.
su_raw
(
"ln "
+
getDbFile
()
+
" "
+
GLOBAL_DB
);
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
onDowngrade
(
db
,
DATABASE_VER
,
0
);
}
}
...
...
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