diff options
author | Nicolas Prevot <nprevot@google.com> | 2015-03-16 11:25:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-03-16 11:25:51 +0000 |
commit | 8458e531bfc681ebb0de98476d782ca4d052a145 (patch) | |
tree | f571749292893ee67cd3b7fa8c8b7f1ee25fc81f | |
parent | 4cd92835be0a4ed2b32b398b0fa9d0d74dfb8b19 (diff) | |
parent | 4b8d5821512c6a4fdaf442f6d48e1dc412539136 (diff) | |
download | frameworks_base-8458e531bfc681ebb0de98476d782ca4d052a145.zip frameworks_base-8458e531bfc681ebb0de98476d782ca4d052a145.tar.gz frameworks_base-8458e531bfc681ebb0de98476d782ca4d052a145.tar.bz2 |
Merge "Remove the owner userid of cross-profile intent filters."
5 files changed, 20 insertions, 39 deletions
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java index f35e746..9f81670 100644 --- a/core/java/android/app/ApplicationPackageManager.java +++ b/core/java/android/app/ApplicationPackageManager.java @@ -1662,7 +1662,7 @@ final class ApplicationPackageManager extends PackageManager { int flags) { try { mPM.addCrossProfileIntentFilter(filter, mContext.getOpPackageName(), - mContext.getUserId(), sourceUserId, targetUserId, flags); + sourceUserId, targetUserId, flags); } catch (RemoteException e) { // Should never happen! } @@ -1674,8 +1674,7 @@ final class ApplicationPackageManager extends PackageManager { @Override public void clearCrossProfileIntentFilters(int sourceUserId) { try { - mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName(), - mContext.getUserId()); + mPM.clearCrossProfileIntentFilters(sourceUserId, mContext.getOpPackageName()); } catch (RemoteException e) { // Should never happen! } diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl index b518498..3e5d362 100644 --- a/core/java/android/content/pm/IPackageManager.aidl +++ b/core/java/android/content/pm/IPackageManager.aidl @@ -261,9 +261,9 @@ interface IPackageManager { void clearPackagePersistentPreferredActivities(String packageName, int userId); void addCrossProfileIntentFilter(in IntentFilter intentFilter, String ownerPackage, - int ownerUserId, int sourceUserId, int targetUserId, int flags); + int sourceUserId, int targetUserId, int flags); - void clearCrossProfileIntentFilters(int sourceUserId, String ownerPackage, int ownerUserId); + void clearCrossProfileIntentFilters(int sourceUserId, String ownerPackage); /** * Report the set of 'Home' activity candidates, plus (if any) which of them diff --git a/services/core/java/com/android/server/pm/CrossProfileIntentFilter.java b/services/core/java/com/android/server/pm/CrossProfileIntentFilter.java index 6d18531..ff4049b 100644 --- a/services/core/java/com/android/server/pm/CrossProfileIntentFilter.java +++ b/services/core/java/com/android/server/pm/CrossProfileIntentFilter.java @@ -33,7 +33,6 @@ import android.os.UserHandle; class CrossProfileIntentFilter extends IntentFilter { private static final String ATTR_TARGET_USER_ID = "targetUserId"; private static final String ATTR_FLAGS = "flags"; - private static final String ATTR_OWNER_USER_ID = "ownerUserId"; private static final String ATTR_OWNER_PACKAGE = "ownerPackage"; private static final String ATTR_FILTER = "filter"; @@ -41,15 +40,13 @@ class CrossProfileIntentFilter extends IntentFilter { // If the intent matches the IntentFilter, then it can be forwarded to this userId. final int mTargetUserId; - final int mOwnerUserId; // userId of the app which has set this CrossProfileIntentFilter. final String mOwnerPackage; // packageName of the app. final int mFlags; - CrossProfileIntentFilter(IntentFilter filter, String ownerPackage, int ownerUserId, - int targetUserId, int flags) { + CrossProfileIntentFilter(IntentFilter filter, String ownerPackage, int targetUserId, + int flags) { super(filter); mTargetUserId = targetUserId; - mOwnerUserId = ownerUserId; mOwnerPackage = ownerPackage; mFlags = flags; } @@ -62,17 +59,12 @@ class CrossProfileIntentFilter extends IntentFilter { return mFlags; } - public int getOwnerUserId() { - return mOwnerUserId; - } - public String getOwnerPackage() { return mOwnerPackage; } CrossProfileIntentFilter(XmlPullParser parser) throws XmlPullParserException, IOException { mTargetUserId = getIntFromXml(parser, ATTR_TARGET_USER_ID, UserHandle.USER_NULL); - mOwnerUserId = getIntFromXml(parser, ATTR_OWNER_USER_ID, UserHandle.USER_NULL); mOwnerPackage = getStringFromXml(parser, ATTR_OWNER_PACKAGE, ""); mFlags = getIntFromXml(parser, ATTR_FLAGS, 0); @@ -129,7 +121,6 @@ class CrossProfileIntentFilter extends IntentFilter { public void writeToXml(XmlSerializer serializer) throws IOException { serializer.attribute(null, ATTR_TARGET_USER_ID, Integer.toString(mTargetUserId)); serializer.attribute(null, ATTR_FLAGS, Integer.toString(mFlags)); - serializer.attribute(null, ATTR_OWNER_USER_ID, Integer.toString(mOwnerUserId)); serializer.attribute(null, ATTR_OWNER_PACKAGE, mOwnerPackage); serializer.startTag(null, ATTR_FILTER); super.writeToXml(serializer); @@ -144,7 +135,6 @@ class CrossProfileIntentFilter extends IntentFilter { boolean equalsIgnoreFilter(CrossProfileIntentFilter other) { return mTargetUserId == other.mTargetUserId - && mOwnerUserId == other.mOwnerUserId && mOwnerPackage.equals(other.mOwnerPackage) && mFlags == other.mFlags; } diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java index 7df7eb3..52411bf 100644 --- a/services/core/java/com/android/server/pm/PackageManagerService.java +++ b/services/core/java/com/android/server/pm/PackageManagerService.java @@ -11792,11 +11792,11 @@ public class PackageManagerService extends IPackageManager.Stub { @Override public void addCrossProfileIntentFilter(IntentFilter intentFilter, String ownerPackage, - int ownerUserId, int sourceUserId, int targetUserId, int flags) { + int sourceUserId, int targetUserId, int flags) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); int callingUid = Binder.getCallingUid(); - enforceOwnerRights(ownerPackage, ownerUserId, callingUid); + enforceOwnerRights(ownerPackage, callingUid); enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, callingUid, sourceUserId); if (intentFilter.countActions() == 0) { Slog.w(TAG, "Cannot set a crossProfile intent filter with no filter actions"); @@ -11804,7 +11804,7 @@ public class PackageManagerService extends IPackageManager.Stub { } synchronized (mPackages) { CrossProfileIntentFilter newFilter = new CrossProfileIntentFilter(intentFilter, - ownerPackage, UserHandle.getUserId(callingUid), targetUserId, flags); + ownerPackage, targetUserId, flags); CrossProfileIntentResolver resolver = mSettings.editCrossProfileIntentResolverLPw(sourceUserId); ArrayList<CrossProfileIntentFilter> existing = resolver.findFilters(intentFilter); @@ -11823,22 +11823,19 @@ public class PackageManagerService extends IPackageManager.Stub { } @Override - public void clearCrossProfileIntentFilters(int sourceUserId, String ownerPackage, - int ownerUserId) { + public void clearCrossProfileIntentFilters(int sourceUserId, String ownerPackage) { mContext.enforceCallingOrSelfPermission( android.Manifest.permission.INTERACT_ACROSS_USERS_FULL, null); int callingUid = Binder.getCallingUid(); - enforceOwnerRights(ownerPackage, ownerUserId, callingUid); + enforceOwnerRights(ownerPackage, callingUid); enforceShellRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES, callingUid, sourceUserId); - int callingUserId = UserHandle.getUserId(callingUid); synchronized (mPackages) { CrossProfileIntentResolver resolver = mSettings.editCrossProfileIntentResolverLPw(sourceUserId); ArraySet<CrossProfileIntentFilter> set = new ArraySet<CrossProfileIntentFilter>(resolver.filterSet()); for (CrossProfileIntentFilter filter : set) { - if (filter.getOwnerPackage().equals(ownerPackage) - && filter.getOwnerUserId() == callingUserId) { + if (filter.getOwnerPackage().equals(ownerPackage)) { resolver.removeFilter(filter); } } @@ -11847,17 +11844,12 @@ public class PackageManagerService extends IPackageManager.Stub { } // Enforcing that callingUid is owning pkg on userId - private void enforceOwnerRights(String pkg, int userId, int callingUid) { + private void enforceOwnerRights(String pkg, int callingUid) { // The system owns everything. if (UserHandle.getAppId(callingUid) == Process.SYSTEM_UID) { return; } int callingUserId = UserHandle.getUserId(callingUid); - if (callingUserId != userId) { - throw new SecurityException("calling uid " + callingUid - + " pretends to own " + pkg + " on user " + userId + " but belongs to user " - + callingUserId); - } PackageInfo pi = getPackageInfo(pkg, 0, callingUserId); if (pi == null) { throw new IllegalArgumentException("Unknown package " + pkg + " on user " diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 8e3eaaf..985c93c 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -4504,12 +4504,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { long id = Binder.clearCallingIdentity(); try { if ((flags & DevicePolicyManager.FLAG_PARENT_CAN_ACCESS_MANAGED) != 0) { - pm.addCrossProfileIntentFilter(filter, who.getPackageName(), - mContext.getUserId(), callingUserId, UserHandle.USER_OWNER, 0); + pm.addCrossProfileIntentFilter(filter, who.getPackageName(), callingUserId, + UserHandle.USER_OWNER, 0); } if ((flags & DevicePolicyManager.FLAG_MANAGED_CAN_ACCESS_PARENT) != 0) { pm.addCrossProfileIntentFilter(filter, who.getPackageName(), - mContext.getUserId(), UserHandle.USER_OWNER, callingUserId, 0); + UserHandle.USER_OWNER, callingUserId, 0); } } catch (RemoteException re) { // Shouldn't happen @@ -4527,12 +4527,12 @@ public class DevicePolicyManagerService extends IDevicePolicyManager.Stub { IPackageManager pm = AppGlobals.getPackageManager(); long id = Binder.clearCallingIdentity(); try { - pm.clearCrossProfileIntentFilters(callingUserId, who.getPackageName(), - callingUserId); + // Removing those that go from the managed profile to the primary user. + pm.clearCrossProfileIntentFilters(callingUserId, who.getPackageName()); + // And those that go from the primary user to the managed profile. // If we want to support multiple managed profiles, we will have to only remove // those that have callingUserId as their target. - pm.clearCrossProfileIntentFilters(UserHandle.USER_OWNER, who.getPackageName(), - callingUserId); + pm.clearCrossProfileIntentFilters(UserHandle.USER_OWNER, who.getPackageName()); } catch (RemoteException re) { // Shouldn't happen } finally { |