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

Commit fee4c32a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Minor controls fixes"

parents 75e65fa6 8b540450
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -645,7 +645,6 @@
        <activity android:name=".controls.management.ControlsProviderSelectorActivity"
                  android:label="Controls Providers"
                  android:theme="@style/Theme.ControlsManagement"
                  android:exported="true"
                  android:showForAllUsers="true"
                  android:excludeFromRecents="true"
                  android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden"
+35 −8
Original line number Diff line number Diff line
@@ -19,9 +19,12 @@ package com.android.systemui.controls.controller
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.database.ContentObserver
import android.net.Uri
import android.os.Environment
import android.os.UserHandle
import android.provider.Settings
@@ -30,6 +33,7 @@ import android.service.controls.actions.ControlAction
import android.util.ArrayMap
import android.util.Log
import com.android.internal.annotations.GuardedBy
import com.android.internal.annotations.VisibleForTesting
import com.android.systemui.DumpController
import com.android.systemui.Dumpable
import com.android.systemui.broadcast.BroadcastDispatcher
@@ -53,15 +57,16 @@ class ControlsControllerImpl @Inject constructor (
    private val uiController: ControlsUiController,
    private val bindingController: ControlsBindingController,
    private val listingController: ControlsListingController,
    broadcastDispatcher: BroadcastDispatcher,
    private val broadcastDispatcher: BroadcastDispatcher,
    optionalWrapper: Optional<ControlsFavoritePersistenceWrapper>,
    dumpController: DumpController
) : Dumpable, ControlsController {

    companion object {
        private const val TAG = "ControlsControllerImpl"
        const val CONTROLS_AVAILABLE = "systemui.controls_available"
        const val USER_CHANGE_RETRY_DELAY = 500L // ms
        internal const val CONTROLS_AVAILABLE = "systemui.controls_available"
        internal val URI = Settings.Secure.getUriFor(CONTROLS_AVAILABLE)
        private const val USER_CHANGE_RETRY_DELAY = 500L // ms
    }

    // Map of map: ComponentName -> (String -> ControlInfo).
@@ -69,9 +74,11 @@ class ControlsControllerImpl @Inject constructor (
    @GuardedBy("currentFavorites")
    private val currentFavorites = ArrayMap<ComponentName, MutableMap<String, ControlInfo>>()

    private var userChanging = true
    override var available = Settings.Secure.getInt(
            context.contentResolver, CONTROLS_AVAILABLE, 0) != 0
    private var userChanging: Boolean = true

    private val contentResolver: ContentResolver
        get() = context.contentResolver
    override var available = Settings.Secure.getInt(contentResolver, CONTROLS_AVAILABLE, 0) != 0
        private set

    private var currentUser = context.user
@@ -95,8 +102,8 @@ class ControlsControllerImpl @Inject constructor (
        val fileName = Environment.buildPath(
                userContext.filesDir, ControlsFavoritePersistenceWrapper.FILE_NAME)
        persistenceWrapper.changeFile(fileName)
        available = Settings.Secure.getIntForUser(
                context.contentResolver, CONTROLS_AVAILABLE, 0) != 0
        available = Settings.Secure.getIntForUser(contentResolver, CONTROLS_AVAILABLE,
                /* default */ 0, newUser.identifier) != 0
        synchronized(currentFavorites) {
            currentFavorites.clear()
        }
@@ -123,6 +130,25 @@ class ControlsControllerImpl @Inject constructor (
        }
    }

    @VisibleForTesting
    internal val settingObserver = object : ContentObserver(null) {
        override fun onChange(selfChange: Boolean, uri: Uri, userId: Int) {
            // Do not listen to changes in the middle of user change, those will be read by the
            // user-switch receiver.
            if (userChanging || userId != currentUserId) {
                return
            }
            available = Settings.Secure.getIntForUser(contentResolver, CONTROLS_AVAILABLE,
                    /* default */ 0, currentUserId) != 0
            synchronized(currentFavorites) {
                currentFavorites.clear()
            }
            if (available) {
                loadFavorites()
            }
        }
    }

    init {
        dumpController.registerDumpable(this)
        if (available) {
@@ -135,6 +161,7 @@ class ControlsControllerImpl @Inject constructor (
                executor,
                UserHandle.ALL
        )
        contentResolver.registerContentObserver(URI, false, settingObserver, UserHandle.USER_ALL)
    }

    private fun confirmAvailability(): Boolean {
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.service.controls.actions.ControlAction
import android.view.ViewGroup

interface ControlsUiController {
    val available: Boolean

    fun show(parent: ViewGroup)
    fun hide()
    fun onRefreshState(componentName: ComponentName, controls: List<Control>)
+3 −0
Original line number Diff line number Diff line
@@ -118,6 +118,9 @@ class ControlsUiControllerImpl @Inject constructor (
    private val controlViewsById = mutableMapOf<ControlKey, ControlViewHolder>()
    private lateinit var parent: ViewGroup

    override val available: Boolean
        get() = controlsController.get().available

    override fun show(parent: ViewGroup) {
        Log.d(TAG, "show()")

+2 −4
Original line number Diff line number Diff line
@@ -1899,9 +1899,7 @@ public class GlobalActionsDialog implements DialogInterface.OnDismissListener,
    }

    private boolean shouldShowControls() {
        return isCurrentUserOwner()
                && !mKeyguardManager.isDeviceLocked()
                && Settings.Secure.getInt(mContext.getContentResolver(),
                        "systemui.controls_available", 0) == 1;
        return !mKeyguardManager.isDeviceLocked()
                && mControlsUiController.getAvailable();
    }
}
Loading