Skip to content

Commit

Permalink
Added auto-revoke permissions warning
Browse files Browse the repository at this point in the history
Signed-off-by: Arnau Mora Gras <[email protected]>
  • Loading branch information
ArnyminerZ authored and sunkup committed Mar 6, 2024
1 parent faf58a9 commit 11fad98
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package at.bitfire.icsdroid.ui.views
import android.app.Application
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.os.PowerManager
import android.widget.Toast
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.foundation.ExperimentalFoundationApi
Expand Down Expand Up @@ -188,6 +190,7 @@ class CalendarListActivity: AppCompatActivity() {
val askForCalendarPermission by model.askForCalendarPermission.observeAsState(false)
val askForNotificationPermission by model.askForNotificationPermission.observeAsState(false)
val askForWhitelisting by model.askForWhitelisting.observeAsState(false)
val askForAutoRevoke by model.askForAutoRevoke.observeAsState(false)

Box(
modifier = Modifier
Expand Down Expand Up @@ -253,6 +256,31 @@ class CalendarListActivity: AppCompatActivity() {
}
}

// Auto Revoke permissions warning
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && askForAutoRevoke) {
item(key = "auto-revoke-whitelisting") {
ActionCard(
title = stringResource(R.string.calendar_list_autorevoke_permissions_title),
message = stringResource(R.string.calendar_list_autorevoke_permissions_text, stringResource(R.string.app_name)),
actionText = stringResource(R.string.calendar_list_battery_whitelist_open_settings),
modifier = Modifier
.fillMaxWidth()
.padding(8.dp)
.animateItemPlacement()
) {
Toast.makeText(
this@CalendarListActivity,
R.string.calendar_list_autorevoke_permissions_instruction,
Toast.LENGTH_LONG
).show()
startActivity(Intent(
Intent.ACTION_AUTO_REVOKE_PERMISSIONS,
Uri.fromParts("package", BuildConfig.APPLICATION_ID, null)
))
}
}
}

if (subscriptions?.isEmpty() == true) {
item(key = "empty") {
Text(
Expand Down Expand Up @@ -372,6 +400,8 @@ class CalendarListActivity: AppCompatActivity() {

val askForWhitelisting = MutableLiveData(false)

val askForAutoRevoke = MutableLiveData(false)


/** whether there are running sync workers */
val isRefreshing = SyncWorker.liveStatus(application).map { workInfos ->
Expand Down Expand Up @@ -408,6 +438,14 @@ class CalendarListActivity: AppCompatActivity() {
// If not ignoring battery optimizations, and sync interval is less than a day
val shouldWhitelistApp = isIgnoringBatteryOptimizations == false && syncInterval != AppAccount.SYNC_INTERVAL_MANUALLY && syncInterval < 86400
askForWhitelisting.postValue(shouldWhitelistApp)

// Make sure permissions are not revoked automatically
val isAutoRevokeWhitelisted = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
getApplication<Application>().packageManager.isAutoRevokeWhitelisted
} else {
true
}
askForAutoRevoke.postValue(!isAutoRevokeWhitelisted)
}

}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<string name="calendar_list_battery_whitelist_title">Battery optimization</string>
<string name="calendar_list_battery_whitelist_text">Battery optimizations may prevent sync intervals shorter than a day. Set %s to \"Not optimized\".</string>
<string name="calendar_list_battery_whitelist_open_settings">Open settings</string>
<string name="calendar_list_autorevoke_permissions_title">Auto-Revoke Permissions</string>
<string name="calendar_list_autorevoke_permissions_text">Android might revoke permissions automatically of apps that you do not access very often. This is usually the case with %s, so please, disable this feature.</string>
<string name="calendar_list_autorevoke_permissions_instruction">Click Permissions > uncheck \"Remove permissions if app isn\'t used\"</string>
<!-- settings, currently in CalendarListActivity -->
<string name="calendar_list_privacy_policy">Privacy policy</string>
<string name="set_sync_interval_title">Set sync. interval:</string>
Expand Down

0 comments on commit 11fad98

Please sign in to comment.