package com.jovan.assistant.service import android.accessibilityservice.AccessibilityService import android.content.Intent import android.os.Build import android.view.accessibility.AccessibilityEvent import com.jovan.assistant.data.AssistantState /** * Executes system-level actions. Declared with canRetrieveWindowContent=false, so it cannot read the screen. * The user must enable it manually: Settings > Accessibility > AI Voice Assistant. */ class AssistantAccessibilityService : AccessibilityService() { override fun onServiceConnected() { super.onServiceConnected() instance = this AssistantState.accessibilityConnected.value = true } override fun onAccessibilityEvent(event: AccessibilityEvent?) { /* intentionally ignored */ } override fun onInterrupt() {} override fun onUnbind(intent: Intent?): Boolean { instance = null AssistantState.accessibilityConnected.value = false return super.onUnbind(intent) } fun lockScreen(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && performGlobalAction(GLOBAL_ACTION_LOCK_SCREEN) fun goHome() = performGlobalAction(GLOBAL_ACTION_HOME) fun goBack() = performGlobalAction(GLOBAL_ACTION_BACK) fun showRecents() = performGlobalAction(GLOBAL_ACTION_RECENTS) fun showNotifications() = performGlobalAction(GLOBAL_ACTION_NOTIFICATIONS) fun showQuickSettings() = performGlobalAction(GLOBAL_ACTION_QUICK_SETTINGS) fun screenshot(): Boolean = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && performGlobalAction(GLOBAL_ACTION_TAKE_SCREENSHOT) fun launch(intent: Intent): Boolean = try { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) startActivity(intent) true } catch (e: Exception) { false } companion object { @Volatile var instance: AssistantAccessibilityService? = null } }