Skip to content

Commit

Permalink
notif: disable actions when biometric is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
hussainmohd-a committed May 29, 2024
1 parent f00a05d commit 9cbf03e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
32 changes: 28 additions & 4 deletions app/src/main/java/com/celzero/bravedns/service/BraveVPNService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ 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
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
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -1343,6 +1352,7 @@ class BraveVPNService :

NotificationActionType.NONE -> {
Logger.i(LOG_TAG_VPN, "No notification action")
builder.setContentTitle(contentTitle)
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9cbf03e

Please sign in to comment.