summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jonathan Scott <scottjonathan@google.com> 2023-01-16 11:33:54 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-01-16 11:33:54 +0000
commit2b7e1dccdc8c41dd5db45c677ca86789b81cfa54 (patch)
tree176490a8b92b4d428f6cac5107ad708283bf8b97
parentc1de654155fb1c6b820916a92134441905ba0c50 (diff)
parent6369ffad26ea8e6ca9bf62bde1fd29ffbf25d988 (diff)
Merge changes from topics "docheckfix4", "docheckfix5", "hasFeatureCrossUser", "testuser"
* changes: Fix incorrect check for Sysuser. Update DO and role holder requirements to block if there are accounts on any user. Allow use of #hasFeatures across users. Update Device Owner and Role Holder requirements to allow FOR_TESTING users. Add FOR_TESTING UserInfo Flag.
-rw-r--r--core/api/test-current.txt2
-rw-r--r--core/java/android/accounts/AccountManager.java15
-rw-r--r--core/java/android/accounts/IAccountManager.aidl2
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java30
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl1
-rw-r--r--core/java/android/content/pm/UserInfo.java19
-rw-r--r--services/core/java/com/android/server/accounts/AccountManagerService.java14
-rw-r--r--services/core/java/com/android/server/pm/PackageManagerShellCommand.java6
-rw-r--r--services/core/java/com/android/server/pm/UserManagerService.java3
-rw-r--r--services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java112
-rw-r--r--services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java21
-rw-r--r--services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java4
12 files changed, 181 insertions, 48 deletions
diff --git a/core/api/test-current.txt b/core/api/test-current.txt
index f9bab59bbe45..8c64e4046013 100644
--- a/core/api/test-current.txt
+++ b/core/api/test-current.txt
@@ -528,6 +528,7 @@ package android.app.admin {
method @NonNull public static String operationSafetyReasonToString(int);
method @NonNull public static String operationToString(int);
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public void resetDefaultCrossProfileIntentFilters(int);
+ method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState();
method @RequiresPermission(allOf={android.Manifest.permission.MANAGE_DEVICE_ADMINS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public void setActiveAdmin(@NonNull android.content.ComponentName, boolean, int);
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwner(@NonNull android.content.ComponentName, int);
method @RequiresPermission(android.Manifest.permission.MANAGE_PROFILE_AND_DEVICE_OWNERS) public boolean setDeviceOwnerOnly(@NonNull android.content.ComponentName, int);
@@ -897,6 +898,7 @@ package android.content.pm {
method public boolean isDemo();
method public boolean isEnabled();
method public boolean isEphemeral();
+ method public boolean isForTesting();
method public boolean isFull();
method public boolean isGuest();
method public boolean isInitialized();
diff --git a/core/java/android/accounts/AccountManager.java b/core/java/android/accounts/AccountManager.java
index dbdee0771ad4..821a23cb0e48 100644
--- a/core/java/android/accounts/AccountManager.java
+++ b/core/java/android/accounts/AccountManager.java
@@ -16,6 +16,8 @@
package android.accounts;
+import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
+
import android.annotation.BroadcastBehavior;
import android.annotation.IntDef;
import android.annotation.NonNull;
@@ -891,15 +893,24 @@ public class AccountManager {
* @return An {@link AccountManagerFuture} which resolves to a Boolean, true if the account
* exists and has all of the specified features.
*/
+ @UserHandleAware(enabledSinceTargetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE,
+ requiresPermissionIfNotCaller = INTERACT_ACROSS_USERS_FULL)
public AccountManagerFuture<Boolean> hasFeatures(final Account account,
final String[] features,
AccountManagerCallback<Boolean> callback, Handler handler) {
+ return hasFeaturesAsUser(account, features, callback, handler, mContext.getUserId());
+ }
+
+ private AccountManagerFuture<Boolean> hasFeaturesAsUser(
+ final Account account, final String[] features,
+ AccountManagerCallback<Boolean> callback, Handler handler, int userId) {
if (account == null) throw new IllegalArgumentException("account is null");
if (features == null) throw new IllegalArgumentException("features is null");
return new Future2Task<Boolean>(handler, callback) {
@Override
public void doWork() throws RemoteException {
- mService.hasFeatures(mResponse, account, features, mContext.getOpPackageName());
+ mService.hasFeatures(
+ mResponse, account, features, userId, mContext.getOpPackageName());
}
@Override
public Boolean bundleToResult(Bundle bundle) throws AuthenticatorException {
@@ -3319,7 +3330,7 @@ public class AccountManager {
* @hide
*/
@SystemApi
- @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+ @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
public AccountManagerFuture<Bundle> finishSessionAsUser(
final Bundle sessionBundle,
final Activity activity,
diff --git a/core/java/android/accounts/IAccountManager.aidl b/core/java/android/accounts/IAccountManager.aidl
index a3a7b0ccbc2b..08fb3080b3ad 100644
--- a/core/java/android/accounts/IAccountManager.aidl
+++ b/core/java/android/accounts/IAccountManager.aidl
@@ -38,7 +38,7 @@ interface IAccountManager {
Account[] getAccountsByTypeForPackage(String type, String packageName, String opPackageName);
Account[] getAccountsAsUser(String accountType, int userId, String opPackageName);
void hasFeatures(in IAccountManagerResponse response, in Account account, in String[] features,
- String opPackageName);
+ int userId, String opPackageName);
void getAccountByTypeAndFeatures(in IAccountManagerResponse response, String accountType,
in String[] features, String opPackageName);
void getAccountsByFeatures(in IAccountManagerResponse response, String accountType,
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index 1633073d7cc8..33721a0de32f 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -19,6 +19,7 @@ package android.app.admin;
import static android.Manifest.permission.QUERY_ADMIN_POLICY;
import static android.Manifest.permission.SET_TIME;
import static android.Manifest.permission.SET_TIME_ZONE;
+import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
import static android.content.Intent.LOCAL_FLAG_FROM_SYSTEM;
import static android.net.NetworkCapabilities.NET_ENTERPRISE_ID_1;
@@ -4186,7 +4187,7 @@ public class DevicePolicyManager {
* @hide
*/
@SystemApi
- @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+ @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
public boolean packageHasActiveAdmins(String packageName) {
return packageHasActiveAdmins(packageName, myUserId());
}
@@ -8743,7 +8744,7 @@ public class DevicePolicyManager {
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
@RequiresPermission(allOf = {
android.Manifest.permission.MANAGE_DEVICE_ADMINS,
- android.Manifest.permission.INTERACT_ACROSS_USERS_FULL
+ INTERACT_ACROSS_USERS_FULL
})
public void setActiveAdmin(@NonNull ComponentName policyReceiver, boolean refreshing,
int userHandle) {
@@ -10654,7 +10655,7 @@ public class DevicePolicyManager {
*/
@UserHandleAware
@RequiresPermission(allOf = {
- android.Manifest.permission.INTERACT_ACROSS_USERS_FULL,
+ INTERACT_ACROSS_USERS_FULL,
android.Manifest.permission.MANAGE_USERS
}, conditional = true)
public @Nullable List<String> getPermittedInputMethods() {
@@ -14845,7 +14846,7 @@ public class DevicePolicyManager {
* @hide
*/
@RequiresPermission(anyOf = {
- permission.INTERACT_ACROSS_USERS_FULL,
+ INTERACT_ACROSS_USERS_FULL,
permission.INTERACT_ACROSS_USERS
}, conditional = true)
public boolean isPackageAllowedToAccessCalendar(@NonNull String packageName) {
@@ -14877,7 +14878,7 @@ public class DevicePolicyManager {
* @hide
*/
@RequiresPermission(anyOf = {
- permission.INTERACT_ACROSS_USERS_FULL,
+ INTERACT_ACROSS_USERS_FULL,
permission.INTERACT_ACROSS_USERS
})
public @Nullable Set<String> getCrossProfileCalendarPackages() {
@@ -14970,7 +14971,7 @@ public class DevicePolicyManager {
* @hide
*/
@RequiresPermission(anyOf = {
- permission.INTERACT_ACROSS_USERS_FULL,
+ INTERACT_ACROSS_USERS_FULL,
permission.INTERACT_ACROSS_USERS,
permission.INTERACT_ACROSS_PROFILES
})
@@ -16154,6 +16155,23 @@ public class DevicePolicyManager {
}
/**
+ * Reset cache for {@link #shouldAllowBypassingDevicePolicyManagementRoleQualification}.
+ *
+ * @hide
+ */
+ @TestApi
+ @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS)
+ public void resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState() {
+ if (mService != null) {
+ try {
+ mService.resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState();
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ }
+ }
+
+ /**
* @return {@code true} if bypassing the device policy management role qualification is allowed
* with the current state of the device.
*
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 20695ca1f78d..aebeaf0897c8 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -575,6 +575,7 @@ interface IDevicePolicyManager {
void resetStrings(in List<String> stringIds);
ParcelableResource getString(String stringId);
+ void resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState();
boolean shouldAllowBypassingDevicePolicyManagementRoleQualification();
List<UserHandle> getPolicyManagedProfiles(in UserHandle userHandle);
diff --git a/core/java/android/content/pm/UserInfo.java b/core/java/android/content/pm/UserInfo.java
index 2be0323a1e8b..44747fabad97 100644
--- a/core/java/android/content/pm/UserInfo.java
+++ b/core/java/android/content/pm/UserInfo.java
@@ -171,6 +171,16 @@ public class UserInfo implements Parcelable {
public static final int FLAG_MAIN = 0x00004000;
/**
+ * Indicates that this user was created for the purposes of testing.
+ *
+ * <p>These users are subject to removal during tests and should not be used on actual devices
+ * used by humans.
+ *
+ * @hide
+ */
+ public static final int FLAG_FOR_TESTING = 0x00008000;
+
+ /**
* @hide
*/
@IntDef(flag = true, prefix = "FLAG_", value = {
@@ -188,7 +198,8 @@ public class UserInfo implements Parcelable {
FLAG_SYSTEM,
FLAG_PROFILE,
FLAG_EPHEMERAL_ON_CREATE,
- FLAG_MAIN
+ FLAG_MAIN,
+ FLAG_FOR_TESTING
})
@Retention(RetentionPolicy.SOURCE)
public @interface UserInfoFlag {
@@ -369,6 +380,12 @@ public class UserInfo implements Parcelable {
return (flags & FLAG_EPHEMERAL) == FLAG_EPHEMERAL;
}
+ /** @hide */
+ @TestApi
+ public boolean isForTesting() {
+ return (flags & FLAG_FOR_TESTING) == FLAG_FOR_TESTING;
+ }
+
public boolean isInitialized() {
return (flags & FLAG_INITIALIZED) == FLAG_INITIALIZED;
}
diff --git a/services/core/java/com/android/server/accounts/AccountManagerService.java b/services/core/java/com/android/server/accounts/AccountManagerService.java
index 88492edc9a73..35b5f1b05788 100644
--- a/services/core/java/com/android/server/accounts/AccountManagerService.java
+++ b/services/core/java/com/android/server/accounts/AccountManagerService.java
@@ -2010,7 +2010,7 @@ public class AccountManagerService
@Override
public void hasFeatures(IAccountManagerResponse response,
- Account account, String[] features, String opPackageName) {
+ Account account, String[] features, int userId, String opPackageName) {
int callingUid = Binder.getCallingUid();
mAppOpsManager.checkPackage(callingUid, opPackageName);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
@@ -2018,12 +2018,22 @@ public class AccountManagerService
+ ", response " + response
+ ", features " + Arrays.toString(features)
+ ", caller's uid " + callingUid
+ + ", userId " + userId
+ ", pid " + Binder.getCallingPid());
}
Preconditions.checkArgument(account != null, "account cannot be null");
Preconditions.checkArgument(response != null, "response cannot be null");
Preconditions.checkArgument(features != null, "features cannot be null");
- int userId = UserHandle.getCallingUserId();
+
+ if (userId != UserHandle.getCallingUserId()
+ && callingUid != Process.SYSTEM_UID
+ && mContext.checkCallingOrSelfPermission(
+ android.Manifest.permission.INTERACT_ACROSS_USERS_FULL)
+ != PackageManager.PERMISSION_GRANTED) {
+ throw new SecurityException("User " + UserHandle.getCallingUserId()
+ + " trying to check account features for " + userId);
+ }
+
checkReadAccountsPermitted(callingUid, account.type, userId,
opPackageName);
diff --git a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
index 12841a447cf7..0685435424e1 100644
--- a/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
+++ b/services/core/java/com/android/server/pm/PackageManagerShellCommand.java
@@ -2875,6 +2875,8 @@ class PackageManagerShellCommand extends ShellCommand {
newUserType = UserManager.USER_TYPE_FULL_DEMO;
} else if ("--ephemeral".equals(opt)) {
flags |= UserInfo.FLAG_EPHEMERAL;
+ } else if ("--for-testing".equals(opt)) {
+ flags |= UserInfo.FLAG_FOR_TESTING;
} else if ("--pre-create-only".equals(opt)) {
preCreateOnly = true;
} else if ("--user-type".equals(opt)) {
@@ -4269,8 +4271,8 @@ class PackageManagerShellCommand extends ShellCommand {
pw.println(" list users");
pw.println(" Lists the current users.");
pw.println("");
- pw.println(" create-user [--profileOf USER_ID] [--managed] [--restricted] [--ephemeral]");
- pw.println(" [--guest] [--pre-create-only] [--user-type USER_TYPE] USER_NAME");
+ pw.println(" create-user [--profileOf USER_ID] [--managed] [--restricted] [--guest]");
+ pw.println(" [--user-type USER_TYPE] [--ephemeral] [--for-testing] [--pre-create-only] USER_NAME");
pw.println(" Create a new user with the given USER_NAME, printing the new user identifier");
pw.println(" of the user.");
// TODO(b/142482943): Consider fetching the list of user types from UMS.
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index 8f7cf91aac6a..4b936c18251b 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -255,7 +255,8 @@ public class UserManagerService extends IUserManager.Stub {
| UserInfo.FLAG_RESTRICTED
| UserInfo.FLAG_GUEST
| UserInfo.FLAG_DEMO
- | UserInfo.FLAG_FULL;
+ | UserInfo.FLAG_FULL
+ | UserInfo.FLAG_FOR_TESTING;
@VisibleForTesting
static final int MIN_USER_ID = UserHandle.MIN_SECONDARY_USER_ID;
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index f47c330d1d13..fa6fa530296c 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -1092,13 +1092,13 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
// (ACTION_DATE_CHANGED), or when manual clock adjustment is made
// (ACTION_TIME_CHANGED)
updateSystemUpdateFreezePeriodsRecord(/* saveIfChanged */ true);
- final int userId = getManagedUserId(UserHandle.USER_SYSTEM);
+ final int userId = getManagedUserId(mUserManager.getMainUser().getIdentifier());
if (userId >= 0) {
updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
}
} else if (ACTION_PROFILE_OFF_DEADLINE.equals(action)) {
Slogf.i(LOG_TAG, "Profile off deadline alarm was triggered");
- final int userId = getManagedUserId(UserHandle.USER_SYSTEM);
+ final int userId = getManagedUserId(mUserManager.getMainUser().getIdentifier());
if (userId >= 0) {
updatePersonalAppsSuspension(userId, mUserManager.isUserUnlocked(userId));
} else {
@@ -8598,9 +8598,20 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
Preconditions.checkArgument(admin != null);
final CallerIdentity caller = getCallerIdentity();
- // Cannot be called while holding the lock:
- final boolean hasIncompatibleAccountsOrNonAdb =
- hasIncompatibleAccountsOrNonAdbNoLock(caller, userId, admin);
+
+ boolean hasIncompatibleAccountsOrNonAdb =
+ !isAdb(caller) || hasIncompatibleAccountsOnAnyUser();
+
+ if (!hasIncompatibleAccountsOrNonAdb) {
+ synchronized (getLockObject()) {
+ if (!isAdminTestOnlyLocked(admin, userId) && hasAccountsOnAnyUser()) {
+ Slogf.w(LOG_TAG,
+ "Non test-only owner can't be installed with existing accounts.");
+ return false;
+ }
+ }
+ }
+
synchronized (getLockObject()) {
enforceCanSetDeviceOwnerLocked(caller, admin, userId, hasIncompatibleAccountsOrNonAdb);
Preconditions.checkArgument(isPackageInstalledForUser(admin.getPackageName(), userId),
@@ -14746,14 +14757,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
if (isAdb) {
// If shell command runs after user setup completed check device status. Otherwise, OK.
if (mIsWatch || hasUserSetupCompleted(UserHandle.USER_SYSTEM)) {
- // In non-headless system user mode, DO can be setup only if
- // there's no non-system user.
- // In headless system user mode, DO can be setup only if there are
- // two users: the headless system user and the foreground user.
- // If there could be multiple foreground users, this constraint should be modified.
-
- int maxNumberOfExistingUsers = isHeadlessSystemUserMode ? 2 : 1;
- if (mUserManager.getUserCount() > maxNumberOfExistingUsers) {
+ // DO can be setup only if there are no users which are neither created by default
+ // nor marked as FOR_TESTING
+
+ if (nonTestNonPrecreatedUsersExist()) {
return STATUS_NONSYSTEM_USER_EXISTS;
}
@@ -14783,6 +14790,17 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
}
+ /**
+ * True if there are any users on the device which were not setup by default (1 usually, 2 for
+ * devices with a headless system user) and also are not marked as FOR_TESTING.
+ */
+ private boolean nonTestNonPrecreatedUsersExist() {
+ int allowedUsers = UserManager.isHeadlessSystemUserMode() ? 2 : 1;
+ return mUserManagerInternal.getUsers(/* excludeDying= */ true).stream()
+ .filter(u -> !u.isForTesting())
+ .count() > allowedUsers;
+ }
+
private int checkDeviceOwnerProvisioningPreCondition(@UserIdInt int callingUserId) {
synchronized (getLockObject()) {
final int deviceOwnerUserId = mInjector.userManagerIsHeadlessSystemUserMode()
@@ -16054,8 +16072,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
wtfIfInLock();
return mInjector.binderWithCleanCallingIdentity(() -> {
- final AccountManager am = AccountManager.get(mContext);
- final Account accounts[] = am.getAccountsAsUser(userId);
+ AccountManager am =
+ mContext.createContextAsUser(UserHandle.of(userId), /* flags= */ 0)
+ .getSystemService(AccountManager.class);
+ Account[] accounts = am.getAccounts();
if (accounts.length == 0) {
return false;
}
@@ -18169,8 +18189,10 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
.addAction(turnProfileOnButton)
.addExtras(extras)
.build();
- mInjector.getNotificationManager().notify(
- SystemMessage.NOTE_PERSONAL_APPS_SUSPENDED, notification);
+
+ mInjector.getNotificationManager().notifyAsUser(
+ null, SystemMessage.NOTE_PERSONAL_APPS_SUSPENDED, notification,
+ UserHandle.of(getProfileParentId(profileUserId)));
}
private String getPersonalAppSuspensionButtonText() {
@@ -19537,6 +19559,14 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
@Override
+ public void resetShouldAllowBypassingDevicePolicyManagementRoleQualificationState() {
+ Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
+ android.Manifest.permission.MANAGE_ROLE_HOLDERS));
+ setBypassDevicePolicyManagementRoleQualificationStateInternal(
+ /* currentRoleHolder= */ null, /* allowBypass= */ false);
+ }
+
+ @Override
public boolean shouldAllowBypassingDevicePolicyManagementRoleQualification() {
Preconditions.checkCallAuthorization(hasCallingOrSelfPermission(
android.Manifest.permission.MANAGE_ROLE_HOLDERS));
@@ -19550,15 +19580,51 @@ public class DevicePolicyManagerService extends BaseIDevicePolicyManager {
}
private boolean shouldAllowBypassingDevicePolicyManagementRoleQualificationInternal() {
- if (mUserManager.getUserCount() > 1) {
+ if (nonTestNonPrecreatedUsersExist()) {
return false;
}
- AccountManager am = AccountManager.get(mContext);
- Account[] accounts = am.getAccounts();
- if (accounts.length == 0) {
- return true;
+
+
+ return !hasIncompatibleAccountsOnAnyUser();
+ }
+
+ private boolean hasAccountsOnAnyUser() {
+ long callingIdentity = Binder.clearCallingIdentity();
+ try {
+ for (UserInfo user : mUserManagerInternal.getUsers(/* excludeDying= */ true)) {
+ AccountManager am = mContext.createContextAsUser(
+ UserHandle.of(user.id), /* flags= */ 0)
+ .getSystemService(AccountManager.class);
+ Account[] accounts = am.getAccounts();
+ if (accounts.length != 0) {
+ return true;
+ }
+ }
+
+ return false;
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentity);
+ }
+ }
+
+ private boolean hasIncompatibleAccountsOnAnyUser() {
+ long callingIdentity = Binder.clearCallingIdentity();
+ try {
+ for (UserInfo user : mUserManagerInternal.getUsers(/* excludeDying= */ true)) {
+ AccountManager am = mContext.createContextAsUser(
+ UserHandle.of(user.id), /* flags= */ 0)
+ .getSystemService(AccountManager.class);
+ Account[] accounts = am.getAccounts();
+
+ if (hasIncompatibleAccounts(am, accounts)) {
+ return true;
+ }
+ }
+
+ return false;
+ } finally {
+ Binder.restoreCallingIdentity(callingIdentity);
}
- return !hasIncompatibleAccounts(am, accounts);
}
private void setBypassDevicePolicyManagementRoleQualificationStateInternal(
diff --git a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
index e54a48b8887d..1298e7bbd344 100644
--- a/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/accounts/AccountManagerServiceTest.java
@@ -1292,10 +1292,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
unlockSystemUser();
try {
mAms.hasFeatures(
- null, // response
- AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
- new String[] {"feature1", "feature2"}, // features
- "testPackage"); // opPackageName
+ null, // response
+ AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS,
+ new String[] {"feature1", "feature2"}, // features
+ 0, // userId
+ "testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
// IllegalArgumentException is expected.
@@ -1307,10 +1308,11 @@ public class AccountManagerServiceTest extends AndroidTestCase {
unlockSystemUser();
try {
mAms.hasFeatures(
- mMockAccountManagerResponse, // response
- null, // account
- new String[] {"feature1", "feature2"}, // features
- "testPackage"); // opPackageName
+ mMockAccountManagerResponse, // response
+ null, // account
+ new String[] {"feature1", "feature2"}, // features
+ 0, // userId
+ "testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
// IllegalArgumentException is expected.
@@ -1325,6 +1327,7 @@ public class AccountManagerServiceTest extends AndroidTestCase {
mMockAccountManagerResponse, // response
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, // account
null, // features
+ 0, // userId
"testPackage"); // opPackageName
fail("IllegalArgumentException expected. But no exception was thrown.");
} catch (IllegalArgumentException e) {
@@ -1341,6 +1344,7 @@ public class AccountManagerServiceTest extends AndroidTestCase {
response, // response
AccountManagerServiceTestFixtures.ACCOUNT_ERROR, // account
AccountManagerServiceTestFixtures.ACCOUNT_FEATURES, // features
+ 0, // userId
"testPackage"); // opPackageName
waitForLatch(latch);
verify(mMockAccountManagerResponse).onError(
@@ -1357,6 +1361,7 @@ public class AccountManagerServiceTest extends AndroidTestCase {
response, // response
AccountManagerServiceTestFixtures.ACCOUNT_SUCCESS, // account
AccountManagerServiceTestFixtures.ACCOUNT_FEATURES, // features
+ 0, // userId
"testPackage"); // opPackageName
waitForLatch(latch);
verify(mMockAccountManagerResponse).onResult(mBundleCaptor.capture());
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 61c3f13c72a6..210aeefde2b2 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -7396,7 +7396,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verify(getServices().alarmManager, times(1)).set(anyInt(), eq(PROFILE_OFF_DEADLINE), any());
// Now the user should see a warning notification.
verify(getServices().notificationManager, times(1))
- .notify(anyInt(), any());
+ .notifyAsUser(any(), anyInt(), any(), any());
// Apps shouldn't be suspended yet.
verifyZeroInteractions(getServices().ipackageManager);
clearInvocations(getServices().alarmManager);
@@ -7410,7 +7410,7 @@ public class DevicePolicyManagerTest extends DpmTestBase {
verifyZeroInteractions(getServices().alarmManager);
// Now the user should see a notification about suspended apps.
verify(getServices().notificationManager, times(1))
- .notify(anyInt(), any());
+ .notifyAsUser(any(), anyInt(), any(), any());
// Verify that the apps are suspended.
verify(getServices().ipackageManager, times(1)).setPackagesSuspendedAsUser(
any(), eq(true), any(), any(), any(), any(), anyInt());