Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 378d5ec3 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Automerger Merge Worker
Browse files

Merge "Remove controls when apps are stopped or removed" into rvc-dev am: a56a27a9

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11839914

Change-Id: Id09f48126c9c6ba339757828e0a875220e52163c
parents d6706ad5 a56a27a9
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -109,6 +109,24 @@ class MediaDataManager @Inject constructor(
        }
    }

    private val appChangeReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            when (intent.action) {
                Intent.ACTION_PACKAGES_SUSPENDED -> {
                    val packages = intent.getStringArrayExtra(Intent.EXTRA_CHANGED_PACKAGE_LIST)
                    packages?.forEach {
                        removeAllForPackage(it)
                    }
                }
                Intent.ACTION_PACKAGE_REMOVED, Intent.ACTION_PACKAGE_RESTARTED -> {
                    intent.data?.encodedSchemeSpecificPart?.let {
                        removeAllForPackage(it)
                    }
                }
            }
        }
    }

    init {
        mediaTimeoutListener.timeoutCallback = { token: String, timedOut: Boolean ->
            setTimedOut(token, timedOut) }
@@ -129,6 +147,17 @@ class MediaDataManager @Inject constructor(

        val userFilter = IntentFilter(Intent.ACTION_USER_SWITCHED)
        broadcastDispatcher.registerReceiver(userChangeReceiver, userFilter, null, UserHandle.ALL)

        val suspendFilter = IntentFilter(Intent.ACTION_PACKAGES_SUSPENDED)
        broadcastDispatcher.registerReceiver(appChangeReceiver, suspendFilter, null, UserHandle.ALL)

        val uninstallFilter = IntentFilter().apply {
            addAction(Intent.ACTION_PACKAGE_REMOVED)
            addAction(Intent.ACTION_PACKAGE_RESTARTED)
            addDataScheme("package")
        }
        // BroadcastDispatcher does not allow filters with data schemes
        context.registerReceiver(appChangeReceiver, uninstallFilter)
    }

    fun onNotificationAdded(key: String, sbn: StatusBarNotification) {
@@ -160,6 +189,18 @@ class MediaDataManager @Inject constructor(
        mediaEntries.clear()
    }

    private fun removeAllForPackage(packageName: String) {
        Assert.isMainThread()
        val listenersCopy = listeners.toSet()
        val toRemove = mediaEntries.filter { it.value.packageName == packageName }
        toRemove.forEach {
            mediaEntries.remove(it.key)
            listenersCopy.forEach { listener ->
                listener.onMediaDataRemoved(it.key)
            }
        }
    }

    private fun addResumptionControls(
        desc: MediaDescription,
        action: Runnable,