Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import androidx.room.Transaction

@Dao
interface ProxyApplicationMappingDAO {
Expand Down Expand Up @@ -101,6 +102,23 @@ interface ProxyApplicationMappingDAO {
@Query("update ProxyApplicationMapping set uid = :uid where packageName = :packageName")
fun updateUidForApp(uid: Int, packageName: String)

@Query("update ProxyApplicationMapping set uid = :newUid where uid = :oldUid")
fun tombstoneApp(oldUid: Int, newUid: Int)
@Transaction
fun tombstoneApp(oldUid: Int, newUid: Int) {
// Only apply the logic bellow, if the uid is from a work profile
if (newUid >= 1_000_000) {
// If a record with the 'newUid' already exists, delete it first
// This prevents an application crash: database constraint
deleteMappingByUid(newUid)
}

// Now that the slot is empty, move the 'oldUid' records to 'newUid'
updateUidByOldUid(oldUid, newUid)
}

@Query("delete from ProxyApplicationMapping where uid = :uid")
fun deleteMappingByUid(uid: Int)

// 'ignore' provides an extra layer of safety
@Query("update or ignore ProxyApplicationMapping set uid = :newUid where uid = :oldUid")
fun updateUidByOldUid(oldUid: Int, newUid: Int)
}
Loading