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

Commit a43c4b28 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fix starting user in Controls controllers

Before this CL, the starting user was assumed to be 0 (from the
Context). This may not be true if the controllers are instantiated for
the first time while on a secondary user (thanks to Dagger).

This retrieves the correct current user when the controllers are
created.

Test: manual, open Power menu for the first time after switching users
and look at dump
Fixes: 150219351

Change-Id: I69a7ac32b82700feb707972693bd9b672d179f19
parent 10398d29
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.controls.controller

import android.app.ActivityManager
import android.content.ComponentName
import android.content.Context
import android.os.IBinder
@@ -50,7 +51,7 @@ open class ControlsBindingControllerImpl @Inject constructor(

    private val refreshing = AtomicBoolean(false)

    private var currentUser = context.user
    private var currentUser = UserHandle.of(ActivityManager.getCurrentUser())

    override val currentUserId: Int
        get() = currentUser.identifier
+9 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.controls.controller

import android.app.ActivityManager
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.ComponentName
@@ -78,16 +79,16 @@ class ControlsControllerImpl @Inject constructor (

    private var userChanging: Boolean = true

    private var currentUser = UserHandle.of(ActivityManager.getCurrentUser())
    override val currentUserId
        get() = currentUser.identifier

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

    private var currentUser = context.user
    override val currentUserId
        get() = currentUser.identifier

    private val persistenceWrapper = optionalWrapper.orElseGet {
        ControlsFavoritePersistenceWrapper(
                Environment.buildPath(
@@ -106,7 +107,7 @@ class ControlsControllerImpl @Inject constructor (
                userContext.filesDir, ControlsFavoritePersistenceWrapper.FILE_NAME)
        persistenceWrapper.changeFile(fileName)
        available = Settings.Secure.getIntForUser(contentResolver, CONTROLS_AVAILABLE,
                /* default */ DEFAULT_ENABLED, newUser.identifier) != 0
                DEFAULT_ENABLED, newUser.identifier) != 0
        synchronized(currentFavorites) {
            currentFavorites.clear()
        }
@@ -142,7 +143,7 @@ class ControlsControllerImpl @Inject constructor (
                return
            }
            available = Settings.Secure.getIntForUser(contentResolver, CONTROLS_AVAILABLE,
                    /* default */ DEFAULT_ENABLED, currentUserId) != 0
                    DEFAULT_ENABLED, currentUserId) != 0
            synchronized(currentFavorites) {
                currentFavorites.clear()
            }
+2 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.controls.management

import android.app.ActivityManager
import android.content.ComponentName
import android.content.Context
import android.content.pm.ServiceInfo
@@ -72,7 +73,7 @@ class ControlsListingControllerImpl @VisibleForTesting constructor(

    private var availableServices = emptyList<ServiceInfo>()

    override var currentUserId = context.userId
    override var currentUserId = ActivityManager.getCurrentUser()
        private set

    private val serviceListingCallback = ServiceListing.Callback {