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

Commit 408dc883 authored by Sunny Shao's avatar Sunny Shao
Browse files

Added the launching account page

Settings get account name and account avatar from SI.
According the account name to launch the account page.

Bug: 119608711
Test: robotest
Change-Id: I0d53e9445f4ba5ce470bd079038db0f08f0cc1c8
parent f8a2304d
Loading
Loading
Loading
Loading
+22 −11
Original line number Diff line number Diff line
@@ -55,27 +55,37 @@ public class AvatarViewMixin implements LifecycleObserver {

    private static final String METHOD_GET_ACCOUNT_AVATAR = "getAccountAvatar";
    private static final String KEY_AVATAR_BITMAP = "account_avatar";
    private static final String KEY_ACCOUNT_NAME = "account_name";
    private static final String EXTRA_ACCOUNT_NAME = "extra.accountName";
    private static final int REQUEST_CODE = 1013;

    private final Context mContext;
    private final ImageView mAvatarView;
    private final MutableLiveData<Bitmap> mAvatarImage;

    private String mAccountName;

    public AvatarViewMixin(SettingsHomepageActivity activity, ImageView avatarView) {
        mContext = activity.getApplicationContext();
        mAvatarView = avatarView;
        mAvatarView.setOnClickListener(v -> {
            if (hasAccount()) {
                //TODO(b/117509285) launch the new page of the MeCard
            } else {
            final Intent intent = FeatureFactory.getFactory(mContext)
                    .getAccountFeatureProvider()
                    .getAccountSettingsDeeplinkIntent();

                if (intent != null) {
                    activity.startActivityForResult(intent, REQUEST_CODE);
            if (intent == null) {
                return;
            }

            if (!TextUtils.isEmpty(mAccountName)) {
                //TODO(b/117509285) launch the new page of the MeCard
                intent.putExtra(EXTRA_ACCOUNT_NAME, mAccountName);
            }

            // Here may have two different UI while start the activity.
            // It will display adding account UI when device has no any account.
            // It will display account information page when intent added the specified account.
            activity.startActivityForResult(intent, REQUEST_CODE);
        });

        mAvatarImage = new MutableLiveData<>();
@@ -91,7 +101,7 @@ public class AvatarViewMixin implements LifecycleObserver {
            return;
        }
        if (hasAccount()) {
            loadAvatar();
            loadAccount();
        } else {
            mAvatarView.setImageResource(R.drawable.ic_account_circle_24dp);
        }
@@ -104,7 +114,7 @@ public class AvatarViewMixin implements LifecycleObserver {
        return (accounts != null) && (accounts.length > 0);
    }

    private void loadAvatar() {
    private void loadAccount() {
        final String authority = queryProviderAuthority();
        if (TextUtils.isEmpty(authority)) {
            return;
@@ -117,6 +127,7 @@ public class AvatarViewMixin implements LifecycleObserver {
            final Bundle bundle = mContext.getContentResolver().call(uri,
                    METHOD_GET_ACCOUNT_AVATAR, null /* arg */, null /* extras */);
            final Bitmap bitmap = bundle.getParcelable(KEY_AVATAR_BITMAP);
            mAccountName = bundle.getString(KEY_ACCOUNT_NAME, "" /* defaultValue */);
            mAvatarImage.postValue(bitmap);
        });
    }
+36 −0
Original line number Diff line number Diff line
@@ -18,16 +18,25 @@ package com.android.settings.accounts;

import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;

import android.accounts.Account;
import android.content.ContentProvider;
import android.content.ContentResolver;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.ProviderInfo;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.widget.ImageView;

import com.android.settings.homepage.SettingsHomepageActivity;
@@ -44,6 +53,7 @@ import org.robolectric.annotation.Config;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;
import org.robolectric.shadow.api.Shadow;
import org.robolectric.shadows.ShadowContentResolver;
import org.robolectric.shadows.ShadowPackageManager;

@RunWith(SettingsRobolectricTestRunner.class)
@@ -51,6 +61,7 @@ public class AvatarViewMixinTest {
    private static final String DUMMY_ACCOUNT = "test@domain.com";
    private static final String DUMMY_DOMAIN = "domain.com";
    private static final String DUMMY_AUTHORITY = "authority.domain.com";
    private static final String METHOD_GET_ACCOUNT_AVATAR = "getAccountAvatar";

    private Context mContext;
    private ImageView mImageView;
@@ -128,6 +139,31 @@ public class AvatarViewMixinTest {
        assertThat(avatarViewMixin.queryProviderAuthority()).isEqualTo(DUMMY_AUTHORITY);
    }

    @Test
    public void callWithGetAccountAvatarMethod_useDummyData_shouldReturnAccountNameAndAvatar() {
        final ShadowContentResolver shadowContentResolver = Shadow.extract(
                mContext.getContentResolver());
        final Uri uri = new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(
                DUMMY_AUTHORITY).build();
        final ContentProvider mockContentProvider = mock(ContentProvider.class);

        ShadowContentResolver.registerProviderInternal(DUMMY_AUTHORITY, mockContentProvider);

        final Bundle bundle = new Bundle();
        final Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        bundle.putParcelable("account_avatar", bitmap);
        bundle.putString("account_name", DUMMY_ACCOUNT);
        doReturn(bundle).when(mockContentProvider).call(anyString(), anyString(),
                any(Bundle.class));

        final Bundle expectBundle = shadowContentResolver.call(uri, METHOD_GET_ACCOUNT_AVATAR,
                null /* arg */, null /* extras */);

        final Object object = bundle.getParcelable("account_avatar");
        assertThat(object instanceof Bitmap).isTrue();
        assertThat(bundle.getString("account_name")).isEqualTo(DUMMY_ACCOUNT);
    }

    @Implements(value = AccountFeatureProviderImpl.class)
    public static class ShadowAccountFeatureProviderImpl {