diff options
9 files changed, 115 insertions, 121 deletions
diff --git a/api/current.txt b/api/current.txt index 55f5a6d7fdba..049272bee3ce 100644 --- a/api/current.txt +++ b/api/current.txt @@ -6579,7 +6579,6 @@ package android.app.admin { } public class DevicePolicyManager { - method public void addCrossProfileCalendarPackage(@NonNull android.content.ComponentName, @NonNull String); method public void addCrossProfileIntentFilter(@NonNull android.content.ComponentName, android.content.IntentFilter, int); method public boolean addCrossProfileWidgetProvider(@NonNull android.content.ComponentName, String); method public int addOverrideApn(@NonNull android.content.ComponentName, @NonNull android.telephony.data.ApnSetting); @@ -6609,7 +6608,7 @@ package android.app.admin { method public boolean getBluetoothContactSharingDisabled(@NonNull android.content.ComponentName); method public boolean getCameraDisabled(@Nullable android.content.ComponentName); method @Deprecated @Nullable public String getCertInstallerPackage(@NonNull android.content.ComponentName) throws java.lang.SecurityException; - method @NonNull public java.util.Set<java.lang.String> getCrossProfileCalendarPackages(@NonNull android.content.ComponentName); + method @Nullable public java.util.Set<java.lang.String> getCrossProfileCalendarPackages(@NonNull android.content.ComponentName); method public boolean getCrossProfileCallerIdDisabled(@NonNull android.content.ComponentName); method public boolean getCrossProfileContactsSearchDisabled(@NonNull android.content.ComponentName); method @NonNull public java.util.List<java.lang.String> getCrossProfileWidgetProviders(@NonNull android.content.ComponentName); @@ -6699,7 +6698,6 @@ package android.app.admin { method public int logoutUser(@NonNull android.content.ComponentName); method public void reboot(@NonNull android.content.ComponentName); method public void removeActiveAdmin(@NonNull android.content.ComponentName); - method public boolean removeCrossProfileCalendarPackage(@NonNull android.content.ComponentName, @NonNull String); method public boolean removeCrossProfileWidgetProvider(@NonNull android.content.ComponentName, String); method public boolean removeKeyPair(@Nullable android.content.ComponentName, @NonNull String); method public boolean removeOverrideApn(@NonNull android.content.ComponentName, int); @@ -6721,6 +6719,7 @@ package android.app.admin { method public void setBluetoothContactSharingDisabled(@NonNull android.content.ComponentName, boolean); method public void setCameraDisabled(@NonNull android.content.ComponentName, boolean); method @Deprecated public void setCertInstallerPackage(@NonNull android.content.ComponentName, @Nullable String) throws java.lang.SecurityException; + method public void setCrossProfileCalendarPackages(@NonNull android.content.ComponentName, @Nullable java.util.Set<java.lang.String>); method public void setCrossProfileCallerIdDisabled(@NonNull android.content.ComponentName, boolean); method public void setCrossProfileContactsSearchDisabled(@NonNull android.content.ComponentName, boolean); method public void setDelegatedScopes(@NonNull android.content.ComponentName, @NonNull String, @NonNull java.util.List<java.lang.String>); diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java index 55a3acb16b11..ae756d436ea2 100644 --- a/core/java/android/app/admin/DevicePolicyManager.java +++ b/core/java/android/app/admin/DevicePolicyManager.java @@ -10428,76 +10428,53 @@ public class DevicePolicyManager { } /** - * Whitelists a package that is allowed to access cross profile calendar APIs. + * Whitelists a set of packages that are allowed to access cross-profile calendar APIs. * * <p>Called by a profile owner of a managed profile. * - * @param admin which {@link DeviceAdminReceiver} this request is associated with. - * @param packageName name of the package to be whitelisted. - * @throws SecurityException if {@code admin} is not a profile owner. - * - * @see #removeCrossProfileCalendarPackage(ComponentName, String) - * @see #getCrossProfileCalendarPackages(ComponentName) - */ - public void addCrossProfileCalendarPackage(@NonNull ComponentName admin, - @NonNull String packageName) { - throwIfParentInstance("addCrossProfileCalendarPackage"); - if (mService != null) { - try { - mService.addCrossProfileCalendarPackage(admin, packageName); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - } - - /** - * Removes a package that was allowed to access cross profile calendar APIs - * from the whitelist. - * - * <p>Called by a profile owner of a managed profile. + * <p>Calling with a null value for the set disables the restriction so that all packages + * are allowed to access cross-profile calendar APIs. Calling with an empty set disallows + * all packages from accessing cross-profile calendar APIs. If this method isn't called, + * no package will be allowed to access cross-profile calendar APIs by default. * * @param admin which {@link DeviceAdminReceiver} this request is associated with. - * @param packageName name of the package to be removed from the whitelist. - * @return {@code true} if the package is successfully removed from the whitelist, - * {@code false} otherwise. + * @param packageNames set of packages to be whitelisted. * @throws SecurityException if {@code admin} is not a profile owner. * - * @see #addCrossProfileCalendarPackage(ComponentName, String) * @see #getCrossProfileCalendarPackages(ComponentName) */ - public boolean removeCrossProfileCalendarPackage(@NonNull ComponentName admin, - @NonNull String packageName) { - throwIfParentInstance("removeCrossProfileCalendarPackage"); + public void setCrossProfileCalendarPackages(@NonNull ComponentName admin, + @Nullable Set<String> packageNames) { + throwIfParentInstance("setCrossProfileCalendarPackages"); if (mService != null) { try { - return mService.removeCrossProfileCalendarPackage(admin, packageName); + mService.setCrossProfileCalendarPackages(admin, packageNames == null ? null + : new ArrayList<>(packageNames)); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } } - return false; } /** - * Gets a set of package names that are whitelisted to access cross profile calendar APIs. + * Gets a set of package names that are whitelisted to access cross-profile calendar APIs. * * <p>Called by a profile owner of a managed profile. * * @param admin which {@link DeviceAdminReceiver} this request is associated with. * @return the set of names of packages that were previously whitelisted via - * {@link #addCrossProfileCalendarPackage(ComponentName, String)}, or an + * {@link #setCrossProfileCalendarPackages(ComponentName, Set)}, or an * empty set if none have been whitelisted. * @throws SecurityException if {@code admin} is not a profile owner. * - * @see #addCrossProfileCalendarPackage(ComponentName, String) - * @see #removeCrossProfileCalendarPackage(ComponentName, String) + * @see #setCrossProfileCalendarPackages(ComponentName, Set) */ - public @NonNull Set<String> getCrossProfileCalendarPackages(@NonNull ComponentName admin) { + public @Nullable Set<String> getCrossProfileCalendarPackages(@NonNull ComponentName admin) { throwIfParentInstance("getCrossProfileCalendarPackages"); if (mService != null) { try { - return new ArraySet<>(mService.getCrossProfileCalendarPackages(admin)); + final List<String> packageNames = mService.getCrossProfileCalendarPackages(admin); + return packageNames == null ? null : new ArraySet<>(packageNames); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } @@ -10506,22 +10483,21 @@ public class DevicePolicyManager { } /** - * Returns if a package is whitelisted to access cross profile calendar APIs. + * Returns if a package is whitelisted to access cross-profile calendar APIs. * * <p>To query for a specific user, use * {@link Context#createPackageContextAsUser(String, int, UserHandle)} to create a context for * that user, and get a {@link DevicePolicyManager} from this context. * * @param packageName the name of the package - * @return {@code true} if the package is whitelisted to access cross profile calendar APIs. + * @return {@code true} if the package is whitelisted to access cross-profile calendar APIs. * {@code false} otherwise. * - * @see #addCrossProfileCalendarPackage(ComponentName, String) - * @see #removeCrossProfileCalendarPackage(ComponentName, String) + * @see #setCrossProfileCalendarPackages(ComponentName, Set) * @see #getCrossProfileCalendarPackages(ComponentName) * @hide */ - public @NonNull boolean isPackageAllowedToAccessCalendar(@NonNull String packageName) { + public boolean isPackageAllowedToAccessCalendar(@NonNull String packageName) { throwIfParentInstance("isPackageAllowedToAccessCalendar"); if (mService != null) { try { @@ -10535,27 +10511,27 @@ public class DevicePolicyManager { } /** - * Gets a set of package names that are whitelisted to access cross profile calendar APIs. + * Gets a set of package names that are whitelisted to access cross-profile calendar APIs. * * <p>To query for a specific user, use * {@link Context#createPackageContextAsUser(String, int, UserHandle)} to create a context for * that user, and get a {@link DevicePolicyManager} from this context. * * @return the set of names of packages that were previously whitelisted via - * {@link #addCrossProfileCalendarPackage(ComponentName, String)}, or an + * {@link #setCrossProfileCalendarPackages(ComponentName, Set)}, or an * empty set if none have been whitelisted. * - * @see #addCrossProfileCalendarPackage(ComponentName, String) - * @see #removeCrossProfileCalendarPackage(ComponentName, String) + * @see #setCrossProfileCalendarPackages(ComponentName, Set) * @see #getCrossProfileCalendarPackages(ComponentName) * @hide */ - public @NonNull Set<String> getCrossProfileCalendarPackages() { + public @Nullable Set<String> getCrossProfileCalendarPackages() { throwIfParentInstance("getCrossProfileCalendarPackages"); if (mService != null) { try { - return new ArraySet<>(mService.getCrossProfileCalendarPackagesForUser( - myUserId())); + final List<String> packageNames = mService.getCrossProfileCalendarPackagesForUser( + myUserId()); + return packageNames == null ? null : new ArraySet<>(packageNames); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl index 568becfcdd1a..1751a91caf1a 100644 --- a/core/java/android/app/admin/IDevicePolicyManager.aidl +++ b/core/java/android/app/admin/IDevicePolicyManager.aidl @@ -424,8 +424,7 @@ interface IDevicePolicyManager { void installUpdateFromFile(in ComponentName admin, in ParcelFileDescriptor updateFileDescriptor, in StartInstallingUpdateCallback listener); - void addCrossProfileCalendarPackage(in ComponentName admin, String packageName); - boolean removeCrossProfileCalendarPackage(in ComponentName admin, String packageName); + void setCrossProfileCalendarPackages(in ComponentName admin, in List<String> packageNames); List<String> getCrossProfileCalendarPackages(in ComponentName admin); boolean isPackageAllowedToAccessCalendarForUser(String packageName, int userHandle); List<String> getCrossProfileCalendarPackagesForUser(int userHandle); diff --git a/core/java/android/provider/CalendarContract.java b/core/java/android/provider/CalendarContract.java index c167ea18f0c5..8bd75d779154 100644 --- a/core/java/android/provider/CalendarContract.java +++ b/core/java/android/provider/CalendarContract.java @@ -44,6 +44,8 @@ import android.util.Log; import com.android.internal.util.Preconditions; +import java.util.Set; + /** * <p> * The contract between the calendar provider and applications. Contains @@ -217,7 +219,7 @@ public final class CalendarContract { * The intent will have its action set to * {@link CalendarContract#ACTION_VIEW_WORK_CALENDAR_EVENT} and contain extras * corresponding to the API's arguments. A calendar app intending to support - * cross profile events viewing should handle this intent, parse the arguments + * cross-profile events viewing should handle this intent, parse the arguments * and show the appropriate UI. * * @param context the context. @@ -767,9 +769,10 @@ public final class CalendarContract { * projection of the query to this uri that are not contained in the above list. * * <p>This uri will return an empty cursor if the calling user is not a parent profile - * of a managed profile, or cross profile calendar is disabled in Settings, or this uri is + * of a managed profile, or cross-profile calendar is disabled in Settings, or this uri is * queried from a package that is not whitelisted by profile owner of the managed profile - * via {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}. + * via + * {@link DevicePolicyManager#setCrossProfileCalendarPackages(ComponentName, Set)}. * * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName) * @see Settings.Secure#CROSS_PROFILE_CALENDAR_ENABLED @@ -1758,9 +1761,10 @@ public final class CalendarContract { * projection of the query to this uri that are not contained in the above list. * * <p>This uri will return an empty cursor if the calling user is not a parent profile - * of a managed profile, or cross profile calendar is disabled in Settings, or this uri is + * of a managed profile, or cross-profile calendar is disabled in Settings, or this uri is * queried from a package that is not whitelisted by profile owner of the managed profile - * via {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}. + * via + * {@link DevicePolicyManager#setCrossProfileCalendarPackages(ComponentName, Set)}. * * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName) * @see Settings.Secure#CROSS_PROFILE_CALENDAR_ENABLED @@ -1968,10 +1972,10 @@ public final class CalendarContract { * projection of the query to this uri that are not contained in the above list. * * <p>This uri will return an empty cursor if the calling user is not a parent profile - * of a managed profile, or cross profile calendar for the managed profile is disabled in + * of a managed profile, or cross-profile calendar for the managed profile is disabled in * Settings, or this uri is queried from a package that is not whitelisted by * profile owner of the managed profile via - * {@link DevicePolicyManager#addCrossProfileCalendarPackage(ComponentName, String)}. + * {@link DevicePolicyManager#setCrossProfileCalendarPackages(ComponentName, Set)}. * * @see DevicePolicyManager#getCrossProfileCalendarPackages(ComponentName) * @see Settings.Secure#CROSS_PROFILE_CALENDAR_ENABLED diff --git a/core/proto/android/stats/devicepolicy/device_policy_enums.proto b/core/proto/android/stats/devicepolicy/device_policy_enums.proto index 82460ec4ed8b..a8e64c6d8324 100644 --- a/core/proto/android/stats/devicepolicy/device_policy_enums.proto +++ b/core/proto/android/stats/devicepolicy/device_policy_enums.proto @@ -92,8 +92,7 @@ enum EventId { SET_UNINSTALL_BLOCKED = 67; SET_PACKAGES_SUSPENDED = 68; ON_LOCK_TASK_MODE_ENTERING = 69; - ADD_CROSS_PROFILE_CALENDAR_PACKAGE = 70; - REMOVE_CROSS_PROFILE_CALENDAR_PACKAGE = 71; + SET_CROSS_PROFILE_CALENDAR_PACKAGES = 70; GET_USER_PASSWORD_COMPLEXITY_LEVEL = 72; INSTALL_SYSTEM_UPDATE = 73; INSTALL_SYSTEM_UPDATE_ERROR = 74; diff --git a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java index 74aaf3c26aba..93f6a94dcf49 100644 --- a/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java +++ b/packages/SettingsLib/src/com/android/settingslib/RestrictedLockUtilsInternal.java @@ -47,6 +47,7 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.widget.LockPatternUtils; import java.util.List; +import java.util.Set; /** * Utility class to host methods usable in adding a restricted padlock icon and showing admin @@ -325,7 +326,8 @@ public class RestrictedLockUtilsInternal extends RestrictedLockUtils { if (admin == null) { return null; } - if (dpm.getCrossProfileCalendarPackages().isEmpty()) { + final Set<String> packages = dpm.getCrossProfileCalendarPackages(); + if (packages != null && packages.isEmpty()) { return admin; } return null; diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java index d8225b38487c..2bf6f357bec8 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/BaseIDevicePolicyManager.java @@ -108,12 +108,7 @@ abstract class BaseIDevicePolicyManager extends IDevicePolicyManager.Stub { ParcelFileDescriptor updateFileDescriptor, StartInstallingUpdateCallback listener) {} @Override - public void addCrossProfileCalendarPackage(ComponentName admin, String packageName) { - } - - @Override - public boolean removeCrossProfileCalendarPackage(ComponentName admin, String packageName) { - return false; + public void setCrossProfileCalendarPackages(ComponentName admin, List<String> packageNames) { } @Override diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java index 54053a896df9..23c68b246510 100644 --- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java +++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java @@ -949,8 +949,8 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { "metered_data_disabled_packages"; private static final String TAG_CROSS_PROFILE_CALENDAR_PACKAGES = "cross-profile-calendar-packages"; - private static final String TAG_PACKAGE = "package"; - + private static final String TAG_CROSS_PROFILE_CALENDAR_PACKAGES_NULL = + "cross-profile-calendar-packages-null"; DeviceAdminInfo info; @@ -1072,7 +1072,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { String endUserSessionMessage = null; // The whitelist of packages that can access cross profile calendar APIs. - final Set<String> mCrossProfileCalendarPackages = new ArraySet<>(); + // This whitelist should be in default an empty list, which indicates that no package + // is whitelisted. + List<String> mCrossProfileCalendarPackages = Collections.emptyList(); ActiveAdmin(DeviceAdminInfo _info, boolean parent) { info = _info; @@ -1343,11 +1345,12 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { out.text(endUserSessionMessage); out.endTag(null, TAG_END_USER_SESSION_MESSAGE); } - if (!mCrossProfileCalendarPackages.isEmpty()) { - out.startTag(null, TAG_CROSS_PROFILE_CALENDAR_PACKAGES); - writeAttributeValuesToXml( - out, TAG_PACKAGE, mCrossProfileCalendarPackages); - out.endTag(null, TAG_CROSS_PROFILE_CALENDAR_PACKAGES); + if (mCrossProfileCalendarPackages == null) { + out.startTag(null, TAG_CROSS_PROFILE_CALENDAR_PACKAGES_NULL); + out.endTag(null, TAG_CROSS_PROFILE_CALENDAR_PACKAGES_NULL); + } else { + writePackageListToXml(out, TAG_CROSS_PROFILE_CALENDAR_PACKAGES, + mCrossProfileCalendarPackages); } } @@ -1542,8 +1545,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { Log.w(LOG_TAG, "Missing text when loading end session message"); } } else if (TAG_CROSS_PROFILE_CALENDAR_PACKAGES.equals(tag)) { - readAttributeValues( - parser, TAG_PACKAGE, mCrossProfileCalendarPackages); + mCrossProfileCalendarPackages = readPackageList(parser, tag); + } else if (TAG_CROSS_PROFILE_CALENDAR_PACKAGES_NULL.equals(tag)) { + mCrossProfileCalendarPackages = null; } else { Slog.w(LOG_TAG, "Unknown admin tag: " + tag); XmlUtils.skipCurrentTag(parser); @@ -1759,8 +1763,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { pw.print(prefix); pw.println("parentAdmin:"); parentAdmin.dump(prefix + " ", pw); } - pw.print(prefix); pw.print("mCrossProfileCalendarPackages="); - pw.println(mCrossProfileCalendarPackages); + if (mCrossProfileCalendarPackages != null) { + pw.print(prefix); pw.print("mCrossProfileCalendarPackages="); + pw.println(mCrossProfileCalendarPackages); + } } } @@ -13988,55 +13994,27 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { } @Override - public void addCrossProfileCalendarPackage(ComponentName who, String packageName) { + public void setCrossProfileCalendarPackages(ComponentName who, List<String> packageNames) { if (!mHasFeature) { return; } Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkStringNotEmpty(packageName, "Package name is null or empty"); synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked( who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); - if (admin.mCrossProfileCalendarPackages.add(packageName)) { - saveSettingsLocked(mInjector.userHandleGetCallingUserId()); - } + admin.mCrossProfileCalendarPackages = packageNames; + saveSettingsLocked(mInjector.userHandleGetCallingUserId()); } DevicePolicyEventLogger - .createEvent(DevicePolicyEnums.ADD_CROSS_PROFILE_CALENDAR_PACKAGE) + .createEvent(DevicePolicyEnums.SET_CROSS_PROFILE_CALENDAR_PACKAGES) .setAdmin(who) - .setStrings(packageName) + .setStrings(packageNames == null ? null + : packageNames.toArray(new String[packageNames.size()])) .write(); } @Override - public boolean removeCrossProfileCalendarPackage(ComponentName who, String packageName) { - if (!mHasFeature) { - return false; - } - Preconditions.checkNotNull(who, "ComponentName is null"); - Preconditions.checkStringNotEmpty(packageName, "Package name is null or empty"); - - boolean isRemoved = false; - synchronized (getLockObject()) { - final ActiveAdmin admin = getActiveAdminForCallerLocked( - who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); - isRemoved = admin.mCrossProfileCalendarPackages.remove(packageName); - if (isRemoved) { - saveSettingsLocked(mInjector.userHandleGetCallingUserId()); - } - } - if (isRemoved) { - DevicePolicyEventLogger - .createEvent(DevicePolicyEnums.REMOVE_CROSS_PROFILE_CALENDAR_PACKAGE) - .setAdmin(who) - .setStrings(packageName) - .write(); - } - return isRemoved; - } - - @Override public List<String> getCrossProfileCalendarPackages(ComponentName who) { if (!mHasFeature) { return Collections.emptyList(); @@ -14046,7 +14024,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { synchronized (getLockObject()) { final ActiveAdmin admin = getActiveAdminForCallerLocked( who, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER); - return new ArrayList<String>(admin.mCrossProfileCalendarPackages); + return admin.mCrossProfileCalendarPackages; } } @@ -14062,6 +14040,9 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { synchronized (getLockObject()) { final ActiveAdmin admin = getProfileOwnerAdminLocked(userHandle); if (admin != null) { + if (admin.mCrossProfileCalendarPackages == null) { + return true; + } return admin.mCrossProfileCalendarPackages.contains(packageName); } } @@ -14077,7 +14058,7 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager { synchronized (getLockObject()) { final ActiveAdmin admin = getProfileOwnerAdminLocked(userHandle); if (admin != null) { - return new ArrayList<String>(admin.mCrossProfileCalendarPackages); + return admin.mCrossProfileCalendarPackages; } } return Collections.emptyList(); diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java index 0813e6fa0252..535198b3dbfa 100644 --- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java +++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java @@ -5239,6 +5239,45 @@ public class DevicePolicyManagerTest extends DpmTestBase { assertEquals(PASSWORD_COMPLEXITY_HIGH, dpm.getPasswordComplexity()); } + public void testCrossProfileCalendarPackages_initiallyEmpty() { + setAsProfileOwner(admin1); + final Set<String> packages = dpm.getCrossProfileCalendarPackages(admin1); + assertCrossProfileCalendarPackagesEqual(packages, Collections.emptySet()); + } + + public void testCrossProfileCalendarPackages_reopenDpms() { + setAsProfileOwner(admin1); + dpm.setCrossProfileCalendarPackages(admin1, null); + Set<String> packages = dpm.getCrossProfileCalendarPackages(admin1); + assertTrue(packages == null); + initializeDpms(); + packages = dpm.getCrossProfileCalendarPackages(admin1); + assertTrue(packages == null); + + dpm.setCrossProfileCalendarPackages(admin1, Collections.emptySet()); + packages = dpm.getCrossProfileCalendarPackages(admin1); + assertCrossProfileCalendarPackagesEqual(packages, Collections.emptySet()); + initializeDpms(); + packages = dpm.getCrossProfileCalendarPackages(admin1); + assertCrossProfileCalendarPackagesEqual(packages, Collections.emptySet()); + + final String dummyPackageName = "test"; + final Set<String> testPackages = new ArraySet<String>(Arrays.asList(dummyPackageName)); + dpm.setCrossProfileCalendarPackages(admin1, testPackages); + packages = dpm.getCrossProfileCalendarPackages(admin1); + assertCrossProfileCalendarPackagesEqual(packages, testPackages); + initializeDpms(); + packages = dpm.getCrossProfileCalendarPackages(admin1); + assertCrossProfileCalendarPackagesEqual(packages, testPackages); + } + + private void assertCrossProfileCalendarPackagesEqual(Set<String> expected, Set<String> actual) { + assertTrue(expected != null); + assertTrue(actual != null); + assertTrue(expected.containsAll(actual)); + assertTrue(actual.containsAll(expected)); + } + private void configureProfileOwnerForDeviceIdAccess(ComponentName who, int userId) { final long ident = mServiceContext.binder.clearCallingIdentity(); mServiceContext.binder.callingUid = |