Skip to content

Commit be47828

Browse files
Amith YamasaniAndroid (Google) Code Review
authored andcommitted
Merge "Load resources for the correct user" into jb-mr1-dev
2 parents 1908cf9 + 98edc95 commit be47828

File tree

12 files changed

+57
-13
lines changed

12 files changed

+57
-13
lines changed

core/java/android/app/ActivityThread.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1740,6 +1740,11 @@ final Handler getHandler() {
17401740

17411741
public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
17421742
int flags) {
1743+
return getPackageInfo(packageName, compatInfo, flags, UserHandle.myUserId());
1744+
}
1745+
1746+
public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo compatInfo,
1747+
int flags, int userId) {
17431748
synchronized (mPackages) {
17441749
WeakReference<LoadedApk> ref;
17451750
if ((flags&Context.CONTEXT_INCLUDE_CODE) != 0) {
@@ -1768,7 +1773,7 @@ public final LoadedApk getPackageInfo(String packageName, CompatibilityInfo comp
17681773
ApplicationInfo ai = null;
17691774
try {
17701775
ai = getPackageManager().getApplicationInfo(packageName,
1771-
PackageManager.GET_SHARED_LIBRARY_FILES, UserHandle.myUserId());
1776+
PackageManager.GET_SHARED_LIBRARY_FILES, userId);
17721777
} catch (RemoteException e) {
17731778
// Ignore
17741779
}

core/java/android/app/ApplicationPackageManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,21 @@ public Drawable getApplicationLogo(String packageName)
759759
getApplicationInfo(appPackageName, 0));
760760
}
761761

762+
/** @hide */
763+
@Override
764+
public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
765+
throws NameNotFoundException {
766+
try {
767+
ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId);
768+
if (ai != null) {
769+
return getResourcesForApplication(ai);
770+
}
771+
} catch (RemoteException e) {
772+
throw new RuntimeException("Package manager has died", e);
773+
}
774+
throw new NameNotFoundException("Package " + appPackageName + " doesn't exist");
775+
}
776+
762777
int mCachedSafeMode = -1;
763778
@Override public boolean isSafeMode() {
764779
try {

core/java/android/app/ContextImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1707,7 +1707,8 @@ public Context createPackageContextAsUser(String packageName, int flags, UserHan
17071707
}
17081708

17091709
LoadedApk pi =
1710-
mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags);
1710+
mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(), flags,
1711+
user.getIdentifier());
17111712
if (pi != null) {
17121713
ContextImpl c = new ContextImpl();
17131714
c.mRestricted = (flags & CONTEXT_RESTRICTED) == CONTEXT_RESTRICTED;

core/java/android/content/pm/PackageManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,10 @@ public abstract Resources getResourcesForApplication(ApplicationInfo app)
23412341
public abstract Resources getResourcesForApplication(String appPackageName)
23422342
throws NameNotFoundException;
23432343

2344+
/** @hide */
2345+
public abstract Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
2346+
throws NameNotFoundException;
2347+
23442348
/**
23452349
* Retrieve overall information about an application package defined
23462350
* in a package archive file

core/java/com/android/internal/statusbar/StatusBarIcon.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,21 @@
1818

1919
import android.os.Parcel;
2020
import android.os.Parcelable;
21+
import android.os.UserHandle;
2122

2223
public class StatusBarIcon implements Parcelable {
2324
public String iconPackage;
25+
public UserHandle user;
2426
public int iconId;
2527
public int iconLevel;
2628
public boolean visible = true;
2729
public int number;
2830
public CharSequence contentDescription;
2931

30-
public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number,
32+
public StatusBarIcon(String iconPackage, UserHandle user, int iconId, int iconLevel, int number,
3133
CharSequence contentDescription) {
3234
this.iconPackage = iconPackage;
35+
this.user = user;
3336
this.iconId = iconId;
3437
this.iconLevel = iconLevel;
3538
this.number = number;
@@ -38,15 +41,16 @@ public StatusBarIcon(String iconPackage, int iconId, int iconLevel, int number,
3841

3942
@Override
4043
public String toString() {
41-
return "StatusBarIcon(pkg=" + this.iconPackage + " id=0x" + Integer.toHexString(this.iconId)
44+
return "StatusBarIcon(pkg=" + this.iconPackage + "user=" + user.getIdentifier()
45+
+ " id=0x" + Integer.toHexString(this.iconId)
4246
+ " level=" + this.iconLevel + " visible=" + visible
4347
+ " num=" + this.number + " )";
4448
}
4549

4650
@Override
4751
public StatusBarIcon clone() {
48-
StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.iconId, this.iconLevel,
49-
this.number, this.contentDescription);
52+
StatusBarIcon that = new StatusBarIcon(this.iconPackage, this.user, this.iconId,
53+
this.iconLevel, this.number, this.contentDescription);
5054
that.visible = this.visible;
5155
return that;
5256
}
@@ -60,6 +64,7 @@ public StatusBarIcon(Parcel in) {
6064

6165
public void readFromParcel(Parcel in) {
6266
this.iconPackage = in.readString();
67+
this.user = (UserHandle) in.readParcelable(null);
6368
this.iconId = in.readInt();
6469
this.iconLevel = in.readInt();
6570
this.visible = in.readInt() != 0;
@@ -69,6 +74,7 @@ public void readFromParcel(Parcel in) {
6974

7075
public void writeToParcel(Parcel out, int flags) {
7176
out.writeString(this.iconPackage);
77+
out.writeParcelable(this.user, 0);
7278
out.writeInt(this.iconId);
7379
out.writeInt(this.iconLevel);
7480
out.writeInt(this.visible ? 1 : 0);

packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,7 @@ protected StatusBarIconView addNotificationViews(IBinder key,
860860
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
861861

862862
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
863+
notification.user,
863864
notification.notification.icon,
864865
notification.notification.iconLevel,
865866
notification.notification.number,
@@ -1012,6 +1013,7 @@ public void updateNotification(IBinder key, StatusBarNotification notification)
10121013
}
10131014
// Update the icon.
10141015
final StatusBarIcon ic = new StatusBarIcon(notification.pkg,
1016+
notification.user,
10151017
notification.notification.icon, notification.notification.iconLevel,
10161018
notification.notification.number,
10171019
notification.notification.tickerText);

packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ public static Drawable getIcon(Context context, StatusBarIcon icon) {
165165

166166
if (icon.iconPackage != null) {
167167
try {
168-
r = context.getPackageManager().getResourcesForApplication(icon.iconPackage);
168+
r = context.getPackageManager().getResourcesForApplicationAsUser(icon.iconPackage,
169+
icon.user.getIdentifier());
169170
} catch (PackageManager.NameNotFoundException ex) {
170171
Slog.e(TAG, "Icon package not found: " + icon.iconPackage);
171172
return null;

packages/SystemUI/src/com/android/systemui/statusbar/phone/Ticker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public void addEntry(StatusBarNotification n) {
192192
}
193193

194194
final Drawable icon = StatusBarIconView.getIcon(mContext,
195-
new StatusBarIcon(n.pkg, n.notification.icon, n.notification.iconLevel, 0,
195+
new StatusBarIcon(n.pkg, n.user, n.notification.icon, n.notification.iconLevel, 0,
196196
n.notification.tickerText));
197197
final Segment newSegment = new Segment(n, icon, n.notification.tickerText);
198198

packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ private View makeTickerView(StatusBarNotification notification) {
288288
} else if (n.tickerText != null) {
289289
group = (ViewGroup)inflater.inflate(R.layout.system_bar_ticker_compat, mWindow, false);
290290
final Drawable icon = StatusBarIconView.getIcon(mContext,
291-
new StatusBarIcon(notification.pkg, n.icon, n.iconLevel, 0, n.tickerText));
291+
new StatusBarIcon(notification.pkg, notification.user, n.icon, n.iconLevel, 0,
292+
n.tickerText));
292293
ImageView iv = (ImageView)group.findViewById(iconId);
293294
iv.setImageDrawable(icon);
294295
iv.setVisibility(View.VISIBLE);

services/java/com/android/server/AppWidgetServiceImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -657,13 +657,13 @@ public void bindRemoteViewsService(int appWidgetId, Intent intent, IBinder conne
657657
}
658658
final ComponentName componentName = intent.getComponent();
659659
try {
660-
final ServiceInfo si = mContext.getPackageManager().getServiceInfo(componentName,
661-
PackageManager.GET_PERMISSIONS);
660+
final ServiceInfo si = AppGlobals.getPackageManager().getServiceInfo(componentName,
661+
PackageManager.GET_PERMISSIONS, mUserId);
662662
if (!android.Manifest.permission.BIND_REMOTEVIEWS.equals(si.permission)) {
663663
throw new SecurityException("Selected service does not require "
664664
+ android.Manifest.permission.BIND_REMOTEVIEWS + ": " + componentName);
665665
}
666-
} catch (PackageManager.NameNotFoundException e) {
666+
} catch (RemoteException e) {
667667
throw new IllegalArgumentException("Unknown component " + componentName);
668668
}
669669

0 commit comments

Comments
 (0)