Remove PackageManager.getResourcesForApplicationAsUser API

To switch another user to do something should create the context of the
specified user by using Context.createContextAsUser rather than call
*AsUser API directly.

This patch replaces the usage of
PackageManager.getResourcesForApplicationAsUser in SystemUI.

Test: make -j droid cts gts vts
Test: make -j docs
Test: atest SystemUITests \
    FrameworksServicesTests:com.android.server.pm
Bug: 170928809
Change-Id: Ie31d772a5002f349d8dd0e0ec8fe6134b1895517
This commit is contained in:
Felka Chang
2020-09-08 20:58:50 +08:00
parent faf7e4a05b
commit 78713031a9

View File

@@ -646,14 +646,14 @@ class Bubble implements BubbleViewProvider {
}
private int getDimenForPackageUser(Context context, int resId, String pkg, int userId) {
PackageManager pm = context.getPackageManager();
Resources r;
if (pkg != null) {
try {
if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_SYSTEM;
}
r = pm.getResourcesForApplicationAsUser(pkg, userId);
r = context.createContextAsUser(UserHandle.of(userId), /* flags */ 0)
.getPackageManager().getResourcesForApplication(pkg);
return r.getDimensionPixelSize(resId);
} catch (PackageManager.NameNotFoundException ex) {
// Uninstalled, don't care