summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabian Kozynski <kozynski@google.com>2020-05-19 15:24:18 -0400
committerFabian Kozynski <kozynski@google.com>2020-05-19 15:24:18 -0400
commit574a1e40be99ca4e4e992812f50145ba019845ff (patch)
treea765670c149eae6f4235a7457c4644aab4a5a1f4
parentf7b6901230342c789047e1da0042e314fb95e927 (diff)
Start ControlsControllerImpl on the correct user
The persistence wrappers are started using the correct file corresponding to the current user, in case that the controler is created now in OWNER. Test: manual, restart sysui on secondary user Bug: 156758594 Change-Id: I6734817a0368aedf9001009fcf4d124e9239b0c2
-rw-r--r--packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt61
1 files changed, 38 insertions, 23 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt
index a1f4c9666423..181170b0dee5 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt
@@ -89,35 +89,36 @@ class ControlsControllerImpl @Inject constructor (
contentResolver, CONTROLS_AVAILABLE, DEFAULT_ENABLED, currentUserId) != 0
private set
- private var file = Environment.buildPath(
- context.filesDir,
- ControlsFavoritePersistenceWrapper.FILE_NAME
- )
- private var auxiliaryFile = Environment.buildPath(
- context.filesDir,
- AuxiliaryPersistenceWrapper.AUXILIARY_FILE_NAME
- )
- private val persistenceWrapper = optionalWrapper.orElseGet {
- ControlsFavoritePersistenceWrapper(
- file,
- executor,
- BackupManager(context)
+ private val persistenceWrapper: ControlsFavoritePersistenceWrapper
+ @VisibleForTesting
+ internal var auxiliaryPersistenceWrapper: AuxiliaryPersistenceWrapper
+
+ init {
+ val userStructure = UserStructure(context, currentUser)
+
+ persistenceWrapper = optionalWrapper.orElseGet {
+ ControlsFavoritePersistenceWrapper(
+ userStructure.file,
+ executor,
+ BackupManager(userStructure.userContext)
+ )
+ }
+
+ auxiliaryPersistenceWrapper = AuxiliaryPersistenceWrapper(
+ userStructure.auxiliaryFile,
+ executor
)
}
- @VisibleForTesting
- internal var auxiliaryPersistenceWrapper = AuxiliaryPersistenceWrapper(auxiliaryFile, executor)
-
private fun setValuesForUser(newUser: UserHandle) {
Log.d(TAG, "Changing to user: $newUser")
currentUser = newUser
- val userContext = context.createContextAsUser(currentUser, 0)
- file = Environment.buildPath(
- userContext.filesDir, ControlsFavoritePersistenceWrapper.FILE_NAME)
- auxiliaryFile = Environment.buildPath(
- userContext.filesDir, AuxiliaryPersistenceWrapper.AUXILIARY_FILE_NAME)
- persistenceWrapper.changeFileAndBackupManager(file, BackupManager(userContext))
- auxiliaryPersistenceWrapper.changeFile(auxiliaryFile)
+ val userStructure = UserStructure(context, currentUser)
+ persistenceWrapper.changeFileAndBackupManager(
+ userStructure.file,
+ BackupManager(userStructure.userContext)
+ )
+ auxiliaryPersistenceWrapper.changeFile(userStructure.auxiliaryFile)
available = Settings.Secure.getIntForUser(contentResolver, CONTROLS_AVAILABLE,
DEFAULT_ENABLED, newUser.identifier) != 0
resetFavorites(available)
@@ -564,6 +565,20 @@ class ControlsControllerImpl @Inject constructor (
}
}
+class UserStructure(context: Context, user: UserHandle) {
+ val userContext = context.createContextAsUser(user, 0)
+
+ val file = Environment.buildPath(
+ context.filesDir,
+ ControlsFavoritePersistenceWrapper.FILE_NAME
+ )
+
+ val auxiliaryFile = Environment.buildPath(
+ context.filesDir,
+ AuxiliaryPersistenceWrapper.AUXILIARY_FILE_NAME
+ )
+}
+
/**
* Relies on immutable data for thread safety. When necessary to update favMap, use reassignment to
* replace it, which will not disrupt any ongoing map traversal.