Create a update for fixing the incorrect permissions

This commit is contained in:
greenart7c3
2025-09-08 15:31:40 -03:00
parent bd794b2f8f
commit bf959c5519
2 changed files with 26 additions and 0 deletions
@@ -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,