Skip to content

Commit 7fcbaf6

Browse files
Hide Control PC in service menu when device is locked
- Adds DeviceLockObserver.isKeyguardLocked using KeyguardManager - Gates the control_pc main menu item on both the direct-boot user-unlocked state and the keyguard not showing, since UserManager.isUserUnlocked stays true after first unlock - No refresh wiring needed because the main menu rebuilds its items each time it opens 🤖 Auto-generated Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 18d57f2 commit 7fcbaf6

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)