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

Commit 4099e24d 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: Ifce19a7d4a41e40740ee86f03789a2072f2af7e2
parents 157dd4d3 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,