Skip to content
This repository was archived by the owner on May 17, 2025. It is now read-only.

Commit c48068c

Browse files
committed
patch 2.7
1 parent 217a305 commit c48068c

4 files changed

Lines changed: 53 additions & 176 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ android {
1818
//noinspection EditedTargetSdkVersion
1919
targetSdk = 35
2020
versionCode = 1
21-
versionName = "2.6.6"
21+
versionName = "2.7"
2222

2323
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2424

app/src/main/java/com/mucheng/mucute/client/game/RealmManager.kt

Lines changed: 0 additions & 156 deletions
This file was deleted.

app/src/main/java/com/mucheng/mucute/client/service/RelayService.kt

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ class RelayService : Service() {
3333

3434
override fun onCreate() {
3535
super.onCreate()
36-
startForegroundImmediate()
36+
37+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
38+
startForegroundImmediate()
39+
} else {
40+
startForeground(NOTIFICATION_ID, createNotification().build())
41+
}
42+
3743
createNotificationChannel()
3844

3945
wakeLock = (getSystemService(POWER_SERVICE) as PowerManager).run {
@@ -55,15 +61,27 @@ class RelayService : Service() {
5561
}
5662

5763
private fun startForegroundImmediate() {
58-
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
64+
val notification = createNotification().build()
65+
66+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
67+
startForeground(
68+
NOTIFICATION_ID,
69+
notification,
70+
ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE
71+
)
72+
} else {
73+
startForeground(NOTIFICATION_ID, notification)
74+
}
75+
}
76+
77+
private fun createNotification(): NotificationCompat.Builder {
78+
return NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
5979
.setContentTitle("MuCute Relay")
6080
.setContentText("Relay service is running")
6181
.setSmallIcon(android.R.drawable.ic_dialog_info)
6282
.setPriority(NotificationCompat.PRIORITY_HIGH)
6383
.setCategory(NotificationCompat.CATEGORY_SERVICE)
64-
.build()
65-
66-
startForeground(NOTIFICATION_ID, notification)
84+
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
6785
}
6886

6987
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
@@ -93,12 +111,7 @@ class RelayService : Service() {
93111
}
94112

95113
private fun startForegroundService() {
96-
val notification = NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID)
97-
.setContentTitle("MuCute Relay")
98-
.setContentText("Relay service is running")
99-
.setSmallIcon(android.R.drawable.ic_dialog_info)
100-
.setPriority(NotificationCompat.PRIORITY_LOW)
101-
.build()
114+
val notification = createNotification().build()
102115

103116
if (Build.VERSION.SDK_INT >= 34) {
104117
startForeground(

app/src/main/java/com/mucheng/mucute/client/service/Services.kt

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.mucheng.mucute.client.service
22

33
import android.content.Context
4+
import android.os.Build
45
import android.os.Handler
56
import android.os.Looper
67
import android.util.Log
@@ -147,19 +148,38 @@ object Services {
147148
private fun setupOverlay(context: Context) {
148149
windowManager = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
149150

150-
val params = WindowManager.LayoutParams(
151-
WindowManager.LayoutParams.MATCH_PARENT,
152-
WindowManager.LayoutParams.MATCH_PARENT,
153-
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
154-
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
155-
PixelFormat.TRANSLUCENT
156-
)
151+
val params = WindowManager.LayoutParams().apply {
152+
width = WindowManager.LayoutParams.MATCH_PARENT
153+
height = WindowManager.LayoutParams.MATCH_PARENT
154+
type = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
155+
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
156+
} else {
157+
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
158+
}
159+
flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE or
160+
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
161+
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN or
162+
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
163+
format = PixelFormat.TRANSLUCENT
164+
165+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
166+
alpha = 0.8f
167+
flags = flags or WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
168+
setFitInsetsTypes(0)
169+
setFitInsetsSides(0)
170+
}
171+
}
157172

158173
renderView = RenderOverlayView(context)
159174
ESPModule.setRenderView(renderView!!)
160175

161176
handler.post {
162-
windowManager?.addView(renderView, params)
177+
try {
178+
windowManager?.addView(renderView, params)
179+
} catch (e: Exception) {
180+
e.printStackTrace()
181+
context.toast("Failed to add overlay view: ${e.message}")
182+
}
163183
}
164184
}
165185

0 commit comments

Comments
 (0)