summaryrefslogtreecommitdiff
path: root/libs/androidfw/StringPool.cpp
diff options
context:
space:
mode:
author Mark Renouf <mrenouf@google.com> 2024-03-15 10:57:36 -0400
committer Mark Renouf <mrenouf@google.com> 2024-03-15 18:53:54 +0000
commite7fd568de5de9f865b3492cb0554c46bb33b73d3 (patch)
treedec11cf067508509ad4f977ee0bd86ad347284c8 /libs/androidfw/StringPool.cpp
parentcf909694ad9394c68720727bdbf0d2ff0eaa649a (diff)
UserScopedService: Create services for users
This facility creates instances for '@UserHandleAware' system service APIs which do not provide methods which accept an explicit user id. In these cases, the service must be retreived from a user-specific Context using context.createContextAsUser. This replaces the typical pattern: @Application val context: Context = // injected fun isPrivateProfile(user: UserHandle): Boolean { val ctx = context.createContextAsUser(user) val service = ctx.getSystemService<UserManager>() return service.isPrivateProfile() } With the following: val userMgr: UserScopedService<UserManager> // Injected fun isPrivateProfile(user: UserHandle): Boolean { return userMgr.forUser(user).isPrivateProfile() } For testing, the functional interface can be implemented as: val mockUserMgr = mock<UserManager>() val scopedUserMgr = UserScopedService { _ -> mockUserManager } Bug: 327613051 Flag: NONE; CLs introducing usage should be guarded instead Test: NA Change-Id: I87881405ae1b93c6288ae998ae2c170d13db8d57
Diffstat (limited to 'libs/androidfw/StringPool.cpp')
0 files changed, 0 insertions, 0 deletions