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

Commit ce65c84f authored by Jian Sun's avatar Jian Sun Committed by Android (Google) Code Review
Browse files

Merge "Currently, when an account with USER_MANAGED_NOT_VISIBLE is chosen in...

Merge "Currently, when an account with USER_MANAGED_NOT_VISIBLE is chosen in ChooseAccountActivity, its visibility doesn't get updated. However, it is supposed to be updated to USER_MANAGED_VISIBLE."
parents d146a135 bdabd40c
Loading
Loading
Loading
Loading
+37 −3
Original line number Original line Diff line number Diff line
@@ -16,12 +16,17 @@
package android.accounts;
package android.accounts;


import android.app.Activity;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcelable;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.Process;
import android.os.UserHandle;
import android.util.Log;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View;
@@ -45,6 +50,8 @@ public class ChooseAccountActivity extends Activity {
    private Parcelable[] mAccounts = null;
    private Parcelable[] mAccounts = null;
    private AccountManagerResponse mAccountManagerResponse = null;
    private AccountManagerResponse mAccountManagerResponse = null;
    private Bundle mResult;
    private Bundle mResult;
    private int mCallingUid;
    private String mCallingPackage;


    private HashMap<String, AuthenticatorDescription> mTypeToAuthDescription
    private HashMap<String, AuthenticatorDescription> mTypeToAuthDescription
            = new HashMap<String, AuthenticatorDescription>();
            = new HashMap<String, AuthenticatorDescription>();
@@ -52,9 +59,6 @@ public class ChooseAccountActivity extends Activity {
    @Override
    @Override
    public void onCreate(Bundle savedInstanceState) {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);
        // TODO This activity is only used by getAuthTokenByFeatures and can not see
        // VISIBILITY_USER_MANAGED_NOT_VISIBLE accounts. It should be moved to account managed
        // service.
        mAccounts = getIntent().getParcelableArrayExtra(AccountManager.KEY_ACCOUNTS);
        mAccounts = getIntent().getParcelableArrayExtra(AccountManager.KEY_ACCOUNTS);
        mAccountManagerResponse =
        mAccountManagerResponse =
                getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_MANAGER_RESPONSE);
                getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_MANAGER_RESPONSE);
@@ -66,6 +70,28 @@ public class ChooseAccountActivity extends Activity {
            return;
            return;
        }
        }


        try {
            IBinder activityToken = getActivityToken();
            mCallingUid = ActivityManager.getService().getLaunchedFromUid(activityToken);
            mCallingPackage = ActivityManager.getService().getLaunchedFromPackage(
                    activityToken);
        } catch (RemoteException re) {
            // Couldn't figure out caller details
            Log.w(getClass().getSimpleName(), "Unable to get caller identity \n" + re);
        }

        if (UserHandle.isSameApp(mCallingUid, Process.SYSTEM_UID) &&
            getIntent().getStringExtra(AccountManager.KEY_ANDROID_PACKAGE_NAME) != null) {
            mCallingPackage = getIntent().getStringExtra(
                AccountManager.KEY_ANDROID_PACKAGE_NAME);
        }

        if (!UserHandle.isSameApp(mCallingUid, Process.SYSTEM_UID) &&
                getIntent().getStringExtra(AccountManager.KEY_ANDROID_PACKAGE_NAME) != null) {
            Log.w(getClass().getSimpleName(),
                "Non-system Uid: " + mCallingUid + " tried to override packageName \n");
        }

        getAuthDescriptions();
        getAuthDescriptions();


        AccountInfo[] mAccountInfos = new AccountInfo[mAccounts.length];
        AccountInfo[] mAccountInfos = new AccountInfo[mAccounts.length];
@@ -120,6 +146,14 @@ public class ChooseAccountActivity extends Activity {


    protected void onListItemClick(ListView l, View v, int position, long id) {
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Account account = (Account) mAccounts[position];
        Account account = (Account) mAccounts[position];
        // Mark account as visible since user chose it.
        AccountManager am = AccountManager.get(this);
        Integer oldVisibility = am.getAccountVisibility(account, mCallingPackage);
        if (oldVisibility != null
                && oldVisibility == AccountManager.VISIBILITY_USER_MANAGED_NOT_VISIBLE) {
            am.setAccountVisibility(account, mCallingPackage,
                AccountManager.VISIBILITY_USER_MANAGED_VISIBLE);
        }
        Log.d(TAG, "selected account " + account);
        Log.d(TAG, "selected account " + account);
        Bundle bundle = new Bundle();
        Bundle bundle = new Bundle();
        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
        bundle.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
+3 −2
Original line number Original line Diff line number Diff line
@@ -4446,11 +4446,12 @@ public class AccountManagerService
    }
    }


    private void startChooseAccountActivityWithAccounts(
    private void startChooseAccountActivityWithAccounts(
        IAccountManagerResponse response, Account[] accounts) {
        IAccountManagerResponse response, Account[] accounts, String callingPackage) {
        Intent intent = new Intent(mContext, ChooseAccountActivity.class);
        Intent intent = new Intent(mContext, ChooseAccountActivity.class);
        intent.putExtra(AccountManager.KEY_ACCOUNTS, accounts);
        intent.putExtra(AccountManager.KEY_ACCOUNTS, accounts);
        intent.putExtra(AccountManager.KEY_ACCOUNT_MANAGER_RESPONSE,
        intent.putExtra(AccountManager.KEY_ACCOUNT_MANAGER_RESPONSE,
                new AccountManagerResponse(response));
                new AccountManagerResponse(response));
        intent.putExtra(AccountManager.KEY_ANDROID_PACKAGE_NAME, callingPackage);


        mContext.startActivityAsUser(intent, UserHandle.of(UserHandle.getCallingUserId()));
        mContext.startActivityAsUser(intent, UserHandle.of(UserHandle.getCallingUserId()));
    }
    }
@@ -4461,7 +4462,7 @@ public class AccountManagerService
        String callingPackage) {
        String callingPackage) {


        if (needToStartChooseAccountActivity(accounts, callingPackage)) {
        if (needToStartChooseAccountActivity(accounts, callingPackage)) {
            startChooseAccountActivityWithAccounts(response, accounts);
            startChooseAccountActivityWithAccounts(response, accounts, callingPackage);
            return;
            return;
        }
        }
        if (accounts.length == 1) {
        if (accounts.length == 1) {