/*
- * Copyright © 2021 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2021-2023 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
*
val realtimeMonitoring = sharedPreferences.getBoolean(applicationContext.getString(R.string.realtime_monitoring_key), true)
// Perform the functions according to the realtime monitoring status.
+ @Suppress("DEPRECATION") // The deprecated `getRunningServices()` now only returns services started by Privacy Cell, but that is all we want to know anyway.
if (realtimeMonitoring) { // Realtime monitoring is enabled.
// Get a handle for the activity manager.
val activityManager: ActivityManager = applicationContext.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
- // Get a list of the running service info. The deprecated `getRunningServices()` now only returns services stared by Privacy Cell, but that is all we want to know anyway.
+ // Get a list of the running service info. The deprecated `getRunningServices()` now only returns services started by Privacy Cell, but that is all we want to know anyway.
val runningServiceInfoList: List<ActivityManager.RunningServiceInfo> = activityManager.getRunningServices(1)
// Check to see if the service is currently running.
applicationContext.bindService(Intent(applicationContext, RealtimeMonitoringService::class.java), serviceConnection, 0)
}
} else { // Realtime monitoring is disabled.
+ // Stop the realtime monitoring service.
+ applicationContext.stopService(Intent(applicationContext, RealtimeMonitoringService::class.java))
+
// Cancel the realtime listener work request.
WorkManager.getInstance(applicationContext).cancelUniqueWork(applicationContext.getString(R.string.register_listener_work_request))
}
// Return a success.
return Result.success()
}
-}
\ No newline at end of file
+}