summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2012-03-13 16:08:00 -0700
committerAmith Yamasani <yamasani@google.com>2012-03-22 10:08:24 -0700
commit483f3b06ea84440a082e21b68ec2c2e54046f5a6 (patch)
treecc0dff8ea3d133a4dc910bc1e90c85380cea2064 /core/java/android
parent8fca15f1f2273fa429e58f783d0970251d0942e5 (diff)
downloadframeworks_base-483f3b06ea84440a082e21b68ec2c2e54046f5a6.zip
frameworks_base-483f3b06ea84440a082e21b68ec2c2e54046f5a6.tar.gz
frameworks_base-483f3b06ea84440a082e21b68ec2c2e54046f5a6.tar.bz2
Package restrictions per user
Packages can be enabled/disabled per user. This requires maintaining stopped/launched states and enabled / disabled components and packages per user. Refactored pm.Settings and PackageSettingsBase to keep track of states per user. Migrated the stopped-packages.xml to users/<u>/package-restrictions.xml Changed intent resolution to handle individual user restrictions. Bunch of IPackageManager calls now have a userId argument. Make AppWidgetService handle removals of packages. Added some tests for pm.Settings and PackageManager. Change-Id: Ia83b529e1df88dbcb3bd55ebfc952a6e9b20e861
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/app/ActivityThread.java2
-rw-r--r--core/java/android/app/ApplicationPackageManager.java44
-rw-r--r--core/java/android/app/LoadedApk.java4
-rw-r--r--core/java/android/content/pm/IPackageManager.aidl42
-rw-r--r--core/java/android/content/pm/PackageParser.java17
-rw-r--r--core/java/android/os/UserId.java8
6 files changed, 72 insertions, 45 deletions
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 2a3e213..0860890 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -1586,7 +1586,7 @@ public final class ActivityThread {
ApplicationInfo ai = null;
try {
ai = getPackageManager().getApplicationInfo(packageName,
- PackageManager.GET_SHARED_LIBRARY_FILES);
+ PackageManager.GET_SHARED_LIBRARY_FILES, UserId.myUserId());
} catch (RemoteException e) {
// Ignore
}
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 758ce09..f38540c 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -49,6 +49,7 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Process;
import android.os.RemoteException;
+import android.os.UserId;
import android.util.Log;
import java.lang.ref.WeakReference;
@@ -67,7 +68,7 @@ final class ApplicationPackageManager extends PackageManager {
public PackageInfo getPackageInfo(String packageName, int flags)
throws NameNotFoundException {
try {
- PackageInfo pi = mPM.getPackageInfo(packageName, flags);
+ PackageInfo pi = mPM.getPackageInfo(packageName, flags, UserId.myUserId());
if (pi != null) {
return pi;
}
@@ -197,7 +198,7 @@ final class ApplicationPackageManager extends PackageManager {
public ApplicationInfo getApplicationInfo(String packageName, int flags)
throws NameNotFoundException {
try {
- ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags);
+ ApplicationInfo ai = mPM.getApplicationInfo(packageName, flags, UserId.myUserId());
if (ai != null) {
return ai;
}
@@ -212,7 +213,7 @@ final class ApplicationPackageManager extends PackageManager {
public ActivityInfo getActivityInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
- ActivityInfo ai = mPM.getActivityInfo(className, flags);
+ ActivityInfo ai = mPM.getActivityInfo(className, flags, UserId.myUserId());
if (ai != null) {
return ai;
}
@@ -227,7 +228,7 @@ final class ApplicationPackageManager extends PackageManager {
public ActivityInfo getReceiverInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
- ActivityInfo ai = mPM.getReceiverInfo(className, flags);
+ ActivityInfo ai = mPM.getReceiverInfo(className, flags, UserId.myUserId());
if (ai != null) {
return ai;
}
@@ -242,7 +243,7 @@ final class ApplicationPackageManager extends PackageManager {
public ServiceInfo getServiceInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
- ServiceInfo si = mPM.getServiceInfo(className, flags);
+ ServiceInfo si = mPM.getServiceInfo(className, flags, UserId.myUserId());
if (si != null) {
return si;
}
@@ -257,7 +258,7 @@ final class ApplicationPackageManager extends PackageManager {
public ProviderInfo getProviderInfo(ComponentName className, int flags)
throws NameNotFoundException {
try {
- ProviderInfo pi = mPM.getProviderInfo(className, flags);
+ ProviderInfo pi = mPM.getProviderInfo(className, flags, UserId.myUserId());
if (pi != null) {
return pi;
}
@@ -422,6 +423,7 @@ final class ApplicationPackageManager extends PackageManager {
@SuppressWarnings("unchecked")
@Override
public List<ApplicationInfo> getInstalledApplications(int flags) {
+ int userId = UserId.getUserId(Process.myUid());
try {
final List<ApplicationInfo> applicationInfos = new ArrayList<ApplicationInfo>();
ApplicationInfo lastItem = null;
@@ -429,7 +431,7 @@ final class ApplicationPackageManager extends PackageManager {
do {
final String lastKey = lastItem != null ? lastItem.packageName : null;
- slice = mPM.getInstalledApplications(flags, lastKey);
+ slice = mPM.getInstalledApplications(flags, lastKey, userId);
lastItem = slice.populateList(applicationInfos, ApplicationInfo.CREATOR);
} while (!slice.isLastSlice());
@@ -445,7 +447,7 @@ final class ApplicationPackageManager extends PackageManager {
return mPM.resolveIntent(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
- flags);
+ flags, UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -458,7 +460,8 @@ final class ApplicationPackageManager extends PackageManager {
return mPM.queryIntentActivities(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
- flags);
+ flags,
+ UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -490,7 +493,7 @@ final class ApplicationPackageManager extends PackageManager {
try {
return mPM.queryIntentActivityOptions(caller, specifics,
specificTypes, intent, intent.resolveTypeIfNeeded(resolver),
- flags);
+ flags, UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -502,7 +505,8 @@ final class ApplicationPackageManager extends PackageManager {
return mPM.queryIntentReceivers(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
- flags);
+ flags,
+ UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -514,7 +518,8 @@ final class ApplicationPackageManager extends PackageManager {
return mPM.resolveService(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
- flags);
+ flags,
+ UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -526,7 +531,8 @@ final class ApplicationPackageManager extends PackageManager {
return mPM.queryIntentServices(
intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
- flags);
+ flags,
+ UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -536,7 +542,7 @@ final class ApplicationPackageManager extends PackageManager {
public ProviderInfo resolveContentProvider(String name,
int flags) {
try {
- return mPM.resolveContentProvider(name, flags);
+ return mPM.resolveContentProvider(name, flags, UserId.myUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
@@ -1026,7 +1032,7 @@ final class ApplicationPackageManager extends PackageManager {
public void clearApplicationUserData(String packageName,
IPackageDataObserver observer) {
try {
- mPM.clearApplicationUserData(packageName, observer);
+ mPM.clearApplicationUserData(packageName, observer, UserId.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
@@ -1139,7 +1145,7 @@ final class ApplicationPackageManager extends PackageManager {
public void setComponentEnabledSetting(ComponentName componentName,
int newState, int flags) {
try {
- mPM.setComponentEnabledSetting(componentName, newState, flags);
+ mPM.setComponentEnabledSetting(componentName, newState, flags, UserId.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
@@ -1148,7 +1154,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public int getComponentEnabledSetting(ComponentName componentName) {
try {
- return mPM.getComponentEnabledSetting(componentName);
+ return mPM.getComponentEnabledSetting(componentName, UserId.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
@@ -1159,7 +1165,7 @@ final class ApplicationPackageManager extends PackageManager {
public void setApplicationEnabledSetting(String packageName,
int newState, int flags) {
try {
- mPM.setApplicationEnabledSetting(packageName, newState, flags);
+ mPM.setApplicationEnabledSetting(packageName, newState, flags, UserId.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
@@ -1168,7 +1174,7 @@ final class ApplicationPackageManager extends PackageManager {
@Override
public int getApplicationEnabledSetting(String packageName) {
try {
- return mPM.getApplicationEnabledSetting(packageName);
+ return mPM.getApplicationEnabledSetting(packageName, UserId.myUserId());
} catch (RemoteException e) {
// Should never happen!
}
diff --git a/core/java/android/app/LoadedApk.java b/core/java/android/app/LoadedApk.java
index de9470e..5340fbb 100644
--- a/core/java/android/app/LoadedApk.java
+++ b/core/java/android/app/LoadedApk.java
@@ -194,7 +194,7 @@ public final class LoadedApk {
ApplicationInfo ai = null;
try {
ai = ActivityThread.getPackageManager().getApplicationInfo(packageName,
- PackageManager.GET_SHARED_LIBRARY_FILES);
+ PackageManager.GET_SHARED_LIBRARY_FILES, UserId.myUserId());
} catch (RemoteException e) {
throw new AssertionError(e);
}
@@ -351,7 +351,7 @@ public final class LoadedApk {
IPackageManager pm = ActivityThread.getPackageManager();
android.content.pm.PackageInfo pi;
try {
- pi = pm.getPackageInfo(mPackageName, 0);
+ pi = pm.getPackageInfo(mPackageName, 0, UserId.myUserId());
} catch (RemoteException e) {
throw new AssertionError(e);
}
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 9bd1940..d89d2de 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -49,8 +49,8 @@ import android.content.IntentSender;
* {@hide}
*/
interface IPackageManager {
- PackageInfo getPackageInfo(String packageName, int flags);
- int getPackageUid(String packageName);
+ PackageInfo getPackageInfo(String packageName, int flags, int userId);
+ int getPackageUid(String packageName, int userId);
int[] getPackageGids(String packageName);
String[] currentToCanonicalPackageNames(in String[] names);
@@ -64,15 +64,15 @@ interface IPackageManager {
List<PermissionGroupInfo> getAllPermissionGroups(int flags);
- ApplicationInfo getApplicationInfo(String packageName, int flags);
+ ApplicationInfo getApplicationInfo(String packageName, int flags ,int userId);
- ActivityInfo getActivityInfo(in ComponentName className, int flags);
+ ActivityInfo getActivityInfo(in ComponentName className, int flags, int userId);
- ActivityInfo getReceiverInfo(in ComponentName className, int flags);
+ ActivityInfo getReceiverInfo(in ComponentName className, int flags, int userId);
- ServiceInfo getServiceInfo(in ComponentName className, int flags);
+ ServiceInfo getServiceInfo(in ComponentName className, int flags, int userId);
- ProviderInfo getProviderInfo(in ComponentName className, int flags);
+ ProviderInfo getProviderInfo(in ComponentName className, int flags, int userId);
int checkPermission(String permName, String pkgName);
@@ -98,24 +98,24 @@ interface IPackageManager {
int getUidForSharedUser(String sharedUserName);
- ResolveInfo resolveIntent(in Intent intent, String resolvedType, int flags);
+ ResolveInfo resolveIntent(in Intent intent, String resolvedType, int flags, int userId);
List<ResolveInfo> queryIntentActivities(in Intent intent,
- String resolvedType, int flags);
+ String resolvedType, int flags, int userId);
List<ResolveInfo> queryIntentActivityOptions(
in ComponentName caller, in Intent[] specifics,
in String[] specificTypes, in Intent intent,
- String resolvedType, int flags);
+ String resolvedType, int flags, int userId);
List<ResolveInfo> queryIntentReceivers(in Intent intent,
- String resolvedType, int flags);
+ String resolvedType, int flags, int userId);
ResolveInfo resolveService(in Intent intent,
- String resolvedType, int flags);
+ String resolvedType, int flags, int userId);
List<ResolveInfo> queryIntentServices(in Intent intent,
- String resolvedType, int flags);
+ String resolvedType, int flags, int userId);
/**
* This implements getInstalledPackages via a "last returned row"
@@ -131,7 +131,7 @@ interface IPackageManager {
* limit that kicks in when flags are included that bloat up the data
* returned.
*/
- ParceledListSlice getInstalledApplications(int flags, in String lastRead);
+ ParceledListSlice getInstalledApplications(int flags, in String lastRead, int userId);
/**
* Retrieve all applications that are marked as persistent.
@@ -141,7 +141,7 @@ interface IPackageManager {
*/
List<ApplicationInfo> getPersistentApplications(int flags);
- ProviderInfo resolveContentProvider(String name, int flags);
+ ProviderInfo resolveContentProvider(String name, int flags, int userId);
/**
* Retrieve sync information for all content providers.
@@ -212,28 +212,28 @@ interface IPackageManager {
* As per {@link android.content.pm.PackageManager#setComponentEnabledSetting}.
*/
void setComponentEnabledSetting(in ComponentName componentName,
- in int newState, in int flags);
+ in int newState, in int flags, int userId);
/**
* As per {@link android.content.pm.PackageManager#getComponentEnabledSetting}.
*/
- int getComponentEnabledSetting(in ComponentName componentName);
+ int getComponentEnabledSetting(in ComponentName componentName, int userId);
/**
* As per {@link android.content.pm.PackageManager#setApplicationEnabledSetting}.
*/
- void setApplicationEnabledSetting(in String packageName, in int newState, int flags);
+ void setApplicationEnabledSetting(in String packageName, in int newState, int flags, int userId);
/**
* As per {@link android.content.pm.PackageManager#getApplicationEnabledSetting}.
*/
- int getApplicationEnabledSetting(in String packageName);
+ int getApplicationEnabledSetting(in String packageName, int userId);
/**
* Set whether the given package should be considered stopped, making
* it not visible to implicit intents that filter out stopped packages.
*/
- void setPackageStoppedState(String packageName, boolean stopped);
+ void setPackageStoppedState(String packageName, boolean stopped, int userId);
/**
* Free storage by deleting LRU sorted list of cache files across
@@ -296,7 +296,7 @@ interface IPackageManager {
* files need to be deleted
* @param observer a callback used to notify when the operation is completed.
*/
- void clearApplicationUserData(in String packageName, IPackageDataObserver observer);
+ void clearApplicationUserData(in String packageName, IPackageDataObserver observer, int userId);
/**
* Get package statistics including the code, data and cache size for
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 207f077..07d231a 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -240,7 +240,13 @@ public class PackageParser {
int gids[], int flags, long firstInstallTime, long lastUpdateTime,
HashSet<String> grantedPermissions) {
- final int userId = Binder.getOrigCallingUser();
+ return generatePackageInfo(p, gids, flags, firstInstallTime, lastUpdateTime,
+ grantedPermissions, UserId.getCallingUserId());
+ }
+
+ static PackageInfo generatePackageInfo(PackageParser.Package p,
+ int gids[], int flags, long firstInstallTime, long lastUpdateTime,
+ HashSet<String> grantedPermissions, int userId) {
PackageInfo pi = new PackageInfo();
pi.packageName = p.packageName;
@@ -3350,7 +3356,7 @@ public class PackageParser {
}
public static ApplicationInfo generateApplicationInfo(Package p, int flags) {
- return generateApplicationInfo(p, flags, UserId.getUserId(Binder.getCallingUid()));
+ return generateApplicationInfo(p, flags, UserId.getCallingUserId());
}
public static ApplicationInfo generateApplicationInfo(Package p, int flags, int userId) {
@@ -3366,6 +3372,13 @@ public class PackageParser {
} else {
p.applicationInfo.flags &= ~ApplicationInfo.FLAG_STOPPED;
}
+ if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) {
+ p.applicationInfo.enabled = true;
+ } else if (p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED
+ || p.mSetEnabled == PackageManager.COMPONENT_ENABLED_STATE_DISABLED_USER) {
+ p.applicationInfo.enabled = false;
+ }
+ p.applicationInfo.enabledSetting = p.mSetEnabled;
return p.applicationInfo;
}
diff --git a/core/java/android/os/UserId.java b/core/java/android/os/UserId.java
index 0da67d6..2d06ef9 100644
--- a/core/java/android/os/UserId.java
+++ b/core/java/android/os/UserId.java
@@ -96,4 +96,12 @@ public final class UserId {
public static final int getAppId(int uid) {
return uid % PER_USER_RANGE;
}
+
+ /**
+ * Returns the user id of the current process
+ * @return user id of the current process
+ */
+ public static final int myUserId() {
+ return getUserId(Process.myUid());
+ }
}