method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
method public java.lang.String[] getAccountTypesWithManagementDisabled();
method public java.util.List<android.content.ComponentName> getActiveAdmins();
- method public java.util.List<java.lang.String> getAffiliationIds(android.content.ComponentName);
+ method public java.util.Set<java.lang.String> getAffiliationIds(android.content.ComponentName);
method public java.lang.String getAlwaysOnVpnPackage(android.content.ComponentName);
method public android.os.Bundle getApplicationRestrictions(android.content.ComponentName, java.lang.String);
method public deprecated java.lang.String getApplicationRestrictionsManagingPackage(android.content.ComponentName);
method public java.util.List<android.app.admin.SecurityLog.SecurityEvent> retrievePreRebootSecurityLogs(android.content.ComponentName);
method public java.util.List<android.app.admin.SecurityLog.SecurityEvent> retrieveSecurityLogs(android.content.ComponentName);
method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean);
- method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
+ method public void setAffiliationIds(android.content.ComponentName, java.util.Set<java.lang.String>);
method public void setAlwaysOnVpnPackage(android.content.ComponentName, java.lang.String, boolean) throws android.content.pm.PackageManager.NameNotFoundException, java.lang.UnsupportedOperationException;
method public boolean setApplicationHidden(android.content.ComponentName, java.lang.String, boolean);
method public void setApplicationRestrictions(android.content.ComponentName, java.lang.String, android.os.Bundle);
method public deprecated android.os.UserHandle createUser(android.content.ComponentName, java.lang.String);
method public deprecated java.lang.String getDeviceInitializerApp();
method public deprecated android.content.ComponentName getDeviceInitializerComponent();
+ method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
}
}
method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
method public java.lang.String[] getAccountTypesWithManagementDisabled();
method public java.util.List<android.content.ComponentName> getActiveAdmins();
- method public java.util.List<java.lang.String> getAffiliationIds(android.content.ComponentName);
+ method public java.util.Set<java.lang.String> getAffiliationIds(android.content.ComponentName);
method public java.lang.String getAlwaysOnVpnPackage(android.content.ComponentName);
method public android.os.Bundle getApplicationRestrictions(android.content.ComponentName, java.lang.String);
method public deprecated java.lang.String getApplicationRestrictionsManagingPackage(android.content.ComponentName);
method public java.util.List<android.app.admin.SecurityLog.SecurityEvent> retrieveSecurityLogs(android.content.ComponentName);
method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean);
method public deprecated boolean setActiveProfileOwner(android.content.ComponentName, java.lang.String) throws java.lang.IllegalArgumentException;
- method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
+ method public void setAffiliationIds(android.content.ComponentName, java.util.Set<java.lang.String>);
method public void setAlwaysOnVpnPackage(android.content.ComponentName, java.lang.String, boolean) throws android.content.pm.PackageManager.NameNotFoundException, java.lang.UnsupportedOperationException;
method public boolean setApplicationHidden(android.content.ComponentName, java.lang.String, boolean);
method public void setApplicationRestrictions(android.content.ComponentName, java.lang.String, android.os.Bundle);
public class DevicePolicyManager {
method public deprecated android.os.UserHandle createAndInitializeUser(android.content.ComponentName, java.lang.String, java.lang.String, android.content.ComponentName, android.os.Bundle);
method public deprecated android.os.UserHandle createUser(android.content.ComponentName, java.lang.String);
+ method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
}
}
method public int enableSystemApp(android.content.ComponentName, android.content.Intent);
method public java.lang.String[] getAccountTypesWithManagementDisabled();
method public java.util.List<android.content.ComponentName> getActiveAdmins();
- method public java.util.List<java.lang.String> getAffiliationIds(android.content.ComponentName);
+ method public java.util.Set<java.lang.String> getAffiliationIds(android.content.ComponentName);
method public java.lang.String getAlwaysOnVpnPackage(android.content.ComponentName);
method public android.os.Bundle getApplicationRestrictions(android.content.ComponentName, java.lang.String);
method public deprecated java.lang.String getApplicationRestrictionsManagingPackage(android.content.ComponentName);
method public java.util.List<android.app.admin.SecurityLog.SecurityEvent> retrievePreRebootSecurityLogs(android.content.ComponentName);
method public java.util.List<android.app.admin.SecurityLog.SecurityEvent> retrieveSecurityLogs(android.content.ComponentName);
method public void setAccountManagementDisabled(android.content.ComponentName, java.lang.String, boolean);
- method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
+ method public void setAffiliationIds(android.content.ComponentName, java.util.Set<java.lang.String>);
method public void setAlwaysOnVpnPackage(android.content.ComponentName, java.lang.String, boolean) throws android.content.pm.PackageManager.NameNotFoundException, java.lang.UnsupportedOperationException;
method public boolean setApplicationHidden(android.content.ComponentName, java.lang.String, boolean);
method public void setApplicationRestrictions(android.content.ComponentName, java.lang.String, android.os.Bundle);
method public deprecated android.os.UserHandle createUser(android.content.ComponentName, java.lang.String);
method public deprecated java.lang.String getDeviceInitializerApp();
method public deprecated android.content.ComponentName getDeviceInitializerComponent();
+ method public void setAffiliationIds(android.content.ComponentName, java.util.List<java.lang.String>);
}
}
import android.security.Credentials;
import android.service.restrictions.RestrictionsReceiver;
import android.telephony.TelephonyManager;
+import android.util.ArraySet;
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
/**
* Public interface for managing policies enforced on a device. Most clients of this class must be
* created.
*
* @param admin Which profile or device owner this request is associated with.
- * @param ids A list of opaque non-empty affiliation ids. Duplicate elements will be ignored.
+ * @param ids A set of opaque non-empty affiliation ids.
*
- * @throws NullPointerException if {@code ids} is null or contains null elements.
- * @throws IllegalArgumentException if {@code ids} contains an empty string.
+ * @throws IllegalArgumentException if {@code ids} is null or contains an empty string.
+ */
+ public void setAffiliationIds(@NonNull ComponentName admin, @NonNull Set<String> ids) {
+ throwIfParentInstance("setAffiliationIds");
+ if (ids == null) {
+ throw new IllegalArgumentException("ids must not be null");
+ }
+ try {
+ mService.setAffiliationIds(admin, new ArrayList<>(ids));
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+
+ /**
+ * STOPSHIP (b/37622682) Remove it before release.
+ * @removed
*/
public void setAffiliationIds(@NonNull ComponentName admin, @NonNull List<String> ids) {
throwIfParentInstance("setAffiliationIds");
+ if (ids == null) {
+ throw new IllegalArgumentException("ids must not be null");
+ }
try {
mService.setAffiliationIds(admin, ids);
} catch (RemoteException e) {
}
/**
- * Returns the list of affiliation ids previously set via {@link #setAffiliationIds}, or an
- * empty list if none have been set.
+ * Returns the set of affiliation ids previously set via {@link #setAffiliationIds}, or an
+ * empty set if none have been set.
*/
- public @NonNull List<String> getAffiliationIds(@NonNull ComponentName admin) {
- throwIfParentInstance("getAffiliationIds");
+ public @NonNull Set<String> getAffiliationIds(@NonNull ComponentName admin) {
try {
- return mService.getAffiliationIds(admin);
+ return new ArraySet<>(mService.getAffiliationIds(admin));
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
if (!mHasFeature) {
return;
}
+ if (ids == null) {
+ throw new IllegalArgumentException("ids must not be null");
+ }
+ for (String id : ids) {
+ if (TextUtils.isEmpty(id)) {
+ throw new IllegalArgumentException("ids must not contain empty string");
+ }
+ }
- Preconditions.checkNotNull(admin);
- Preconditions.checkCollectionElementsNotNull(ids, "ids");
-
- final Set<String> affiliationIds = new ArraySet<String>(ids);
- Preconditions.checkArgument(
- !affiliationIds.contains(""), "ids must not contain empty strings");
-
+ final Set<String> affiliationIds = new ArraySet<>(ids);
final int callingUserId = mInjector.userHandleGetCallingUserId();
synchronized (this) {
getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_PROFILE_OWNER);
// Have the profile owner specify a set of affiliation ids. Check that the test user remains
// unaffiliated.
- final List<String> userAffiliationIds = new ArrayList<>();
+ final Set<String> userAffiliationIds = new ArraySet<>();
userAffiliationIds.add("red");
userAffiliationIds.add("green");
userAffiliationIds.add("blue");
// Have the device owner specify a set of affiliation ids that do not intersect with those
// specified by the profile owner. Check that the test user remains unaffiliated.
- final List<String> deviceAffiliationIds = new ArrayList<>();
+ final Set<String> deviceAffiliationIds = new ArraySet<>();
deviceAffiliationIds.add("cyan");
deviceAffiliationIds.add("yellow");
deviceAffiliationIds.add("magenta");
assertTrue(dpm.isAffiliatedUser());
// Clear affiliation ids for the profile owner. The user becomes unaffiliated.
- dpm.setAffiliationIds(admin2, Collections.emptyList());
+ dpm.setAffiliationIds(admin2, Collections.emptySet());
assertTrue(dpm.getAffiliationIds(admin2).isEmpty());
assertFalse(dpm.isAffiliatedUser());
MoreAsserts.assertEmpty(targetUsers);
// Setting affiliation ids
- final List<String> userAffiliationIds = Arrays.asList("some.affiliation-id");
+ final Set<String> userAffiliationIds = Collections.singleton("some.affiliation-id");
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
dpm.setAffiliationIds(admin1, userAffiliationIds);
MoreAsserts.assertContentsInAnyOrder(targetUsers, UserHandle.SYSTEM);
// Changing affiliation ids in one
- dpm.setAffiliationIds(admin1, Arrays.asList("some-different-affiliation-id"));
+ dpm.setAffiliationIds(admin1, Collections.singleton("some-different-affiliation-id"));
// Since the managed profile is not affiliated any more, they should not be allowed to talk
// to each other.
addManagedProfile(adminDifferentPackage, MANAGED_PROFILE_ADMIN_UID, admin2);
// Setting affiliation ids
- final List<String> userAffiliationIds = Arrays.asList("some-affiliation-id");
+ final Set<String> userAffiliationIds = Collections.singleton("some-affiliation-id");
dpm.setAffiliationIds(admin1, userAffiliationIds);
mContext.binder.callingUid = MANAGED_PROFILE_ADMIN_UID;
assertFalse(dpm.isLockTaskPermitted("doPackage1"));
// Setting same affiliation ids
- final List<String> userAffiliationIds = Arrays.asList("some-affiliation-id");
+ final Set<String> userAffiliationIds = Collections.singleton("some-affiliation-id");
mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
dpm.setAffiliationIds(admin1, userAffiliationIds);
.updateLockTaskPackages(eq(MANAGED_PROFILE_USER_ID), eq(poPackages));
// Unaffiliate the profile, lock task mode no longer available on the profile.
- dpm.setAffiliationIds(adminDifferentPackage, Collections.<String>emptyList());
+ dpm.setAffiliationIds(adminDifferentPackage, Collections.emptySet());
assertFalse(dpm.isLockTaskPermitted("poPackage1"));
// Lock task packages cleared when loading user data and when the user becomes unaffiliated.
verify(mContext.iactivityManager, times(2))