am 5e9187a3: Merge "Fix "system" resources; more context user work." into jb-mr1-dev

* commit '5e9187a3cf2a33e559212004795e1278eb60da81':
  Fix "system" resources; more context user work.
This commit is contained in:
Jeff Sharkey
2012-09-27 20:27:31 -07:00
committed by Android Git Automerger
3 changed files with 51 additions and 35 deletions

View File

@@ -50,7 +50,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Process; import android.os.Process;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.UserHandle;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
@@ -70,7 +69,7 @@ final class ApplicationPackageManager extends PackageManager {
public PackageInfo getPackageInfo(String packageName, int flags) public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
PackageInfo pi = mPM.getPackageInfo(packageName, flags, UserHandle.myUserId()); PackageInfo pi = mPM.getPackageInfo(packageName, flags, mContext.getUserId());
if (pi != null) { if (pi != null) {
return pi; return pi;
} }
@@ -200,7 +199,7 @@ final class ApplicationPackageManager extends PackageManager {
public ApplicationInfo getApplicationInfo(String packageName, int flags) public ApplicationInfo getApplicationInfo(String packageName, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, UserHandle.myUserId()); ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, mContext.getUserId());
if (ai != null) { if (ai != null) {
return ai; return ai;
} }
@@ -215,7 +214,7 @@ final class ApplicationPackageManager extends PackageManager {
public ActivityInfo getActivityInfo(ComponentName className, int flags) public ActivityInfo getActivityInfo(ComponentName className, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
ActivityInfo ai = mPM.getActivityInfo(className, flags, UserHandle.myUserId()); ActivityInfo ai = mPM.getActivityInfo(className, flags, mContext.getUserId());
if (ai != null) { if (ai != null) {
return ai; return ai;
} }
@@ -230,7 +229,7 @@ final class ApplicationPackageManager extends PackageManager {
public ActivityInfo getReceiverInfo(ComponentName className, int flags) public ActivityInfo getReceiverInfo(ComponentName className, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
ActivityInfo ai = mPM.getReceiverInfo(className, flags, UserHandle.myUserId()); ActivityInfo ai = mPM.getReceiverInfo(className, flags, mContext.getUserId());
if (ai != null) { if (ai != null) {
return ai; return ai;
} }
@@ -245,7 +244,7 @@ final class ApplicationPackageManager extends PackageManager {
public ServiceInfo getServiceInfo(ComponentName className, int flags) public ServiceInfo getServiceInfo(ComponentName className, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
ServiceInfo si = mPM.getServiceInfo(className, flags, UserHandle.myUserId()); ServiceInfo si = mPM.getServiceInfo(className, flags, mContext.getUserId());
if (si != null) { if (si != null) {
return si; return si;
} }
@@ -260,7 +259,7 @@ final class ApplicationPackageManager extends PackageManager {
public ProviderInfo getProviderInfo(ComponentName className, int flags) public ProviderInfo getProviderInfo(ComponentName className, int flags)
throws NameNotFoundException { throws NameNotFoundException {
try { try {
ProviderInfo pi = mPM.getProviderInfo(className, flags, UserHandle.myUserId()); ProviderInfo pi = mPM.getProviderInfo(className, flags, mContext.getUserId());
if (pi != null) { if (pi != null) {
return pi; return pi;
} }
@@ -405,7 +404,7 @@ final class ApplicationPackageManager extends PackageManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<PackageInfo> getInstalledPackages(int flags) { public List<PackageInfo> getInstalledPackages(int flags) {
return getInstalledPackages(flags, UserHandle.myUserId()); return getInstalledPackages(flags, mContext.getUserId());
} }
/** @hide */ /** @hide */
@@ -431,7 +430,7 @@ final class ApplicationPackageManager extends PackageManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
public List<ApplicationInfo> getInstalledApplications(int flags) { public List<ApplicationInfo> getInstalledApplications(int flags) {
int userId = UserHandle.getUserId(Process.myUid()); final int userId = mContext.getUserId();
try { try {
final List<ApplicationInfo> applicationInfos = new ArrayList<ApplicationInfo>(); final List<ApplicationInfo> applicationInfos = new ArrayList<ApplicationInfo>();
ApplicationInfo lastItem = null; ApplicationInfo lastItem = null;
@@ -451,7 +450,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public ResolveInfo resolveActivity(Intent intent, int flags) { public ResolveInfo resolveActivity(Intent intent, int flags) {
return resolveActivityAsUser(intent, flags, UserHandle.myUserId()); return resolveActivityAsUser(intent, flags, mContext.getUserId());
} }
@Override @Override
@@ -470,7 +469,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public List<ResolveInfo> queryIntentActivities(Intent intent, public List<ResolveInfo> queryIntentActivities(Intent intent,
int flags) { int flags) {
return queryIntentActivitiesAsUser(intent, flags, UserHandle.myUserId()); return queryIntentActivitiesAsUser(intent, flags, mContext.getUserId());
} }
/** @hide Same as above but for a specific user */ /** @hide Same as above but for a specific user */
@@ -514,7 +513,7 @@ final class ApplicationPackageManager extends PackageManager {
try { try {
return mPM.queryIntentActivityOptions(caller, specifics, return mPM.queryIntentActivityOptions(caller, specifics,
specificTypes, intent, intent.resolveTypeIfNeeded(resolver), specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
flags, UserHandle.myUserId()); flags, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e); throw new RuntimeException("Package manager has died", e);
} }
@@ -538,7 +537,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) { public List<ResolveInfo> queryBroadcastReceivers(Intent intent, int flags) {
return queryBroadcastReceivers(intent, flags, UserHandle.myUserId()); return queryBroadcastReceivers(intent, flags, mContext.getUserId());
} }
@Override @Override
@@ -548,7 +547,7 @@ final class ApplicationPackageManager extends PackageManager {
intent, intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()), intent.resolveTypeIfNeeded(mContext.getContentResolver()),
flags, flags,
UserHandle.myUserId()); mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e); throw new RuntimeException("Package manager has died", e);
} }
@@ -569,14 +568,14 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public List<ResolveInfo> queryIntentServices(Intent intent, int flags) { public List<ResolveInfo> queryIntentServices(Intent intent, int flags) {
return queryIntentServicesAsUser(intent, flags, UserHandle.myUserId()); return queryIntentServicesAsUser(intent, flags, mContext.getUserId());
} }
@Override @Override
public ProviderInfo resolveContentProvider(String name, public ProviderInfo resolveContentProvider(String name,
int flags) { int flags) {
try { try {
return mPM.resolveContentProvider(name, flags, UserHandle.myUserId()); return mPM.resolveContentProvider(name, flags, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e); throw new RuntimeException("Package manager has died", e);
} }
@@ -763,6 +762,13 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public Resources getResourcesForApplicationAsUser(String appPackageName, int userId) public Resources getResourcesForApplicationAsUser(String appPackageName, int userId)
throws NameNotFoundException { throws NameNotFoundException {
if (userId < 0) {
throw new IllegalArgumentException(
"Call does not support special user #" + userId);
}
if ("system".equals(appPackageName)) {
return mContext.mMainThread.getSystemContext().getResources();
}
try { try {
ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId); ApplicationInfo ai = mPM.getApplicationInfo(appPackageName, 0, userId);
if (ai != null) { if (ai != null) {
@@ -1118,7 +1124,7 @@ final class ApplicationPackageManager extends PackageManager {
public void clearApplicationUserData(String packageName, public void clearApplicationUserData(String packageName,
IPackageDataObserver observer) { IPackageDataObserver observer) {
try { try {
mPM.clearApplicationUserData(packageName, observer, UserHandle.myUserId()); mPM.clearApplicationUserData(packageName, observer, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }
@@ -1191,7 +1197,7 @@ final class ApplicationPackageManager extends PackageManager {
public void addPreferredActivity(IntentFilter filter, public void addPreferredActivity(IntentFilter filter,
int match, ComponentName[] set, ComponentName activity) { int match, ComponentName[] set, ComponentName activity) {
try { try {
mPM.addPreferredActivity(filter, match, set, activity, UserHandle.myUserId()); mPM.addPreferredActivity(filter, match, set, activity, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }
@@ -1241,7 +1247,7 @@ final class ApplicationPackageManager extends PackageManager {
public void setComponentEnabledSetting(ComponentName componentName, public void setComponentEnabledSetting(ComponentName componentName,
int newState, int flags) { int newState, int flags) {
try { try {
mPM.setComponentEnabledSetting(componentName, newState, flags, UserHandle.myUserId()); mPM.setComponentEnabledSetting(componentName, newState, flags, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }
@@ -1250,7 +1256,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public int getComponentEnabledSetting(ComponentName componentName) { public int getComponentEnabledSetting(ComponentName componentName) {
try { try {
return mPM.getComponentEnabledSetting(componentName, UserHandle.myUserId()); return mPM.getComponentEnabledSetting(componentName, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }
@@ -1261,7 +1267,7 @@ final class ApplicationPackageManager extends PackageManager {
public void setApplicationEnabledSetting(String packageName, public void setApplicationEnabledSetting(String packageName,
int newState, int flags) { int newState, int flags) {
try { try {
mPM.setApplicationEnabledSetting(packageName, newState, flags, UserHandle.myUserId()); mPM.setApplicationEnabledSetting(packageName, newState, flags, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }
@@ -1270,7 +1276,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override @Override
public int getApplicationEnabledSetting(String packageName) { public int getApplicationEnabledSetting(String packageName) {
try { try {
return mPM.getApplicationEnabledSetting(packageName, UserHandle.myUserId()); return mPM.getApplicationEnabledSetting(packageName, mContext.getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// Should never happen! // Should never happen!
} }

View File

@@ -1029,7 +1029,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, null, mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, null, false, false, Activity.RESULT_OK, null, null, null, false, false,
UserHandle.myUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1042,7 +1042,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, null, mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, receiverPermission, false, false, Activity.RESULT_OK, null, null, receiverPermission, false, false,
UserHandle.myUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1056,7 +1056,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, null, mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, receiverPermission, true, false, Activity.RESULT_OK, null, null, receiverPermission, true, false,
UserHandle.myUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1089,7 +1089,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, rd, mMainThread.getApplicationThread(), intent, resolvedType, rd,
initialCode, initialData, initialExtras, receiverPermission, initialCode, initialData, initialExtras, receiverPermission,
true, false, UserHandle.myUserId()); true, false, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1160,7 +1160,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, null, mMainThread.getApplicationThread(), intent, resolvedType, null,
Activity.RESULT_OK, null, null, null, false, true, Activity.RESULT_OK, null, null, null, false, true,
UserHandle.myUserId()); getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1193,7 +1193,7 @@ class ContextImpl extends Context {
ActivityManagerNative.getDefault().broadcastIntent( ActivityManagerNative.getDefault().broadcastIntent(
mMainThread.getApplicationThread(), intent, resolvedType, rd, mMainThread.getApplicationThread(), intent, resolvedType, rd,
initialCode, initialData, initialExtras, null, initialCode, initialData, initialExtras, null,
true, true, UserHandle.myUserId()); true, true, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1208,7 +1208,7 @@ class ContextImpl extends Context {
try { try {
intent.setAllowFds(false); intent.setAllowFds(false);
ActivityManagerNative.getDefault().unbroadcastIntent( ActivityManagerNative.getDefault().unbroadcastIntent(
mMainThread.getApplicationThread(), intent, UserHandle.myUserId()); mMainThread.getApplicationThread(), intent, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
} }
} }
@@ -1281,7 +1281,7 @@ class ContextImpl extends Context {
@Override @Override
public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter, public Intent registerReceiver(BroadcastReceiver receiver, IntentFilter filter,
String broadcastPermission, Handler scheduler) { String broadcastPermission, Handler scheduler) {
return registerReceiverInternal(receiver, UserHandle.myUserId(), return registerReceiverInternal(receiver, getUserId(),
filter, broadcastPermission, scheduler, getOuterContext()); filter, broadcastPermission, scheduler, getOuterContext());
} }
@@ -1337,12 +1337,12 @@ class ContextImpl extends Context {
@Override @Override
public ComponentName startService(Intent service) { public ComponentName startService(Intent service) {
return startServiceAsUser(service, Process.myUserHandle()); return startServiceAsUser(service, mUser);
} }
@Override @Override
public boolean stopService(Intent service) { public boolean stopService(Intent service) {
return stopServiceAsUser(service, Process.myUserHandle()); return stopServiceAsUser(service, mUser);
} }
@Override @Override
@@ -1446,7 +1446,7 @@ class ContextImpl extends Context {
arguments.setAllowFds(false); arguments.setAllowFds(false);
} }
return ActivityManagerNative.getDefault().startInstrumentation( return ActivityManagerNative.getDefault().startInstrumentation(
className, profileFile, 0, arguments, null, UserHandle.myUserId()); className, profileFile, 0, arguments, null, getUserId());
} catch (RemoteException e) { } catch (RemoteException e) {
// System has crashed, nothing we can do. // System has crashed, nothing we can do.
} }
@@ -1792,6 +1792,11 @@ class ContextImpl extends Context {
return file; return file;
} }
/** {@hide} */
public int getUserId() {
return mUser.getIdentifier();
}
static ContextImpl createSystemContext(ActivityThread mainThread) { static ContextImpl createSystemContext(ActivityThread mainThread) {
final ContextImpl context = new ContextImpl(); final ContextImpl context = new ContextImpl();
context.init(Resources.getSystem(), mainThread, Process.myUserHandle()); context.init(Resources.getSystem(), mainThread, Process.myUserHandle());

View File

@@ -24,6 +24,7 @@ import android.graphics.drawable.Drawable;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Rect; import android.graphics.Rect;
import android.os.UserHandle;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Slog; import android.util.Slog;
@@ -165,8 +166,12 @@ public class StatusBarIconView extends AnimatedImageView {
if (icon.iconPackage != null) { if (icon.iconPackage != null) {
try { try {
r = context.getPackageManager().getResourcesForApplicationAsUser(icon.iconPackage, int userId = icon.user.getIdentifier();
icon.user.getIdentifier()); if (userId == UserHandle.USER_ALL) {
userId = UserHandle.USER_OWNER;
}
r = context.getPackageManager()
.getResourcesForApplicationAsUser(icon.iconPackage, userId);
} catch (PackageManager.NameNotFoundException ex) { } catch (PackageManager.NameNotFoundException ex) {
Slog.e(TAG, "Icon package not found: " + icon.iconPackage); Slog.e(TAG, "Icon package not found: " + icon.iconPackage);
return null; return null;