From c4d1adb0baf1c9239e1453c2be042f1eecdd79c1 Mon Sep 17 00:00:00 2001 From: "Kresten P. Vester" Date: Mon, 10 Aug 2020 14:26:22 +0200 Subject: [PATCH] Cleanup with android studio --- .../geofencing/GeofencingBroadcastReceiver.kt | 2 +- .../plugins/geofencing/GeofencingPlugin.kt | 417 +++++++++--------- .../GeofencingRebootBroadcastReceiver.kt | 12 +- .../plugins/geofencing/GeofencingService.kt | 18 +- .../geofencing/IsolateHolderService.kt | 18 +- 5 files changed, 238 insertions(+), 229 deletions(-) diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingBroadcastReceiver.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingBroadcastReceiver.kt index a937b494..ba73fd64 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingBroadcastReceiver.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingBroadcastReceiver.kt @@ -7,7 +7,6 @@ package io.flutter.plugins.geofencing import android.content.BroadcastReceiver import android.content.Context import android.content.Intent -import android.util.Log import io.flutter.view.FlutterMain @@ -15,6 +14,7 @@ class GeofencingBroadcastReceiver : BroadcastReceiver() { companion object { private const val TAG = "GeofencingBroadcastReceiver" } + override fun onReceive(context: Context, intent: Intent) { FlutterMain.ensureInitializationComplete(context, null) GeofencingService.enqueueWork(context, intent) diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt index fc47ade7..6479879d 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingPlugin.kt @@ -16,238 +16,245 @@ import com.google.android.gms.location.Geofence import com.google.android.gms.location.GeofencingClient import com.google.android.gms.location.GeofencingRequest import com.google.android.gms.location.LocationServices +import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.PluginRegistry.Registrar import org.json.JSONArray class GeofencingPlugin(context: Context, activity: Activity?) : MethodCallHandler { - private val mContext = context - private val mActivity = activity - private val mGeofencingClient = LocationServices.getGeofencingClient(mContext) - - companion object { - @JvmStatic - private val TAG = "GeofencingPlugin" - @JvmStatic - val SHARED_PREFERENCES_KEY = "geofencing_plugin_cache" - @JvmStatic - val CALLBACK_HANDLE_KEY = "callback_handle" - @JvmStatic - val CALLBACK_DISPATCHER_HANDLE_KEY = "callback_dispatch_handler" - @JvmStatic - val PERSISTENT_GEOFENCES_KEY = "persistent_geofences" - @JvmStatic - val PERSISTENT_GEOFENCES_IDS = "persistent_geofences_ids" - @JvmStatic - private val REQUIRED_PERMISSIONS = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION) - @JvmStatic - private val sGeofenceCacheLock = Object() - - @JvmStatic - fun registerWith(registrar: Registrar) { - val plugin = GeofencingPlugin(registrar.context(), registrar.activity()) - val channel = MethodChannel(registrar.messenger(), "plugins.flutter.io/geofencing_plugin") - channel.setMethodCallHandler(plugin) - } + private val mContext = context + private val mActivity = activity + private val mGeofencingClient = LocationServices.getGeofencingClient(mContext) - @JvmStatic - fun reRegisterAfterReboot(context: Context) { - synchronized(sGeofenceCacheLock) { - var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) - if (persistentGeofences == null) { - return - } - for (id in persistentGeofences) { - val gfJson = p.getString(getPersistentGeofenceKey(id), null) - if (gfJson == null) { - continue - } - val gfArgs = JSONArray(gfJson) - val list = ArrayList() - for (i in 0 until gfArgs.length()) { - list.add(gfArgs.get(i) as Object) - } - val geoClient = LocationServices.getGeofencingClient(context) - registerGeofence(context, geoClient, list, null, false) + companion object { + @JvmStatic + private val TAG = "GeofencingPlugin" + + @JvmStatic + val SHARED_PREFERENCES_KEY = "geofencing_plugin_cache" + + @JvmStatic + val CALLBACK_HANDLE_KEY = "callback_handle" + + @JvmStatic + val CALLBACK_DISPATCHER_HANDLE_KEY = "callback_dispatch_handler" + + @JvmStatic + val PERSISTENT_GEOFENCES_KEY = "persistent_geofences" + + @JvmStatic + val PERSISTENT_GEOFENCES_IDS = "persistent_geofences_ids" + + @JvmStatic + private val REQUIRED_PERMISSIONS = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION) + + @JvmStatic + private val sGeofenceCacheLock = Object() + + @JvmStatic + fun registerWith(registrar: Registrar) { + val plugin = GeofencingPlugin(registrar.context(), registrar.activity()) + val channel = MethodChannel(registrar.messenger(), "plugins.flutter.io/geofencing_plugin") + channel.setMethodCallHandler(plugin) } - } - } - @JvmStatic - private fun registerGeofence(context: Context, - geofencingClient: GeofencingClient, - args: ArrayList<*>?, - result: Result?, - cache: Boolean) { - val callbackHandle = args!![0] as Long - val id = args[1] as String - val lat = args[2] as Double - val long = args[3] as Double - val radius = (args[4] as Number).toFloat() - val fenceTriggers = args[5] as Int - val initialTriggers = args[6] as Int - val expirationDuration = (args[7] as Int).toLong() - val loiteringDelay = args[8] as Int - val notificationResponsiveness = args[9] as Int - val geofence = Geofence.Builder() - .setRequestId(id) - .setCircularRegion(lat, long, radius) - .setTransitionTypes(fenceTriggers) - .setLoiteringDelay(loiteringDelay) - .setNotificationResponsiveness(notificationResponsiveness) - .setExpirationDuration(expirationDuration) - .build() - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && - (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) - == PackageManager.PERMISSION_DENIED)) { - val msg = "'registerGeofence' requires the ACCESS_FINE_LOCATION permission." - Log.w(TAG, msg) - result?.error(msg, null, null) - } - geofencingClient.addGeofences(getGeofencingRequest(geofence, initialTriggers), - getGeofencePendingIndent(context, callbackHandle))?.run { - addOnSuccessListener { - Log.i(TAG, "Successfully added geofence") - if (cache) { - addGeofenceToCache(context, id, args) - } - result?.success(true) + @JvmStatic + fun reRegisterAfterReboot(context: Context) { + synchronized(sGeofenceCacheLock) { + var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) + if (persistentGeofences == null) { + return + } + for (id in persistentGeofences) { + val gfJson = p.getString(getPersistentGeofenceKey(id), null) + if (gfJson == null) { + continue + } + val gfArgs = JSONArray(gfJson) + val list = ArrayList() + for (i in 0 until gfArgs.length()) { + list.add(gfArgs.get(i) as Object) + } + val geoClient = LocationServices.getGeofencingClient(context) + registerGeofence(context, geoClient, list, null, false) + } + } } - addOnFailureListener { - Log.e(TAG, "Failed to add geofence: $it") - result?.error(it.toString(), null, null) + + @JvmStatic + private fun registerGeofence(context: Context, + geofencingClient: GeofencingClient, + args: ArrayList<*>?, + result: Result?, + cache: Boolean) { + val callbackHandle = args!![0] as Long + val id = args[1] as String + val lat = args[2] as Double + val long = args[3] as Double + val radius = (args[4] as Number).toFloat() + val fenceTriggers = args[5] as Int + val initialTriggers = args[6] as Int + val expirationDuration = (args[7] as Int).toLong() + val loiteringDelay = args[8] as Int + val notificationResponsiveness = args[9] as Int + val geofence = Geofence.Builder() + .setRequestId(id) + .setCircularRegion(lat, long, radius) + .setTransitionTypes(fenceTriggers) + .setLoiteringDelay(loiteringDelay) + .setNotificationResponsiveness(notificationResponsiveness) + .setExpirationDuration(expirationDuration) + .build() + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && + (context.checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) + == PackageManager.PERMISSION_DENIED)) { + val msg = "'registerGeofence' requires the ACCESS_FINE_LOCATION permission." + Log.w(TAG, msg) + result.error(msg, null, null) + } + geofencingClient.addGeofences(getGeofencingRequest(geofence, initialTriggers), + getGeofencePendingIndent(context, callbackHandle))?.run { + addOnSuccessListener { + Log.i(TAG, "Successfully added geofence") + if (cache) { + addGeofenceToCache(context, id, args) + } + result.success(true) + } + addOnFailureListener { + Log.e(TAG, "Failed to add geofence: $it") + result.error(it.toString(), null, null) + } + } } - } - } - @JvmStatic - private fun addGeofenceToCache(context: Context, id: String, args: ArrayList<*>) { - synchronized(sGeofenceCacheLock) { - var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - var obj = JSONArray(args) - var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) - if (persistentGeofences == null) { - persistentGeofences = HashSet() - } else { - persistentGeofences = HashSet(persistentGeofences) + @JvmStatic + private fun addGeofenceToCache(context: Context, id: String, args: ArrayList<*>) { + synchronized(sGeofenceCacheLock) { + var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + var obj = JSONArray(args) + var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) + if (persistentGeofences == null) { + persistentGeofences = HashSet() + } else { + persistentGeofences = HashSet(persistentGeofences) + } + persistentGeofences.add(id) + context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + .edit() + .putStringSet(PERSISTENT_GEOFENCES_IDS, persistentGeofences) + .putString(getPersistentGeofenceKey(id), obj.toString()) + .apply() + } } - persistentGeofences.add(id) - context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - .edit() - .putStringSet(PERSISTENT_GEOFENCES_IDS, persistentGeofences) - .putString(getPersistentGeofenceKey(id), obj.toString()) - .apply() - } - } - @JvmStatic - private fun initializeService(context: Context, args: ArrayList<*>?) { - Log.d(TAG, "Initializing GeofencingService") - val callbackHandle = args!![0] as Long - context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - .edit() - .putLong(CALLBACK_DISPATCHER_HANDLE_KEY, callbackHandle) - .apply() - } + @JvmStatic + private fun initializeService(context: Context, args: ArrayList<*>?) { + Log.d(TAG, "Initializing GeofencingService") + val callbackHandle = args!![0] as Long + context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + .edit() + .putLong(CALLBACK_DISPATCHER_HANDLE_KEY, callbackHandle) + .apply() + } - @JvmStatic - private fun getGeofencingRequest(geofence: Geofence, initialTrigger: Int): GeofencingRequest { - return GeofencingRequest.Builder().apply { - setInitialTrigger(initialTrigger) - addGeofence(geofence) - }.build() - } + @JvmStatic + private fun getGeofencingRequest(geofence: Geofence, initialTrigger: Int): GeofencingRequest { + return GeofencingRequest.Builder().apply { + setInitialTrigger(initialTrigger) + addGeofence(geofence) + }.build() + } - @JvmStatic - private fun getGeofencePendingIndent(context: Context, callbackHandle: Long): PendingIntent { - val intent = Intent(context, GeofencingBroadcastReceiver::class.java) - .putExtra(CALLBACK_HANDLE_KEY, callbackHandle) - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) - } + @JvmStatic + private fun getGeofencePendingIndent(context: Context, callbackHandle: Long): PendingIntent { + val intent = Intent(context, GeofencingBroadcastReceiver::class.java) + .putExtra(CALLBACK_HANDLE_KEY, callbackHandle) + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + } - @JvmStatic - private fun removeGeofence(context: Context, - geofencingClient: GeofencingClient, - args: ArrayList<*>?, - result: Result) { - val ids = listOf(args!![0] as String) - geofencingClient.removeGeofences(ids).run { - addOnSuccessListener { - for (id in ids) { - removeGeofenceFromCache(context, id) - } - result.success(true) + @JvmStatic + private fun removeGeofence(context: Context, + geofencingClient: GeofencingClient, + args: ArrayList<*>?, + result: Result) { + val ids = listOf(args!![0] as String) + geofencingClient.removeGeofences(ids).run { + addOnSuccessListener { + for (id in ids) { + removeGeofenceFromCache(context, id) + } + result.success(true) + } + addOnFailureListener { + result.error(it.toString(), null, null) + } + } } - addOnFailureListener { - result.error(it.toString(), null, null) + + @JvmStatic + private fun getRegisteredGeofenceIds(context: Context, result: Result) { + synchronized(sGeofenceCacheLock) { + val list = ArrayList() + var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) + if (persistentGeofences != null && persistentGeofences.size > 0) { + for (id in persistentGeofences) { + list.add(id) + } + } + result.success(list) + } } - } - } - @JvmStatic - private fun getRegisteredGeofenceIds(context: Context, result: Result) { - synchronized(sGeofenceCacheLock) { - val list = ArrayList() - var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) - if (persistentGeofences != null && persistentGeofences.size > 0) { - for (id in persistentGeofences) { - list.add(id) - } + @JvmStatic + private fun removeGeofenceFromCache(context: Context, id: String) { + synchronized(sGeofenceCacheLock) { + var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) + var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) + if (persistentGeofences == null) { + return + } + persistentGeofences = HashSet(persistentGeofences) + persistentGeofences.remove(id) + p.edit() + .remove(getPersistentGeofenceKey(id)) + .putStringSet(PERSISTENT_GEOFENCES_IDS, persistentGeofences) + .apply() + } } - result.success(list) - } - } - @JvmStatic - private fun removeGeofenceFromCache(context: Context, id: String) { - synchronized(sGeofenceCacheLock) { - var p = context.getSharedPreferences(SHARED_PREFERENCES_KEY, Context.MODE_PRIVATE) - var persistentGeofences = p.getStringSet(PERSISTENT_GEOFENCES_IDS, null) - if (persistentGeofences == null) { - return + @JvmStatic + private fun getPersistentGeofenceKey(id: String): String { + return "persistent_geofence/" + id } - persistentGeofences = HashSet(persistentGeofences) - persistentGeofences.remove(id) - p.edit() - .remove(getPersistentGeofenceKey(id)) - .putStringSet(PERSISTENT_GEOFENCES_IDS, persistentGeofences) - .apply() - } } - @JvmStatic - private fun getPersistentGeofenceKey(id: String): String { - return "persistent_geofence/" + id - } - } - - override fun onMethodCall(call: MethodCall, result: Result) { - val args = call.arguments>() - when(call.method) { - "GeofencingPlugin.initializeService" -> { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - mActivity?.requestPermissions(REQUIRED_PERMISSIONS, 12312) + override fun onMethodCall(call: MethodCall, result: Result) { + val args = call.arguments>() + when (call.method) { + "GeofencingPlugin.initializeService" -> { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + mActivity?.requestPermissions(REQUIRED_PERMISSIONS, 12312) + } + initializeService(mContext, args) + result.success(true) + } + "GeofencingPlugin.registerGeofence" -> registerGeofence(mContext, + mGeofencingClient, + args, + result, + true) + "GeofencingPlugin.removeGeofence" -> removeGeofence(mContext, + mGeofencingClient, + args, + result) + "GeofencingPlugin.getRegisteredGeofenceIds" -> getRegisteredGeofenceIds(mContext, result) + else -> result.notImplemented() } - initializeService(mContext, args) - result.success(true) - } - "GeofencingPlugin.registerGeofence" -> registerGeofence(mContext, - mGeofencingClient, - args, - result, - true) - "GeofencingPlugin.removeGeofence" -> removeGeofence(mContext, - mGeofencingClient, - args, - result) - "GeofencingPlugin.getRegisteredGeofenceIds" -> getRegisteredGeofenceIds(mContext, result) - else -> result.notImplemented() } - } } \ No newline at end of file diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingRebootBroadcastReceiver.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingRebootBroadcastReceiver.kt index 5b8cd0fa..9bcb601e 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingRebootBroadcastReceiver.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingRebootBroadcastReceiver.kt @@ -2,16 +2,16 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -package io.flutter.plugins.geofencing; +package io.flutter.plugins.geofencing -import android.content.BroadcastReceiver; -import android.content.Context; -import android.content.Intent; -import android.util.Log; +import android.content.BroadcastReceiver +import android.content.Context +import android.content.Intent +import android.util.Log class GeofencingRebootBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { - if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) { + if (intent.action.equals("android.intent.action.BOOT_COMPLETED")) { Log.e("GEOFENCING REBOOT", "Reregistering geofences!") GeofencingPlugin.reRegisterAfterReboot(context) } diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingService.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingService.kt index db6b2fc2..70e0bb9f 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingService.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/GeofencingService.kt @@ -6,25 +6,22 @@ package io.flutter.plugins.geofencing import android.content.Context import android.content.Intent -import android.os.IBinder -import android.os.PowerManager import android.os.Handler import android.util.Log import androidx.core.app.JobIntentService +import com.google.android.gms.location.GeofencingEvent +import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.MethodChannel import io.flutter.plugin.common.MethodChannel.MethodCallHandler import io.flutter.plugin.common.MethodChannel.Result -import io.flutter.plugin.common.MethodCall import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback import io.flutter.view.FlutterCallbackInformation import io.flutter.view.FlutterMain import io.flutter.view.FlutterNativeView import io.flutter.view.FlutterRunArguments import java.util.ArrayDeque -import java.util.concurrent.atomic.AtomicBoolean import java.util.UUID - -import com.google.android.gms.location.GeofencingEvent +import java.util.concurrent.atomic.AtomicBoolean class GeofencingService : MethodCallHandler, JobIntentService() { private val queue = ArrayDeque>() @@ -34,10 +31,13 @@ class GeofencingService : MethodCallHandler, JobIntentService() { companion object { @JvmStatic private val TAG = "GeofencingService" + @JvmStatic private val JOB_ID = UUID.randomUUID().mostSignificantBits.toInt() + @JvmStatic private var sBackgroundFlutterView: FlutterNativeView? = null + @JvmStatic private val sServiceStarted = AtomicBoolean(false) @@ -88,8 +88,8 @@ class GeofencingService : MethodCallHandler, JobIntentService() { mBackgroundChannel.setMethodCallHandler(this) } - override fun onMethodCall(call: MethodCall, result: Result) { - when(call.method) { + override fun onMethodCall(call: MethodCall, result: Result) { + when (call.method) { "GeofencingService.initialized" -> { synchronized(sServiceStarted) { while (!queue.isEmpty()) { @@ -103,7 +103,7 @@ class GeofencingService : MethodCallHandler, JobIntentService() { } "GeofencingService.demoteToBackground" -> { val intent = Intent(mContext, IsolateHolderService::class.java) - intent.setAction(IsolateHolderService.ACTION_SHUTDOWN) + intent.action = IsolateHolderService.ACTION_SHUTDOWN mContext.startForegroundService(intent) } else -> result.notImplemented() diff --git a/android/src/main/kotlin/io/flutter/plugins/geofencing/IsolateHolderService.kt b/android/src/main/kotlin/io/flutter/plugins/geofencing/IsolateHolderService.kt index c94b9634..cd68b782 100644 --- a/android/src/main/kotlin/io/flutter/plugins/geofencing/IsolateHolderService.kt +++ b/android/src/main/kotlin/io/flutter/plugins/geofencing/IsolateHolderService.kt @@ -12,17 +12,19 @@ import android.content.Intent import android.os.IBinder import android.os.PowerManager import androidx.core.app.NotificationCompat -import android.util.Log import io.flutter.view.FlutterNativeView class IsolateHolderService : Service() { companion object { @JvmStatic val ACTION_SHUTDOWN = "SHUTDOWN" + @JvmStatic private val WAKELOCK_TAG = "IsolateHolderService::WAKE_LOCK" + @JvmStatic private val TAG = "IsolateHolderService" + @JvmStatic private var sBackgroundFlutterView: FlutterNativeView? = null @@ -32,8 +34,8 @@ class IsolateHolderService : Service() { } } - override fun onBind(p0: Intent) : IBinder? { - return null; + override fun onBind(p0: Intent): IBinder? { + return null } override fun onCreate() { @@ -42,7 +44,7 @@ class IsolateHolderService : Service() { val channel = NotificationChannel(CHANNEL_ID, "Flutter Geofencing Plugin", NotificationManager.IMPORTANCE_LOW) - val imageId = getResources().getIdentifier("ic_launcher", "mipmap", getPackageName()) + val imageId = resources.getIdentifier("ic_launcher", "mipmap", packageName) (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).createNotificationChannel(channel) val notification = NotificationCompat.Builder(this, CHANNEL_ID) @@ -61,11 +63,11 @@ class IsolateHolderService : Service() { startForeground(1, notification) } - override fun onStartCommand(intent: Intent, flags: Int, startId: Int) : Int { - if (intent.getAction() == ACTION_SHUTDOWN) { + override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { + if (intent.action == ACTION_SHUTDOWN) { (getSystemService(Context.POWER_SERVICE) as PowerManager).run { newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, WAKELOCK_TAG).apply { - if (isHeld()) { + if (isHeld) { release() } } @@ -73,6 +75,6 @@ class IsolateHolderService : Service() { stopForeground(true) stopSelf() } - return START_STICKY; + return START_STICKY } }