X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyCell.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacycell%2Fworkers%2FRegisterRealtimeListenerWorker.kt;h=7eeea89b2dfb22e54844605e361477a65995e682;hp=7fe86d028b06ede04598f9bff6f24642cb06b851;hb=HEAD;hpb=9ee51bf9fbf3ef3e463456c4a4e4ef626eab3412 diff --git a/app/src/main/java/com/stoutner/privacycell/workers/RegisterRealtimeListenerWorker.kt b/app/src/main/java/com/stoutner/privacycell/workers/RegisterRealtimeListenerWorker.kt index 7fe86d0..7eeea89 100644 --- a/app/src/main/java/com/stoutner/privacycell/workers/RegisterRealtimeListenerWorker.kt +++ b/app/src/main/java/com/stoutner/privacycell/workers/RegisterRealtimeListenerWorker.kt @@ -1,5 +1,5 @@ /* - * Copyright © 2021 Soren Stoutner . + * Copyright 2021-2023 Soren Stoutner . * * This file is part of Privacy Cell . * @@ -46,11 +46,12 @@ class RegisterRealtimeListenerWorker(appContext: Context, workerParameters: Work 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.getRunningServices(1) // Check to see if the service is currently running. @@ -76,6 +77,9 @@ class RegisterRealtimeListenerWorker(appContext: Context, workerParameters: Work // Register the telephony manager listener. realtimeMonitoringService.registerTelephonyManagerListener() + // Populate the notification, which might have been accidentally dismissed by the user beginning in Android 14. + realtimeMonitoringService.populateNotification() + // Unbind the service. applicationContext.unbindService(this) } @@ -89,6 +93,9 @@ class RegisterRealtimeListenerWorker(appContext: Context, workerParameters: Work 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)) } @@ -96,4 +103,4 @@ class RegisterRealtimeListenerWorker(appContext: Context, workerParameters: Work // Return a success. return Result.success() } -} \ No newline at end of file +}