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

Commit a2be0990 authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Remove "Device Controls" from Settings" into sc-dev

parents 6b0cff16 73702413
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -9428,9 +9428,12 @@ public final class Settings {
         * 0 indicates disabled and 1 indicates enabled. A non existent value should be treated as
         * enabled.
         *
         * @deprecated Controls are migrated to Quick Settings, rendering this unnecessary and will
         *             be removed in a future release.
         * @hide
         */
        @Readable
        @Deprecated
        public static final String CONTROLS_ENABLED = "controls_enabled";
        /**
+0 −5
Original line number Diff line number Diff line
@@ -40,11 +40,6 @@ import java.util.function.Consumer
 */
interface ControlsController : UserAwareController {

    /**
     * Whether the controls system is available for the current user.
     */
    val available: Boolean

    // SERVICE COMMUNICATION

    /**
+6 −26
Original line number Diff line number Diff line
@@ -28,7 +28,6 @@ import android.database.ContentObserver
import android.net.Uri
import android.os.Environment
import android.os.UserHandle
import android.provider.Settings
import android.service.controls.Control
import android.service.controls.actions.ControlAction
import android.util.ArrayMap
@@ -70,15 +69,10 @@ class ControlsControllerImpl @Inject constructor (

    companion object {
        private const val TAG = "ControlsControllerImpl"
        internal const val CONTROLS_AVAILABLE = Settings.Secure.CONTROLS_ENABLED
        internal val URI = Settings.Secure.getUriFor(CONTROLS_AVAILABLE)
        private const val USER_CHANGE_RETRY_DELAY = 500L // ms
        private const val DEFAULT_ENABLED = 1
        private const val PERMISSION_SELF = "com.android.systemui.permission.SELF"
        const val SUGGESTED_CONTROLS_PER_STRUCTURE = 6

        private fun isAvailable(userId: Int, cr: ContentResolver) = Settings.Secure.getIntForUser(
            cr, CONTROLS_AVAILABLE, DEFAULT_ENABLED, userId) != 0
    }

    private var userChanging: Boolean = true
@@ -93,8 +87,6 @@ class ControlsControllerImpl @Inject constructor (

    private val contentResolver: ContentResolver
        get() = context.contentResolver
    override var available = isAvailable(currentUserId, contentResolver)
        private set

    private val persistenceWrapper: ControlsFavoritePersistenceWrapper
    @VisibleForTesting
@@ -126,8 +118,7 @@ class ControlsControllerImpl @Inject constructor (
                BackupManager(userStructure.userContext)
        )
        auxiliaryPersistenceWrapper.changeFile(userStructure.auxiliaryFile)
        available = isAvailable(newUser.identifier, contentResolver)
        resetFavorites(available)
        resetFavorites()
        bindingController.changeUser(newUser)
        listingController.changeUser(newUser)
        userChanging = false
@@ -157,7 +148,7 @@ class ControlsControllerImpl @Inject constructor (
                    Log.d(TAG, "Restore finished, storing auxiliary favorites")
                    auxiliaryPersistenceWrapper.initialize()
                    persistenceWrapper.storeFavorites(auxiliaryPersistenceWrapper.favorites)
                    resetFavorites(available)
                    resetFavorites()
                }
            }
        }
@@ -176,8 +167,7 @@ class ControlsControllerImpl @Inject constructor (
            if (userChanging || userId != currentUserId) {
                return
            }
            available = isAvailable(currentUserId, contentResolver)
            resetFavorites(available)
            resetFavorites()
        }
    }

@@ -242,7 +232,7 @@ class ControlsControllerImpl @Inject constructor (

    init {
        dumpManager.registerDumpable(javaClass.name, this)
        resetFavorites(available)
        resetFavorites()
        userChanging = false
        broadcastDispatcher.registerReceiver(
                userSwitchReceiver,
@@ -256,34 +246,25 @@ class ControlsControllerImpl @Inject constructor (
            PERMISSION_SELF,
            null
        )
        contentResolver.registerContentObserver(URI, false, settingObserver, UserHandle.USER_ALL)
        listingController.addCallback(listingCallback)
    }

    fun destroy() {
        broadcastDispatcher.unregisterReceiver(userSwitchReceiver)
        context.unregisterReceiver(restoreFinishedReceiver)
        contentResolver.unregisterContentObserver(settingObserver)
        listingController.removeCallback(listingCallback)
    }

    private fun resetFavorites(shouldLoad: Boolean) {
    private fun resetFavorites() {
        Favorites.clear()

        if (shouldLoad) {
        Favorites.load(persistenceWrapper.readFavorites())
    }
    }

    private fun confirmAvailability(): Boolean {
        if (userChanging) {
            Log.w(TAG, "Controls not available while user is changing")
            return false
        }
        if (!available) {
            Log.d(TAG, "Controls not available")
            return false
        }
        return true
    }

@@ -577,7 +558,6 @@ class ControlsControllerImpl @Inject constructor (

    override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
        pw.println("ControlsController state:")
        pw.println("  Available: $available")
        pw.println("  Changing users: $userChanging")
        pw.println("  Current user: ${currentUser.identifier}")
        pw.println("  Favorites:")
+1 −1
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ class ControlsComponent @Inject constructor(
    /**
     * @return true if controls are feature-enabled and the user has the setting enabled
     */
    fun isEnabled() = featureEnabled && lazyControlsController.get().available
    fun isEnabled() = featureEnabled

    /**
     * Returns one of 3 states:
+1 −4
Original line number Diff line number Diff line
@@ -71,10 +71,7 @@ open class ControlsRequestDialog @Inject constructor(

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        if (!controller.available) {
            Log.w(TAG, "Quick Controls not available for this user ")
            finish()
        }

        currentUserTracker.startTracking()
        controlsListingController.addCallback(callback)

Loading