@@ -37,7 +37,6 @@ import androidx.annotation.VisibleForTesting
37
37
import androidx.core.content.ContextCompat
38
38
import androidx.core.content.getSystemService
39
39
import androidx.work.Configuration
40
- import androidx.work.WorkManager
41
40
import com.github.shadowsocks.acl.Acl
42
41
import com.github.shadowsocks.aidl.ShadowsocksConnection
43
42
import com.github.shadowsocks.core.BuildConfig
@@ -62,14 +61,15 @@ import java.io.File
62
61
import java.io.IOException
63
62
import kotlin.reflect.KClass
64
63
65
- object Core {
64
+ object Core : Configuration.Provider {
66
65
lateinit var app: Application
67
66
@VisibleForTesting set
68
67
lateinit var configureIntent: (Context ) -> PendingIntent
69
68
val activity by lazy { app.getSystemService<ActivityManager >()!! }
70
69
val clipboard by lazy { app.getSystemService<ClipboardManager >()!! }
71
70
val connectivity by lazy { app.getSystemService<ConnectivityManager >()!! }
72
71
val notification by lazy { app.getSystemService<NotificationManager >()!! }
72
+ val user by lazy { app.getSystemService<UserManager >()!! }
73
73
val packageInfo: PackageInfo by lazy { getPackageInfo(app.packageName) }
74
74
val deviceStorage by lazy { if (Build .VERSION .SDK_INT < 24 ) app else DeviceStorageApp (app) }
75
75
val directBootSupported by lazy {
@@ -121,14 +121,11 @@ object Core {
121
121
}
122
122
}
123
123
})
124
- WorkManager .initialize(deviceStorage, Configuration .Builder ().apply {
125
- setExecutor { GlobalScope .launch { it.run () } }
126
- setTaskExecutor { GlobalScope .launch { it.run () } }
127
- }.build())
128
124
129
125
// handle data restored/crash
130
- if (Build .VERSION .SDK_INT >= 24 && DataStore .directBootAware &&
131
- app.getSystemService<UserManager >()?.isUserUnlocked == true ) DirectBoot .flushTrafficStats()
126
+ if (Build .VERSION .SDK_INT >= 24 && DataStore .directBootAware && user.isUserUnlocked) {
127
+ DirectBoot .flushTrafficStats()
128
+ }
132
129
if (DataStore .publicStore.getLong(Key .assetUpdateTime, - 1 ) != packageInfo.lastUpdateTime) {
133
130
val assetManager = app.assets
134
131
try {
@@ -143,6 +140,12 @@ object Core {
143
140
updateNotificationChannels()
144
141
}
145
142
143
+ override fun getWorkManagerConfiguration () = Configuration .Builder ().apply {
144
+ setMinimumLoggingLevel(if (BuildConfig .DEBUG ) Log .VERBOSE else Log .INFO )
145
+ setExecutor { GlobalScope .launch { it.run () } }
146
+ setTaskExecutor { GlobalScope .launch { it.run () } }
147
+ }.build()
148
+
146
149
fun updateNotificationChannels () {
147
150
if (Build .VERSION .SDK_INT >= 26 ) @RequiresApi(26 ) {
148
151
notification.createNotificationChannels(listOf (
0 commit comments