@@ -56,55 +56,27 @@ class OverlayService : Service() {
5656 when (intent?.action) {
5757 ACTION_START -> {
5858 try {
59- // Phase 1: Immediately start foreground with a minimal notification
60- // to satisfy Android's 5-second rule.
61- val minimalNotification = NotificationCompat .Builder (this , CHANNEL_ID )
62- .setContentTitle(" GameDeck" )
63- .setContentText(" Initializing..." )
64- .setSmallIcon(android.R .drawable.ic_menu_info_details)
65- .setOngoing(true )
66- .setSilent(true )
67- .build()
68-
69- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
70- ServiceCompat .startForeground(
71- this ,
72- NOTIFICATION_ID ,
73- minimalNotification,
59+ val notification = buildNotification()
60+ ServiceCompat .startForeground(
61+ this ,
62+ NOTIFICATION_ID ,
63+ notification,
64+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .UPSIDE_DOWN_CAKE ) {
7465 ServiceInfo .FOREGROUND_SERVICE_TYPE_SPECIAL_USE
75- )
76- } else {
77- startForeground(NOTIFICATION_ID , minimalNotification)
78- }
79- Log .i(TAG , " Foreground service started with minimal notification." )
80-
81- // Phase 2: Now build the full notification and update it.
82- val fullNotification = buildNotification()
83- val mgr = getSystemService(Context .NOTIFICATION_SERVICE ) as NotificationManager
84- mgr.notify(NOTIFICATION_ID , fullNotification)
85- Log .i(TAG , " Full notification updated." )
86-
87- if (overlayView == null ) {
88- try {
89- showOverlay()
90- Log .i(TAG , " Overlay view added successfully." )
91- } catch (t: Throwable ) {
92- Log .e(TAG , " Failed to add overlay view." , t)
66+ } else {
67+ 0
9368 }
94- }
69+ )
70+ Log .i(TAG , " Foreground service started." )
71+ if (overlayView == null ) showOverlay()
9572 } catch (t: Throwable ) {
9673 Log .e(TAG , " Failed to start foreground service." , t)
9774 stopSelf()
9875 }
9976 }
10077 ACTION_STOP -> {
10178 removeOverlay()
102- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .N ) {
103- stopForeground(STOP_FOREGROUND_REMOVE )
104- } else {
105- @Suppress(" DEPRECATION" )
106- stopForeground(true )
107- }
79+ stopForeground(STOP_FOREGROUND_REMOVE )
10880 stopSelf()
10981 }
11082 }
@@ -146,7 +118,8 @@ class OverlayService : Service() {
146118 WindowManager .LayoutParams .WRAP_CONTENT ,
147119 WindowManager .LayoutParams .WRAP_CONTENT ,
148120 WindowManager .LayoutParams .TYPE_APPLICATION_OVERLAY ,
149- WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE or WindowManager .LayoutParams .FLAG_LAYOUT_IN_SCREEN ,
121+ WindowManager .LayoutParams .FLAG_NOT_FOCUSABLE or
122+ WindowManager .LayoutParams .FLAG_LAYOUT_IN_SCREEN ,
150123 PixelFormat .TRANSLUCENT
151124 ).apply {
152125 gravity = Gravity .TOP or Gravity .START
0 commit comments