Skip to content

Commit d6e7c42

Browse files
Defer PC controller until device unlock (#2411)
- Move PC service connection controller creation out of direct boot startup - Initialize PC control support with other unlock-protected service components - Hide Control PC from the locked-boot service menu ?? Auto-generated Co-authored-by: Owen McGirr <o.a.mcgirr@gmail.com>
1 parent 99ae693 commit d6e7c42

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

app/src/main/java/com/enaboapps/switchify/service/core/SwitchifyAccessibilityService.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ class SwitchifyAccessibilityService : AccessibilityService(), LifecycleOwner,
101101
AudioActionManager.init(this)
102102

103103
ServiceCore.init(this)
104-
ServiceCore.setPcServiceConnectionController(PcServiceConnectionController(this, serviceScope))
105104

106105
val scanningManager = ServiceCore.getScanningManager() ?: return
107106
val externalSwitchListener = ServiceCore.getExternalSwitchListener() ?: return
@@ -167,6 +166,7 @@ class SwitchifyAccessibilityService : AccessibilityService(), LifecycleOwner,
167166
IAPHandler.connect(context = this)
168167
// Evaluate camera state now that switches are loaded
169168
cameraManager.evaluateAndUpdateCameraState()
169+
initPcServiceConnectionControllerIfNeeded()
170170
// Initialize StatsCollector now that device is unlocked and flush any queued events
171171
val statsCollector = StatsCollector.getInstance()
172172
statsCollector.ensureInitialized()
@@ -176,6 +176,11 @@ class SwitchifyAccessibilityService : AccessibilityService(), LifecycleOwner,
176176
}
177177
}
178178

179+
private fun initPcServiceConnectionControllerIfNeeded() {
180+
if (ServiceCore.getPcServiceConnectionController() != null) return
181+
ServiceCore.setPcServiceConnectionController(PcServiceConnectionController(this, serviceScope))
182+
}
183+
179184

180185
/**
181186
* Setup callbacks for the camera service

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,15 @@ class MainMenuStructure(
145145
action = { MenuManager.getInstance().openMediaControlMenu() }
146146
)
147147
},
148-
MenuItemRegistry.getMainMenuDefinition("control_pc")?.let { def ->
149-
MenuItem(
150-
definition = def,
151-
isLinkToMenu = true,
152-
action = { openPcControlActivity() }
153-
)
154-
},
148+
if (deviceLockObserver.isUserUnlocked() == true) {
149+
MenuItemRegistry.getMainMenuDefinition("control_pc")?.let { def ->
150+
MenuItem(
151+
definition = def,
152+
isLinkToMenu = true,
153+
action = { openPcControlActivity() }
154+
)
155+
}
156+
} else null,
155157
if (NodeExaminer.canPerformEditActions(GesturePoint.getPoint())) {
156158
MenuItemRegistry.getMainMenuDefinition("edit")?.let { def ->
157159
MenuItem(

0 commit comments

Comments
 (0)