forked from topjohnwu/Magisk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
161 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/com/topjohnwu/magisk/database/RepoDatabaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.topjohnwu.magisk.database; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
import com.topjohnwu.magisk.module.Repo; | ||
import com.topjohnwu.magisk.utils.ValueSortedMap; | ||
|
||
import java.util.Collection; | ||
|
||
public class RepoDatabaseHelper extends SQLiteOpenHelper { | ||
|
||
private static final int DATABASE_VER = 1; | ||
private static final String TABLE_NAME = "repos"; | ||
|
||
public RepoDatabaseHelper(Context context) { | ||
super(context, "repo.db", null, DATABASE_VER); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
onUpgrade(db, 0, DATABASE_VER); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | ||
if (oldVersion == 0) { | ||
db.execSQL( | ||
"CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " " + | ||
"(id TEXT, name TEXT, version TEXT, versionCode INT, " + | ||
"author TEXT, description TEXT, repo_name TEXT, last_update INT, " + | ||
"PRIMARY KEY(id))"); | ||
} | ||
// No upgrades yet | ||
} | ||
|
||
public void addRepoMap(ValueSortedMap<String, Repo> map) { | ||
SQLiteDatabase db = getWritableDatabase(); | ||
Collection<Repo> list = map.values(); | ||
for (Repo repo : list) | ||
db.replace(TABLE_NAME, null, repo.getContentValues()); | ||
db.close(); | ||
} | ||
|
||
public void clearRepo() { | ||
SQLiteDatabase db = getWritableDatabase(); | ||
db.delete(TABLE_NAME, null, null); | ||
db.close(); | ||
} | ||
|
||
public void removeRepo(ValueSortedMap<String, Repo> map) { | ||
SQLiteDatabase db = getWritableDatabase(); | ||
Collection<Repo> list = map.values(); | ||
for (Repo repo : list) | ||
db.delete(TABLE_NAME, "id=?", new String[] { repo.getId() }); | ||
db.close(); | ||
} | ||
|
||
public ValueSortedMap<String, Repo> getRepoMap() { | ||
ValueSortedMap<String, Repo> ret = new ValueSortedMap<>(); | ||
SQLiteDatabase db = getReadableDatabase(); | ||
Repo repo; | ||
try (Cursor c = db.query(TABLE_NAME, null, null, null, null, null, null)) { | ||
while (c.moveToNext()) { | ||
repo = new Repo(c); | ||
ret.put(repo.getId(), repo); | ||
} | ||
} | ||
db.close(); | ||
return ret; | ||
} | ||
} |
4 changes: 3 additions & 1 deletion
4
...wu/magisk/superuser/SuDatabaseHelper.java → ...nwu/magisk/database/SuDatabaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
...magisk/superuser/SuLogDatabaseHelper.java → .../magisk/database/SuLogDatabaseHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.