Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ class SettingsRepository(private val context: Context) {
const val KEY_HIDE_GESTURE_BAR_ENABLED = "hide_gesture_bar_enabled"
const val KEY_HIDE_GESTURE_BAR_ON_LAUNCHER_ENABLED = "hide_gesture_bar_on_launcher_enabled"
const val KEY_CIRCLE_TO_SEARCH_GESTURE_ENABLED = "circle_to_search_gesture_enabled"
const val KEY_CIRCLE_TO_SEARCH_GESTURE_HEIGHT = "circle_to_search_gesture_height"
const val KEY_CIRCLE_TO_SEARCH_PREVIEW_ENABLED = "circle_to_search_preview_enabled"
const val KEY_AUTO_UPDATE_ENABLED = "auto_update_enabled"
const val KEY_UPDATE_NOTIFICATION_ENABLED = "update_notification_enabled"
const val KEY_LAST_UPDATE_CHECK_TIME = "last_update_check_time"
const val KEY_CHECK_PRE_RELEASES_ENABLED = "check_pre_releases_enabled"

const val KEY_APP_LOCK_ENABLED = "app_lock_enabled"
const val KEY_APP_LOCK_SELECTED_APPS = "app_lock_selected_apps"
const val KEY_APP_LOCK_AUTO_LOCK_DELAY_INDEX = "app_lock_auto_lock_delay_index"
const val KEY_USE_USAGE_ACCESS = "use_usage_access"

const val KEY_FREEZE_WHEN_LOCKED_ENABLED = "freeze_when_locked_enabled"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class AppFlowHandler(
private val scope = CoroutineScope(Dispatchers.Main)

private val authenticatedPackages = mutableSetOf<String>()
private val lastLeaveTimes = mutableMapOf<String, Long>()

// App Lock State
private var lockingPackage: String? = null
Expand All @@ -53,8 +54,13 @@ class AppFlowHandler(
val prefs = context.getSharedPreferences("essentials_prefs", Context.MODE_PRIVATE)
val useUsageAccess = prefs.getBoolean("use_usage_access", false)

val oldPackage = currentPackage
currentPackage = packageName

if (oldPackage != null && oldPackage != packageName) {
lastLeaveTimes[oldPackage] = System.currentTimeMillis()
}

if (packageName != context.packageName && packageName != lockingPackage) {
lockingPackage = null
}
Expand Down Expand Up @@ -101,6 +107,29 @@ class AppFlowHandler(

val isLocked = selectedApps.find { it.packageName == packageName }?.isEnabled ?: false

if (isLocked && authenticatedPackages.contains(packageName)) {
val delayIndex = prefs.getInt("app_lock_auto_lock_delay_index", 0)
if (delayIndex > 0) {
val delayMinutes = when (delayIndex) {
1 -> 1
2 -> 5
3 -> 10
4 -> 20
5 -> 30
else -> 0
}

val lastLeaveTime = lastLeaveTimes[packageName] ?: 0L
if (lastLeaveTime > 0) {
val now = System.currentTimeMillis()
if (now - lastLeaveTime > delayMinutes * 60 * 1000L) {
authenticatedPackages.remove(packageName)
lastLeaveTimes.remove(packageName)
}
}
}
}

if (isLocked && !authenticatedPackages.contains(packageName)) {
// Skip if we already requested a lock for this package very recently
val now = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ class FlashlightHandler(
private var flashlightJob: Job? = null
private var isInternalToggle = false

private val NOTIFICATION_ID_FLASHLIGHT = 1001
private val NOTIFICATION_ID_FLASHLIGHT = 1010
private val CHANNEL_ID_FLASHLIGHT = "flashlight_live_update"

private val torchCallback = object : CameraManager.TorchCallback() {
override fun onTorchModeChanged(cameraId: String, enabled: Boolean) {
if (!enabled) {
cancelFlashlightNotification()
}

val primaryId = getCameraId()
if (cameraId != primaryId) return // Ignore updates from auxiliary camera IDs

Expand Down Expand Up @@ -140,7 +144,7 @@ class FlashlightHandler(

private fun updateFlashlightNotification(intensity: Int) {
val prefs = service.getSharedPreferences("essentials_prefs", Context.MODE_PRIVATE)
if (!prefs.getBoolean("flashlight_live_update_enabled", true)) {
if (!prefs.getBoolean("flashlight_live_update_enabled", true) || !isTorchOn) {
cancelFlashlightNotification()
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,16 @@ class OmniGestureOverlayHandler(private val service: AccessibilityService) {
runCatching { VibrationEffect.createWaveform(timings, amplitudes, -1) }.getOrNull()
}

fun updateOverlay(enabled: Boolean) {
fun updateOverlay(enabled: Boolean, heightDp: Float = 48f, isPreview: Boolean = false) {
handler.post {
if (enabled) showOverlay() else removeOverlay()
if (enabled) showOverlay(heightDp, isPreview) else removeOverlay()
}
}

private fun showOverlay() {
if (overlayView != null) return

overlayView = View(service).apply {
setBackgroundColor(Color.TRANSPARENT)
setOnTouchListener { _, event ->
handleTouch(event)
true
}
}

private fun showOverlay(heightDp: Float, isPreview: Boolean) {
val params = WindowManager.LayoutParams(
dpToPx(WIDTH_DP),
dpToPx(HEIGHT_DP),
dpToPx(heightDp),
WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
Expand All @@ -69,7 +59,21 @@ class OmniGestureOverlayHandler(private val service: AccessibilityService) {
}
}

runCatching { windowManager.addView(overlayView, params) }
if (overlayView == null) {
overlayView = View(service).apply {
setBackgroundColor(if (isPreview) Color.parseColor("#406200EE") else Color.TRANSPARENT)
setOnTouchListener { _, event ->
handleTouch(event)
true
}
}
runCatching { windowManager.addView(overlayView, params) }
} else {
overlayView?.apply {
setBackgroundColor(if (isPreview) Color.parseColor("#406200EE") else Color.TRANSPARENT)
runCatching { windowManager.updateViewLayout(this, params) }
}
}
}

private fun handleTouch(event: MotionEvent) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
private lateinit var notificationLightingHandler: NotificationLightingHandler
private lateinit var buttonRemapHandler: ButtonRemapHandler
private lateinit var appFlowHandler: AppFlowHandler
private lateinit var securityHandler: SecurityHandler
private lateinit var ambientGlanceHandler: AmbientGlanceHandler
private lateinit var aodForceTurnOffHandler: AodForceTurnOffHandler
private lateinit var omniGestureOverlayHandler: OmniGestureOverlayHandler
Expand All @@ -55,7 +54,9 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene

private val preferenceChangeListener =
android.content.SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
if (key == "circle_to_search_gesture_enabled" || key == "hide_gesture_bar_enabled") {
if (key == "circle_to_search_gesture_enabled" ||
key == "circle_to_search_gesture_height" ||
key == "circle_to_search_preview_enabled") {
updateOmniOverlay()
}
}
Expand All @@ -68,7 +69,6 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
notificationLightingHandler = NotificationLightingHandler(this)
buttonRemapHandler = ButtonRemapHandler(this, flashlightHandler)
appFlowHandler = AppFlowHandler(this, this)
securityHandler = SecurityHandler(this)
ambientGlanceHandler = AmbientGlanceHandler(this)
aodForceTurnOffHandler = AodForceTurnOffHandler(this)
omniGestureOverlayHandler = OmniGestureOverlayHandler(this)
Expand Down Expand Up @@ -97,7 +97,6 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
}

Intent.ACTION_USER_PRESENT -> {
securityHandler.restoreAnimationScale()
}

InputEventListenerService.ACTION_VOLUME_LONG_PRESSED -> {
Expand Down Expand Up @@ -165,9 +164,10 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene

private fun updateOmniOverlay() {
val prefs = getSharedPreferences("essentials_prefs", MODE_PRIVATE)
val isHideBarEnabled = prefs.getBoolean("hide_gesture_bar_enabled", false)
val isGestureEnabled = prefs.getBoolean("circle_to_search_gesture_enabled", false)
omniGestureOverlayHandler.updateOverlay(isHideBarEnabled && isGestureEnabled)
val height = try { prefs.getFloat("circle_to_search_gesture_height", 48f) } catch (e: Exception) { 48f }
val isPreview = prefs.getBoolean("circle_to_search_preview_enabled", false)
omniGestureOverlayHandler.updateOverlay(isGestureEnabled, height, isPreview)
}

override fun onDestroy() {
Expand All @@ -177,7 +177,6 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
}
flashlightHandler.unregister()
sensorManager.unregisterListener(this)
securityHandler.restoreAnimationScale()
notificationLightingHandler.removeOverlay()
ambientGlanceHandler.removeOverlay()
aodForceTurnOffHandler.removeOverlay()
Expand All @@ -196,13 +195,6 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
val packageName = event.packageName?.toString() ?: return
appFlowHandler.onPackageChanged(packageName)
}

// Bypass security scanning for camera apps to avoid performance interference
if (appFlowHandler.isCameraApp()) {
return
}

securityHandler.onAccessibilityEvent(event)
}

override fun onInterrupt() {}
Expand Down Expand Up @@ -288,7 +280,7 @@ class ScreenOffAccessibilityService : AccessibilityService(), SensorEventListene
val vibrator = getSystemService(VIBRATOR_SERVICE) as? Vibrator
vibrator?.let { performHapticFeedback(it, hapticType) }
}
securityHandler.lockDevice()
performGlobalAction(AccessibilityService.GLOBAL_ACTION_LOCK_SCREEN)
}

"SHOW_NOTIFICATION_LIGHTING" -> notificationLightingHandler.handleIntent(intent)
Expand Down
Loading