Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da1350f2 authored by Sander Alewijnse's avatar Sander Alewijnse
Browse files

AccountManager cannot modify accounts according to device policy.

Change-Id: Ied03b16c31312f7a4a934616c3c25b2481de818e
parent 695015dd
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.app.AppGlobals;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.admin.DevicePolicyManager;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentValues;
@@ -857,7 +858,7 @@ public class AccountManagerService
        checkManageAccountsPermission();
        UserHandle user = Binder.getCallingUserHandle();
        UserAccounts accounts = getUserAccountsForCaller();
        if (!canUserModifyAccounts(Binder.getCallingUid())) {
        if (!canUserModifyAccounts(Binder.getCallingUid(), account.type)) {
            try {
                response.onError(AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION,
                        "User cannot modify accounts");
@@ -1512,7 +1513,7 @@ public class AccountManagerService
        checkManageAccountsPermission();

        // Is user disallowed from modifying accounts?
        if (!canUserModifyAccounts(Binder.getCallingUid())) {
        if (!canUserModifyAccounts(Binder.getCallingUid(), accountType)) {
            try {
                response.onError(AccountManager.ERROR_CODE_USER_RESTRICTED,
                        "User is not allowed to add an account!");
@@ -2758,7 +2759,7 @@ public class AccountManagerService
                Manifest.permission.USE_CREDENTIALS);
    }

    private boolean canUserModifyAccounts(int callingUid) {
    private boolean canUserModifyAccounts(int callingUid, String accountType) {
        if (callingUid != Process.myUid()) {
            if (getUserManager().getUserRestrictions(
                    new UserHandle(UserHandle.getUserId(callingUid)))
@@ -2766,6 +2767,15 @@ public class AccountManagerService
                return false;
            }
        }

        DevicePolicyManager dpm = (DevicePolicyManager) mContext
                .getSystemService(Context.DEVICE_POLICY_SERVICE);
        String[] typesArray = dpm.getAccountTypesWithManagementDisabled();
        for (String forbiddenType : typesArray) {
            if (forbiddenType.equals(accountType)) {
                return false;
            }
        }
        return true;
    }