Use ContextCompat.getSystemService
This commit is contained in:
@@ -36,6 +36,7 @@ import com.github.shadowsocks.R
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
||||
import com.github.shadowsocks.utils.Action
|
||||
import com.github.shadowsocks.utils.broadcastReceiver
|
||||
import com.github.shadowsocks.utils.systemService
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@@ -46,7 +47,7 @@ import java.util.*
|
||||
*/
|
||||
class ServiceNotification(private val service: BaseService.Interface, profileName: String,
|
||||
channel: String, private val visible: Boolean = false) {
|
||||
private val keyGuard = (service as Context).getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager
|
||||
private val keyGuard = (service as Context).systemService<KeyguardManager>()
|
||||
private val nm by lazy {
|
||||
(service as Context).getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
}
|
||||
@@ -82,7 +83,7 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
|
||||
service as Context
|
||||
if (Build.VERSION.SDK_INT < 24) builder.addAction(R.drawable.ic_navigation_close,
|
||||
service.getString(R.string.stop), PendingIntent.getBroadcast(service, 0, Intent(Action.CLOSE), 0))
|
||||
val power = service.getSystemService(Context.POWER_SERVICE) as PowerManager
|
||||
val power = service.systemService<PowerManager>()
|
||||
update(if (power.isInteractive) Intent.ACTION_SCREEN_ON else Intent.ACTION_SCREEN_OFF, true)
|
||||
val screenFilter = IntentFilter()
|
||||
screenFilter.addAction(Intent.ACTION_SCREEN_ON)
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
package com.github.shadowsocks.bg
|
||||
|
||||
import android.app.KeyguardManager
|
||||
import android.content.Context
|
||||
import android.graphics.drawable.Icon
|
||||
import android.service.quicksettings.Tile
|
||||
import android.support.annotation.RequiresApi
|
||||
@@ -31,6 +30,7 @@ import com.github.shadowsocks.ShadowsocksConnection
|
||||
import com.github.shadowsocks.aidl.IShadowsocksService
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
||||
import com.github.shadowsocks.preference.DataStore
|
||||
import com.github.shadowsocks.utils.systemService
|
||||
import android.service.quicksettings.TileService as BaseTileService
|
||||
|
||||
@RequiresApi(24)
|
||||
@@ -38,7 +38,7 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
|
||||
private val iconIdle by lazy { Icon.createWithResource(this, R.drawable.ic_service_idle) }
|
||||
private val iconBusy by lazy { Icon.createWithResource(this, R.drawable.ic_service_busy) }
|
||||
private val iconConnected by lazy { Icon.createWithResource(this, R.drawable.ic_service_active) }
|
||||
private val keyguard by lazy { getSystemService(Context.KEYGUARD_SERVICE) as KeyguardManager }
|
||||
private val keyguard by lazy { systemService<KeyguardManager>() }
|
||||
|
||||
override val serviceCallback: IShadowsocksServiceCallback.Stub by lazy {
|
||||
@RequiresApi(24)
|
||||
|
||||
@@ -22,7 +22,6 @@ package com.github.shadowsocks.bg
|
||||
|
||||
import android.annotation.TargetApi
|
||||
import android.app.Service
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.*
|
||||
@@ -40,6 +39,7 @@ import com.github.shadowsocks.acl.Acl
|
||||
import com.github.shadowsocks.preference.DataStore
|
||||
import com.github.shadowsocks.utils.Subnet
|
||||
import com.github.shadowsocks.utils.parseNumericAddress
|
||||
import com.github.shadowsocks.utils.systemService
|
||||
import java.io.File
|
||||
import java.io.FileDescriptor
|
||||
import java.io.IOException
|
||||
@@ -108,7 +108,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
private var worker: ProtectWorker? = null
|
||||
private var tun2socksProcess: GuardedProcess? = null
|
||||
|
||||
private val connectivity by lazy { getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
|
||||
private val connectivity by lazy { systemService<ConnectivityManager>() }
|
||||
@TargetApi(Build.VERSION_CODES.P)
|
||||
private val defaultNetworkCallback = object : ConnectivityManager.NetworkCallback() {
|
||||
override fun onAvailable(network: Network) {
|
||||
|
||||
Reference in New Issue
Block a user