diff options
Diffstat (limited to 'PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt')
-rw-r--r-- | PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt b/PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt index b2e0236fa..09a7bb1e4 100644 --- a/PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt +++ b/PermissionController/src/com/android/permissioncontroller/permission/data/PackageBroadcastReceiver.kt @@ -29,31 +29,24 @@ import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch -/** - * Listens for package additions, replacements, and removals, and notifies listeners. - */ +/** Listens for package additions, replacements, and removals, and notifies listeners. */ object PackageBroadcastReceiver : BroadcastReceiver() { private val app: Application = PermissionControllerApplication.get() - private val intentFilter = IntentFilter(Intent.ACTION_PACKAGE_ADDED).apply { - addAction(Intent.ACTION_PACKAGE_REMOVED) - addAction(Intent.ACTION_PACKAGE_REPLACED) - addAction(Intent.ACTION_PACKAGE_CHANGED) - addDataScheme("package") - } + private val intentFilter = + IntentFilter(Intent.ACTION_PACKAGE_ADDED).apply { + addAction(Intent.ACTION_PACKAGE_REMOVED) + addAction(Intent.ACTION_PACKAGE_REPLACED) + addAction(Intent.ACTION_PACKAGE_CHANGED) + addDataScheme("package") + } - /** - * Map<packageName, callbacks listenening to package> - */ + /** Map<packageName, callbacks listenening to package> */ private val changeCallbacks = mutableMapOf<String, MutableSet<PackageBroadcastListener>>() - /** - * A list of listener IDs, which listen to all package additions, changes, and removals. - */ + /** A list of listener IDs, which listen to all package additions, changes, and removals. */ private val allCallbacks = mutableSetOf<PackageBroadcastListener>() - /** - * Add a callback which will be notified when the specified packaged is changed or removed. - */ + /** Add a callback which will be notified when the specified packaged is changed or removed. */ fun addChangeCallback(packageName: String, listener: PackageBroadcastListener) { GlobalScope.launch(Main.immediate) { val wasEmpty = hasNoListeners() @@ -61,8 +54,12 @@ object PackageBroadcastReceiver : BroadcastReceiver() { changeCallbacks.getOrPut(packageName, { mutableSetOf() }).add(listener) if (wasEmpty) { - app.applicationContext.registerReceiverForAllUsers(this@PackageBroadcastReceiver, - intentFilter, null, null) + app.applicationContext.registerReceiverForAllUsers( + this@PackageBroadcastReceiver, + intentFilter, + null, + null + ) } } } @@ -80,8 +77,12 @@ object PackageBroadcastReceiver : BroadcastReceiver() { allCallbacks.add(listener) if (wasEmpty) { - app.applicationContext.registerReceiverForAllUsers(this@PackageBroadcastReceiver, - intentFilter, null, null) + app.applicationContext.registerReceiverForAllUsers( + this@PackageBroadcastReceiver, + intentFilter, + null, + null + ) } } } @@ -171,9 +172,7 @@ object PackageBroadcastReceiver : BroadcastReceiver() { } } - /** - * A listener interface for objects desiring to be notified of package broadcasts. - */ + /** A listener interface for objects desiring to be notified of package broadcasts. */ interface PackageBroadcastListener { /** * To be called when a specific package has been changed, or when any package has been |