From 9cbf03eaf6de3f2d7b9d547cb269cea1e4b839d3 Mon Sep 17 00:00:00 2001 From: hussainmohd-a Date: Wed, 29 May 2024 20:28:20 +0530 Subject: [PATCH] notif: disable actions when biometric is enabled --- .../bravedns/service/BraveVPNService.kt | 32 ++++++++++++++++--- .../bravedns/service/PersistentState.kt | 1 + 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt b/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt index 0d39fee99..1c2481896 100644 --- a/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt +++ b/app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt @@ -28,6 +28,7 @@ import android.app.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.app.Service +import android.app.UiModeManager import android.content.Context import android.content.Intent import android.content.SharedPreferences @@ -35,6 +36,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener import android.content.pm.PackageManager import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED +import android.content.res.Configuration import android.net.ConnectivityManager import android.net.Network import android.net.NetworkCapabilities @@ -1273,11 +1275,18 @@ class BraveVPNService : // 1. Pause / Resume, Stop action button. // 2. RethinkDNS modes (dns & dns+firewall mode) // 3. No action button. - logd("notification action type: ${persistentState.notificationActionType}") + val isAppLockEnabled = persistentState.biometricAuth && !isAppRunningOnTv() + // do not show notification action when app lock is enabled + val notifActionType = if (isAppLockEnabled) { + NotificationActionType.NONE + } else { + NotificationActionType.getNotificationActionType( + persistentState.notificationActionType + ) + } + logd("notification action type: ${persistentState.notificationActionType}, $notifActionType") - when ( - NotificationActionType.getNotificationActionType(persistentState.notificationActionType) - ) { + when (notifActionType) { NotificationActionType.PAUSE_STOP -> { // Add the action based on AppState (PAUSE/ACTIVE) val openIntent1 = @@ -1343,6 +1352,7 @@ class BraveVPNService : NotificationActionType.NONE -> { Logger.i(LOG_TAG_VPN, "No notification action") + builder.setContentTitle(contentTitle) } } @@ -1370,6 +1380,15 @@ class BraveVPNService : return notification } + private fun isAppRunningOnTv(): Boolean { + return try { + val uiModeManager: UiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager + uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION + } catch (ignored: Exception) { + false + } + } + // keep in sync with RefreshDatabase#makeVpnIntent private fun makeVpnIntent(notificationID: Int, intentExtra: String): PendingIntent { val intent = Intent(this, NotificationActionReceiver::class.java) @@ -1727,6 +1746,11 @@ class BraveVPNService : notificationManager.notify(SERVICE_ID, updateNotificationBuilder()) } + PersistentState.BIOMETRIC_AUTH -> { + // update the notification builder to show the action buttons based on the biometric + notificationManager.notify(SERVICE_ID, updateNotificationBuilder()) + } + PersistentState.INTERNET_PROTOCOL -> { io("chooseIpVersion") { handleIPProtoChanges() } } diff --git a/app/src/main/java/com/celzero/bravedns/service/PersistentState.kt b/app/src/main/java/com/celzero/bravedns/service/PersistentState.kt index dde05b9e6..32ea508c2 100644 --- a/app/src/main/java/com/celzero/bravedns/service/PersistentState.kt +++ b/app/src/main/java/com/celzero/bravedns/service/PersistentState.kt @@ -58,6 +58,7 @@ class PersistentState(context: Context) : SimpleKrate(context), KoinComponent { const val CONNECTIVITY_CHECKS = "connectivity_check" const val NOTIFICATION_PERMISSION = "notification_permission_request" const val EXCLUDE_APPS_IN_PROXY = "exclude_apps_in_proxy" + const val BIOMETRIC_AUTH = "biometric_authentication" } // when vpn is started by the user, this is set to true; set to false when user stops