Skip to content

Commit afe060e

Browse files
Improve the design of Cross Profile Intent Filter (#299, #301)
Update dependencies Co-authored-by: Araaf Royall ❂ <87515236+AraafRoyall@users.noreply.github.com>
1 parent aea0a8a commit afe060e

12 files changed

Lines changed: 248 additions & 177 deletions

File tree

app/src/main/java/com/bintianqi/owndroid/MyDbHelper.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import android.content.Context
44
import android.database.sqlite.SQLiteDatabase
55
import android.database.sqlite.SQLiteOpenHelper
66

7-
class MyDbHelper(context: Context): SQLiteOpenHelper(context, "data", null, 8) {
7+
class MyDbHelper(context: Context): SQLiteOpenHelper(context, "data", null, 9) {
88
override fun onCreate(db: SQLiteDatabase) {
99
db.execSQL(DHIZUKU_CLIENTS_TABLE)
1010
db.execSQL(SECURITY_LOGS_TABLE)
1111
db.execSQL(NETWORK_LOGS_TABLE)
1212
db.execSQL(APP_GROUPS_TABLE)
13-
db.execSQL(CPIF_TABLE)
13+
db.execSQL(CPIF2_TABLE)
1414
}
1515
override fun onUpgrade(db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
1616
if (oldVersion < 2) {
@@ -25,6 +25,10 @@ class MyDbHelper(context: Context): SQLiteOpenHelper(context, "data", null, 8) {
2525
if (oldVersion < 8) {
2626
db.execSQL(CPIF_TABLE)
2727
}
28+
if (oldVersion < 9) {
29+
db.execSQL(DELETE_CPIF)
30+
db.execSQL(CPIF2_TABLE)
31+
}
2832
}
2933
companion object {
3034
const val DHIZUKU_CLIENTS_TABLE = "CREATE TABLE dhizuku_clients (uid INTEGER PRIMARY KEY," +
@@ -39,5 +43,9 @@ class MyDbHelper(context: Context): SQLiteOpenHelper(context, "data", null, 8) {
3943
"name TEXT, apps TEXT)"
4044
const val CPIF_TABLE = "CREATE TABLE cpif (" +
4145
"action_str TEXT, category TEXT, mime_type TEXT, direction INTEGER, time INTEGER)"
46+
const val DELETE_CPIF = "DROP TABLE cpif"
47+
const val CPIF2_TABLE = "CREATE TABLE cpif2 (id INTEGER PRIMARY KEY AUTOINCREMENT," +
48+
"action_str TEXT, category TEXT, mime_type TEXT, direction INTEGER," +
49+
"created_at INTEGER)"
4250
}
4351
}

app/src/main/java/com/bintianqi/owndroid/feature/work_profile/CrossProfileIntentFilterModel.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ data class IntentFilterOptions(
1010
val direction: Int // 1: private to work, 2: work to private, 3: both
1111
)
1212

13+
/** Represents a row in database table `cpif` */
14+
class IntentFilterEntry(
15+
val id: Int, val options: IntentFilterOptions, val time: Long
16+
)
17+
1318
val directionTextMap = mapOf(
1419
1 to R.string.personal_to_work,
1520
2 to R.string.work_to_personal,

app/src/main/java/com/bintianqi/owndroid/feature/work_profile/CrossProfileIntentFilterRepository.kt

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,30 @@ class CrossProfileIntentFilterRepository(val dbHelper: MyDbHelper) {
1010
cv.put("category", data.category)
1111
cv.put("mime_type", data.mimeType)
1212
cv.put("direction", data.direction)
13-
cv.put("time", System.currentTimeMillis())
14-
dbHelper.writableDatabase.insert("cpif", null, cv)
13+
cv.put("created_at", System.currentTimeMillis())
14+
dbHelper.writableDatabase.insert("cpif2", null, cv)
1515
}
1616

17-
fun getAllCrossProfileIntentFilters(): List<IntentFilterOptions> {
18-
val list = mutableListOf<IntentFilterOptions>()
17+
fun getAllFilters(): List<IntentFilterEntry> {
18+
val list = mutableListOf<IntentFilterEntry>()
1919
dbHelper.readableDatabase.rawQuery(
20-
"SELECT * FROM cpif ORDER BY time DESC", null
20+
"SELECT * FROM cpif2 ORDER BY created_at DESC", null
2121
).use {
2222
while (it.moveToNext()) {
23-
list += IntentFilterOptions(
24-
it.getString(0), it.getString(1), it.getString(2), it.getInt(3)
23+
val options = IntentFilterOptions(
24+
it.getString(1), it.getString(2), it.getString(3), it.getInt(4)
2525
)
26+
list += IntentFilterEntry(it.getInt(0), options, it.getLong(5))
2627
}
2728
}
2829
return list
2930
}
3031

32+
fun deleteById(id: Int) {
33+
dbHelper.writableDatabase.delete("cpif2", "id = ?", arrayOf("$id"))
34+
}
35+
3136
fun deleteAllCrossProfileIntentFilters() {
32-
dbHelper.writableDatabase.delete("cpif", null, null)
37+
dbHelper.writableDatabase.delete("cpif2", null, null)
3338
}
3439
}

0 commit comments

Comments
 (0)