Merge "[User Switcher] Improve documentation" into tm-qpr-dev am: 40e947cf45

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19324252

Change-Id: I3fb1c31c45babdb34a15e31dca205659b6f617ba
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Aaron Liu
2022-07-20 16:21:51 +00:00
committed by Automerger Merge Worker

View File

@@ -1,10 +1,30 @@
# UserFileManager
This class is used to generate file paths and SharedPreferences that is compatible for multiple
This class is used to generate file paths and SharedPreferences that is compatible for specific OS
users in SystemUI. Due to constraints in SystemUI, we can only read/write files as the system user.
Therefore, for secondary users, we want to store secondary user specific files into the system user
directory.
## Usages
Inject UserFileManager into your class.
### fun getFile(fileName: String, userId: Int): File
Add a file name and user id. You can retrieve the current user id from UserTracker. This will
return a java.io File object that contains the file path to write/read to.
i.e. `fileManager.getFile("example.xml", userTracker.userId)`
### fun getSharedPreferences(fileName: String, mode: Int, userId: Int): SharedPreferences
Add a file name, user id, and PreferencesMode. You can retrieve the current user id from
UserTracker. This returns SharedPreferences object that is tied to the specific user. Note that if
the SharedPreferences file does not exist, one will be created automatically. See
[SharedPreferences documentation](https://developer.android.com/reference/android/content/Context#getSharedPreferences(java.lang.String,%20int))
for more details.
i.e. `fileManager.getSharedPreferences("prefs.xml", userTracker.userId, 0)`
## Handling User Removal
This class will listen for Intent.ACTION_USER_REMOVED and remove directories that no longer