Skip to content

Commit 9cbf03e

Browse files
committed
notif: disable actions when biometric is enabled
1 parent f00a05d commit 9cbf03e

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ import android.app.NotificationChannel
2828
import android.app.NotificationManager
2929
import android.app.PendingIntent
3030
import android.app.Service
31+
import android.app.UiModeManager
3132
import android.content.Context
3233
import android.content.Intent
3334
import android.content.SharedPreferences
3435
import android.content.SharedPreferences.OnSharedPreferenceChangeListener
3536
import android.content.pm.PackageManager
3637
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_CONNECTED_DEVICE
3738
import android.content.pm.ServiceInfo.FOREGROUND_SERVICE_TYPE_SYSTEM_EXEMPTED
39+
import android.content.res.Configuration
3840
import android.net.ConnectivityManager
3941
import android.net.Network
4042
import android.net.NetworkCapabilities
@@ -1273,11 +1275,18 @@ class BraveVPNService :
12731275
// 1. Pause / Resume, Stop action button.
12741276
// 2. RethinkDNS modes (dns & dns+firewall mode)
12751277
// 3. No action button.
1276-
logd("notification action type: ${persistentState.notificationActionType}")
1278+
val isAppLockEnabled = persistentState.biometricAuth && !isAppRunningOnTv()
1279+
// do not show notification action when app lock is enabled
1280+
val notifActionType = if (isAppLockEnabled) {
1281+
NotificationActionType.NONE
1282+
} else {
1283+
NotificationActionType.getNotificationActionType(
1284+
persistentState.notificationActionType
1285+
)
1286+
}
1287+
logd("notification action type: ${persistentState.notificationActionType}, $notifActionType")
12771288

1278-
when (
1279-
NotificationActionType.getNotificationActionType(persistentState.notificationActionType)
1280-
) {
1289+
when (notifActionType) {
12811290
NotificationActionType.PAUSE_STOP -> {
12821291
// Add the action based on AppState (PAUSE/ACTIVE)
12831292
val openIntent1 =
@@ -1343,6 +1352,7 @@ class BraveVPNService :
13431352

13441353
NotificationActionType.NONE -> {
13451354
Logger.i(LOG_TAG_VPN, "No notification action")
1355+
builder.setContentTitle(contentTitle)
13461356
}
13471357
}
13481358

@@ -1370,6 +1380,15 @@ class BraveVPNService :
13701380
return notification
13711381
}
13721382

1383+
private fun isAppRunningOnTv(): Boolean {
1384+
return try {
1385+
val uiModeManager: UiModeManager = getSystemService(UI_MODE_SERVICE) as UiModeManager
1386+
uiModeManager.currentModeType == Configuration.UI_MODE_TYPE_TELEVISION
1387+
} catch (ignored: Exception) {
1388+
false
1389+
}
1390+
}
1391+
13731392
// keep in sync with RefreshDatabase#makeVpnIntent
13741393
private fun makeVpnIntent(notificationID: Int, intentExtra: String): PendingIntent {
13751394
val intent = Intent(this, NotificationActionReceiver::class.java)
@@ -1727,6 +1746,11 @@ class BraveVPNService :
17271746
notificationManager.notify(SERVICE_ID, updateNotificationBuilder())
17281747
}
17291748

1749+
PersistentState.BIOMETRIC_AUTH -> {
1750+
// update the notification builder to show the action buttons based on the biometric
1751+
notificationManager.notify(SERVICE_ID, updateNotificationBuilder())
1752+
}
1753+
17301754
PersistentState.INTERNET_PROTOCOL -> {
17311755
io("chooseIpVersion") { handleIPProtoChanges() }
17321756
}

app/src/main/java/com/celzero/bravedns/service/PersistentState.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class PersistentState(context: Context) : SimpleKrate(context), KoinComponent {
5858
const val CONNECTIVITY_CHECKS = "connectivity_check"
5959
const val NOTIFICATION_PERMISSION = "notification_permission_request"
6060
const val EXCLUDE_APPS_IN_PROXY = "exclude_apps_in_proxy"
61+
const val BIOMETRIC_AUTH = "biometric_authentication"
6162
}
6263

6364
// when vpn is started by the user, this is set to true; set to false when user stops

0 commit comments

Comments
 (0)