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

Commit fb5f9cb9 authored by Aseem Kumar's avatar Aseem Kumar Committed by Android (Google) Code Review
Browse files

Merge "DO NOT MERGE Move accountname and typeName length check from...

Merge "DO NOT MERGE Move accountname and typeName length check from Account.java to AccountManagerService." into rvc-qpr-dev
parents 83ef3b97 5c3d1dce
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -30,7 +30,6 @@ import android.util.Log;


import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.GuardedBy;


import java.util.Objects;
import java.util.Set;
import java.util.Set;


/**
/**
@@ -86,12 +85,6 @@ public class Account implements Parcelable {
        if (TextUtils.isEmpty(type)) {
        if (TextUtils.isEmpty(type)) {
            throw new IllegalArgumentException("the type must not be empty: " + type);
            throw new IllegalArgumentException("the type must not be empty: " + type);
        }
        }
        if (name.length() > 200) {
            throw new IllegalArgumentException("account name is longer than 200 characters");
        }
        if (type.length() > 200) {
            throw new IllegalArgumentException("account type is longer than 200 characters");
        }
        this.name = name;
        this.name = name;
        this.type = type;
        this.type = type;
        this.accessId = accessId;
        this.accessId = accessId;
+12 −0
Original line number Original line Diff line number Diff line
@@ -1806,6 +1806,14 @@ public class AccountManagerService
        if (account == null) {
        if (account == null) {
            return false;
            return false;
        }
        }
        if (account.name != null && account.name.length() > 200) {
            Log.w(TAG, "Account cannot be added - Name longer than 200 chars");
            return false;
        }
        if (account.type != null && account.type.length() > 200) {
            Log.w(TAG, "Account cannot be added - Name longer than 200 chars");
            return false;
        }
        if (!isLocalUnlockedUser(accounts.userId)) {
        if (!isLocalUnlockedUser(accounts.userId)) {
            Log.w(TAG, "Account " + account.toSafeString() + " cannot be added - user "
            Log.w(TAG, "Account " + account.toSafeString() + " cannot be added - user "
                    + accounts.userId + " is locked. callingUid=" + callingUid);
                    + accounts.userId + " is locked. callingUid=" + callingUid);
@@ -1999,6 +2007,10 @@ public class AccountManagerService
                + ", pid " + Binder.getCallingPid());
                + ", pid " + Binder.getCallingPid());
        }
        }
        if (accountToRename == null) throw new IllegalArgumentException("account is null");
        if (accountToRename == null) throw new IllegalArgumentException("account is null");
        if (newName != null && newName.length() > 200) {
            Log.e(TAG, "renameAccount failed - account name longer than 200");
            throw new IllegalArgumentException("account name longer than 200");
        }
        int userId = UserHandle.getCallingUserId();
        int userId = UserHandle.getCallingUserId();
        if (!isAccountManagedByCaller(accountToRename.type, callingUid, userId)) {
        if (!isAccountManagedByCaller(accountToRename.type, callingUid, userId)) {
            String msg = String.format(
            String msg = String.format(
+22 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@ import android.accounts.CantAddAccountActivity;
import android.accounts.IAccountManagerResponse;
import android.accounts.IAccountManagerResponse;
import android.app.AppOpsManager;
import android.app.AppOpsManager;
import android.app.INotificationManager;
import android.app.INotificationManager;
import android.app.PropertyInvalidatedCache;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManager;
import android.app.admin.DevicePolicyManagerInternal;
import android.app.admin.DevicePolicyManagerInternal;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
@@ -132,6 +133,8 @@ public class AccountManagerServiceTest extends AndroidTestCase {
    protected void setUp() throws Exception {
    protected void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
        MockitoAnnotations.initMocks(this);


        PropertyInvalidatedCache.disableForTestMode();

        when(mMockPackageManager.checkSignatures(anyInt(), anyInt()))
        when(mMockPackageManager.checkSignatures(anyInt(), anyInt()))
                    .thenReturn(PackageManager.SIGNATURE_MATCH);
                    .thenReturn(PackageManager.SIGNATURE_MATCH);
        final UserInfo ui = new UserInfo(UserHandle.USER_SYSTEM, "user0", 0);
        final UserInfo ui = new UserInfo(UserHandle.USER_SYSTEM, "user0", 0);
@@ -241,6 +244,25 @@ public class AccountManagerServiceTest extends AndroidTestCase {
        assertEquals(a31, accounts[1]);
        assertEquals(a31, accounts[1]);
    }
    }


    @SmallTest
    public void testCheckAddAccountLongName() throws Exception {
        unlockSystemUser();
        String longString = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
                + "aaaaa";
        Account a11 = new Account(longString, AccountManagerServiceTestFixtures.ACCOUNT_TYPE_1);

        mAms.addAccountExplicitly(a11, /* password= */ "p11", null);

        String[] list = new String[]{AccountManagerServiceTestFixtures.CALLER_PACKAGE};
        when(mMockPackageManager.getPackagesForUid(anyInt())).thenReturn(list);
        Account[] accounts = mAms.getAccountsAsUser(null,
                UserHandle.getCallingUserId(), mContext.getOpPackageName());
        assertEquals(0, accounts.length);
    }


    @SmallTest
    @SmallTest
    public void testPasswords() throws Exception {
    public void testPasswords() throws Exception {
        unlockSystemUser();
        unlockSystemUser();