Loading app/src/main/kotlin/at/bitfire/davdroid/ReLoginWithOidcService.kt +0 −3 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.os.Bundle import android.os.IBinder import androidx.core.content.ContextCompat import at.bitfire.davdroid.log.Logger import org.apache.commons.lang3.NotImplementedException class ReLoginWithOidcService: Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Loading Loading @@ -83,7 +81,6 @@ class ReLoginWithOidcService: Service() { Logger.log.warning("${exception.javaClass}: can't add account: ${exception.message}") null } } override fun onBind(intent: Intent?): IBinder? { Loading app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +25 −4 Original line number Diff line number Diff line Loading @@ -4,12 +4,16 @@ package at.bitfire.davdroid.receiver import android.Manifest.permission.POST_NOTIFICATIONS import android.accounts.Account import android.accounts.AccountManager import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.pm.PackageManager.PERMISSION_GRANTED import android.os.Build.VERSION import android.os.Build.VERSION_CODES import androidx.core.app.NotificationManagerCompat import at.bitfire.davdroid.R import at.bitfire.davdroid.ReLoginWithOidcService Loading @@ -35,10 +39,13 @@ class BootCompletedReceiver: BroadcastReceiver() { val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) val canNotify = canNotify(context) AccountUtils.getMainAccounts(context) .forEach { if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { val needReLogin = eAccountType == it.type && !isLoggedWithOpenId(it, accountManager) if ( canNotify && needReLogin) { notifySwitchToOpenId(it, context) } else { // sync intervals are checked in App.onCreate() val accountSettings = AccountSettings(context, it) Loading @@ -54,7 +61,6 @@ class BootCompletedReceiver: BroadcastReceiver() { } private fun notifySwitchToOpenId(account: Account, context: Context) { val tag = "Switch to openID" val title = context.getString(R.string.notification_account_title, account.name) val contentText = context.getString(R.string.notification_switch_to_openId_text) val intent = generateReLoginIntent(context) Loading @@ -68,7 +74,7 @@ class BootCompletedReceiver: BroadcastReceiver() { .build() val notificationManager = NotificationManagerCompat.from(context) notificationManager.notifyIfPossible(tag, NOTIFY_SWITCH_TO_OPENID, notification) notificationManager.notifyIfPossible(NOTIFICATION_TAG, NOTIFY_SWITCH_TO_OPENID, notification) } private fun generateReLoginIntent(context: Context): PendingIntent { Loading @@ -79,4 +85,19 @@ class BootCompletedReceiver: BroadcastReceiver() { reLoginIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) } private fun canNotify(context: Context): Boolean { if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { val permission = POST_NOTIFICATIONS if (context.checkSelfPermission(permission) != PERMISSION_GRANTED) { Logger.log.warning("Missing notification permission") return false } } return true } companion object { private const val NOTIFICATION_TAG = "SWITCH_TO_OPENID" } } Loading
app/src/main/kotlin/at/bitfire/davdroid/ReLoginWithOidcService.kt +0 −3 Original line number Diff line number Diff line Loading @@ -26,8 +26,6 @@ import android.os.Bundle import android.os.IBinder import androidx.core.content.ContextCompat import at.bitfire.davdroid.log.Logger import org.apache.commons.lang3.NotImplementedException class ReLoginWithOidcService: Service() { override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { Loading Loading @@ -83,7 +81,6 @@ class ReLoginWithOidcService: Service() { Logger.log.warning("${exception.javaClass}: can't add account: ${exception.message}") null } } override fun onBind(intent: Intent?): IBinder? { Loading
app/src/main/kotlin/at/bitfire/davdroid/receiver/BootCompletedReceiver.kt +25 −4 Original line number Diff line number Diff line Loading @@ -4,12 +4,16 @@ package at.bitfire.davdroid.receiver import android.Manifest.permission.POST_NOTIFICATIONS import android.accounts.Account import android.accounts.AccountManager import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.pm.PackageManager.PERMISSION_GRANTED import android.os.Build.VERSION import android.os.Build.VERSION_CODES import androidx.core.app.NotificationManagerCompat import at.bitfire.davdroid.R import at.bitfire.davdroid.ReLoginWithOidcService Loading @@ -35,10 +39,13 @@ class BootCompletedReceiver: BroadcastReceiver() { val eAccountType = context.getString(R.string.eelo_account_type) val accountManager = AccountManager.get(context) val canNotify = canNotify(context) AccountUtils.getMainAccounts(context) .forEach { if (eAccountType == it.type && !isLoggedWithOpenId(it, accountManager)) { val needReLogin = eAccountType == it.type && !isLoggedWithOpenId(it, accountManager) if ( canNotify && needReLogin) { notifySwitchToOpenId(it, context) } else { // sync intervals are checked in App.onCreate() val accountSettings = AccountSettings(context, it) Loading @@ -54,7 +61,6 @@ class BootCompletedReceiver: BroadcastReceiver() { } private fun notifySwitchToOpenId(account: Account, context: Context) { val tag = "Switch to openID" val title = context.getString(R.string.notification_account_title, account.name) val contentText = context.getString(R.string.notification_switch_to_openId_text) val intent = generateReLoginIntent(context) Loading @@ -68,7 +74,7 @@ class BootCompletedReceiver: BroadcastReceiver() { .build() val notificationManager = NotificationManagerCompat.from(context) notificationManager.notifyIfPossible(tag, NOTIFY_SWITCH_TO_OPENID, notification) notificationManager.notifyIfPossible(NOTIFICATION_TAG, NOTIFY_SWITCH_TO_OPENID, notification) } private fun generateReLoginIntent(context: Context): PendingIntent { Loading @@ -79,4 +85,19 @@ class BootCompletedReceiver: BroadcastReceiver() { reLoginIntent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT) } private fun canNotify(context: Context): Boolean { if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { val permission = POST_NOTIFICATIONS if (context.checkSelfPermission(permission) != PERMISSION_GRANTED) { Logger.log.warning("Missing notification permission") return false } } return true } companion object { private const val NOTIFICATION_TAG = "SWITCH_TO_OPENID" } }