Skip to content

Commit 160c363

Browse files
committed
Let screen wake touches pass through
1 parent c1bf6b8 commit 160c363

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

app/src/main/java/eu/darken/bluemusic/monitor/core/screenwake/ScreenWakeActivity.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import android.os.Build
44
import android.os.Bundle
55
import android.os.Handler
66
import android.os.Looper
7-
import android.view.MotionEvent
87
import android.view.WindowManager
98
import eu.darken.bluemusic.common.ui.Activity2
109

@@ -25,6 +24,10 @@ class ScreenWakeActivity : Activity2() {
2524
// launched (typically the music app) before system display timeout fires.
2625
// FLAG_KEEP_SCREEN_ON is dropped automatically when the activity finishes.
2726
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
27+
// This activity is visually transparent, so it must not consume the first
28+
// tap or swipe after wake. Let touches pass through to the lockscreen or
29+
// launched app underneath while the timer controls our own lifetime.
30+
window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE)
2831
}
2932

3033
override fun onResume() {
@@ -37,13 +40,6 @@ class ScreenWakeActivity : Activity2() {
3740
Handler(Looper.getMainLooper()).postDelayed(::finish, HOLD_DURATION_MS)
3841
}
3942

40-
override fun dispatchTouchEvent(ev: MotionEvent): Boolean {
41-
// The user is interacting now — get out of their way immediately. The host app
42-
// they tapped will keep the screen on naturally from here.
43-
finish()
44-
return true
45-
}
46-
4743
companion object {
4844
// Long enough to read the screen and tap a launched music app; short enough
4945
// not to drain battery on a forgotten connection. Single tunable constant.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package eu.darken.bluemusic.monitor.core.screenwake
2+
3+
import io.kotest.matchers.collections.shouldNotContain
4+
import org.junit.jupiter.api.Test
5+
import testhelpers.BaseTest
6+
7+
class ScreenWakeActivityTest : BaseTest() {
8+
9+
@Test
10+
fun `does not intercept touch events`() {
11+
val methodNames = ScreenWakeActivity::class.java.declaredMethods.map { it.name }
12+
13+
methodNames shouldNotContain "dispatchTouchEvent"
14+
}
15+
}

0 commit comments

Comments
 (0)