Skip to content

Commit

Permalink
💥 improve perf
Browse files Browse the repository at this point in the history
  • Loading branch information
Szzrain committed Apr 4, 2024
1 parent b9e6eb2 commit 1968c01
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
minSdk 26
//noinspection ExpiredTargetSdkVersion
targetSdk 28
versionCode 40
versionName "v0.6.1-rc1"
versionCode 44
versionName "v0.6.1-rc6"
buildConfigField "String", "DOCUMENTS_AUTHORITY", "\"com.sealdice.dice.authorities\""
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
externalNativeBuild {
Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/com/sealdice/dice/ProcessService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class ProcessService : LifecycleService(){
private var isRunning = false
private var shellLogs = ""
private lateinit var player: MediaPlayer
private lateinit var wakeLock: PowerManager.WakeLock
private lateinit var networkCallback: ConnectivityManager.NetworkCallback
private lateinit var notification : Notification

private lateinit var windowManager: WindowManager
private var floatRootView: View? = null//悬浮窗View
Expand Down Expand Up @@ -153,7 +156,7 @@ class ProcessService : LifecycleService(){
val notificationChannel = NotificationChannel("sealdice","SealDice", NotificationManager.IMPORTANCE_HIGH)
mNotificationManager.createNotificationChannel(notificationChannel)
val pendingIntent = PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, NotificationActivity::class.java), PendingIntent.FLAG_MUTABLE)
val notification: Notification = Notification.Builder(this,"sealdice")
notification = Notification.Builder(this,"sealdice")
.setContentTitle("SealDice is running")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentIntent(pendingIntent)
Expand All @@ -162,7 +165,7 @@ class ProcessService : LifecycleService(){
}
else {
val pendingIntent = PendingIntent.getActivity(applicationContext, 0, Intent(applicationContext, NotificationActivity::class.java), PendingIntent.FLAG_MUTABLE)
val notification: Notification = Notification.Builder(this)
notification = Notification.Builder(this)
.setContentTitle("SealDice is running")
.setSmallIcon(R.drawable.ic_launcher_foreground)
.setContentIntent(pendingIntent)
Expand All @@ -176,14 +179,14 @@ class ProcessService : LifecycleService(){
}
if (intent.getBooleanExtra("alive_wakelock", false)) {
val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
val wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sealdice:LocationManagerService")
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "sealdice:LocationManagerService")
wakeLock.acquire()
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.build()

val networkCallback = object : ConnectivityManager.NetworkCallback() {
networkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
// Network is now available
}
Expand Down Expand Up @@ -243,6 +246,13 @@ class ProcessService : LifecycleService(){
}
override fun onDestroy() {
super.onDestroy()
player.stop()
stopForeground(STOP_FOREGROUND_REMOVE)
if (wakeLock.isHeld) {
wakeLock.release()
}
val connectivityManager = getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
connectivityManager.unregisterNetworkCallback(networkCallback)
stopProcess()
}
}

0 comments on commit 1968c01

Please sign in to comment.