Skip to content

Commit 75c8454

Browse files
authored
Merge pull request #2624 from switchifyapp/fix/hide-control-pc-locked-2623
Hide Control PC in service menu when device is locked
2 parents 18d57f2 + 7fcbaf6 commit 75c8454

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

app/src/main/java/com/enaboapps/switchify/service/menu/menus/main/MainMenuStructure.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ class MainMenuStructure(
145145
action = { MenuManager.getInstance().openMediaControlMenu() }
146146
)
147147
},
148-
if (deviceLockObserver.isUserUnlocked() == true) {
148+
if (deviceLockObserver.isUserUnlocked() == true &&
149+
!DeviceLockObserver.isKeyguardLocked(accessibilityService)
150+
) {
149151
MenuItemRegistry.getMainMenuDefinition("control_pc")?.let { def ->
150152
MenuItem(
151153
definition = def,

app/src/main/java/com/enaboapps/switchify/service/utils/DeviceLockObserver.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.enaboapps.switchify.service.utils
22

3+
import android.app.KeyguardManager
34
import android.content.BroadcastReceiver
45
import android.content.Context
56
import android.content.Intent
@@ -20,6 +21,13 @@ class DeviceLockObserver(context: Context) {
2021
context.applicationContext.getSystemService(Context.USER_SERVICE) as UserManager
2122
return um.isUserUnlocked
2223
}
24+
25+
@JvmStatic
26+
fun isKeyguardLocked(context: Context): Boolean {
27+
val km =
28+
context.applicationContext.getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
29+
return km.isKeyguardLocked
30+
}
2331
}
2432

2533
private val appContext = context.applicationContext

0 commit comments

Comments
 (0)