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
This commit is contained in:
Fabian Kozynski
2020-02-24 15:43:42 -05:00
parent 10398d29f3
commit a43c4b2872
3 changed files with 14 additions and 11 deletions

View File

@@ -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

View File

@@ -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 val contentResolver: ContentResolver
get() = context.contentResolver
override var available = Settings.Secure.getInt(
contentResolver, CONTROLS_AVAILABLE, DEFAULT_ENABLED) != 0
private set
private var currentUser = context.user
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.getIntForUser(
contentResolver, CONTROLS_AVAILABLE, DEFAULT_ENABLED, currentUserId) != 0
private set
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()
}

View File

@@ -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 {