mirror of
https://github.com/greenart7c3/Amber.git
synced 2026-10-05 19:08:23 +00:00
Create a update for fixing the incorrect permissions
This commit is contained in:
@@ -228,6 +228,7 @@ class Amber : Application(), LifecycleObserver {
|
||||
settings = LocalPreferences.loadSettingsFromEncryptedStorage()
|
||||
LocalPreferences.reloadApp()
|
||||
fixRejectedPermissions()
|
||||
fixAcceptedPermissions()
|
||||
isStartingApp.value = false
|
||||
|
||||
checkForNewRelaysAndUpdateAllFilters(true)
|
||||
@@ -287,6 +288,27 @@ class Amber : Application(), LifecycleObserver {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun fixAcceptedPermissions() {
|
||||
LocalPreferences.allSavedAccounts(this).forEach { account ->
|
||||
val permissions = getDatabase(account.npub).applicationDao().getAllAcceptedPermissions()
|
||||
Log.d(TAG, "Found ${permissions.size} accepted permissions")
|
||||
val localPermissions =
|
||||
permissions.map {
|
||||
val isAcceptable = it.acceptable
|
||||
val acceptUntil = if (isAcceptable) Long.MAX_VALUE / 1000 else 0L
|
||||
val rejectUntil = if (!isAcceptable) Long.MAX_VALUE / 1000 else 0L
|
||||
|
||||
it.copy(
|
||||
acceptable = it.acceptable,
|
||||
acceptUntil = acceptUntil,
|
||||
rejectUntil = rejectUntil,
|
||||
rememberType = RememberType.ALWAYS.screenCode,
|
||||
)
|
||||
}
|
||||
getDatabase(account.npub).applicationDao().insertPermissions(localPermissions)
|
||||
}
|
||||
}
|
||||
|
||||
fun startService() {
|
||||
try {
|
||||
Log.d(TAG, "Starting ConnectivityService")
|
||||
|
||||
@@ -79,6 +79,10 @@ interface ApplicationDao {
|
||||
@Transaction
|
||||
fun getAllRejectedPermissions(): List<ApplicationPermissionsEntity>
|
||||
|
||||
@Query("SELECT * FROM applicationPermission WHERE acceptable = 1 AND acceptUntil = 0")
|
||||
@Transaction
|
||||
fun getAllAcceptedPermissions(): List<ApplicationPermissionsEntity>
|
||||
|
||||
@Query("SELECT * FROM applicationPermission WHERE pkKey = :key AND type = :type AND kind = :kind")
|
||||
fun getPermission(
|
||||
key: String,
|
||||
|
||||
Reference in New Issue
Block a user