Launch view account page when it's available.

- Add to launch the new Contextual Landing Page when user clicks the avatar
  icon and check the matching intent activity exist.
- Use the serialized intent and keeps in config.xml.
- Remove the getAccountSettingsDeeplinkIntent in the AccountFeatureProvider
  which never use again.

Change-Id: I50396af67eb04034572f8c885b4d9aef48a67e9d
Fixes: 122486552
Test: robotest
This commit is contained in:
Sunny Shao
2018-12-19 17:39:09 +08:00
parent a9f902b9c2
commit 7aa9fdd75c
5 changed files with 32 additions and 16 deletions

View File

@@ -174,4 +174,7 @@
<!-- Max allowed value for screen timeout, in milliseconds --> <!-- Max allowed value for screen timeout, in milliseconds -->
<integer name="max_lock_after_timeout_ms">1800000</integer> <integer name="max_lock_after_timeout_ms">1800000</integer>
<!-- App intent -->
<string name="config_account_intent_uri" translatable="false"></string>
</resources> </resources>

View File

@@ -23,5 +23,4 @@ import android.content.Intent;
public interface AccountFeatureProvider { public interface AccountFeatureProvider {
String getAccountType(); String getAccountType();
Account[] getAccounts(Context context); Account[] getAccounts(Context context);
Intent getAccountSettingsDeeplinkIntent();
} }

View File

@@ -2,7 +2,6 @@ package com.android.settings.accounts;
import android.accounts.Account; import android.accounts.Account;
import android.content.Context; import android.content.Context;
import android.content.Intent;
public class AccountFeatureProviderImpl implements AccountFeatureProvider { public class AccountFeatureProviderImpl implements AccountFeatureProvider {
@Override @Override
@@ -14,9 +13,4 @@ public class AccountFeatureProviderImpl implements AccountFeatureProvider {
public Account[] getAccounts(Context context) { public Account[] getAccounts(Context context) {
return new Account[0]; return new Account[0];
} }
@Override
public Intent getAccountSettingsDeeplinkIntent() {
return null;
}
} }

View File

@@ -40,6 +40,7 @@ import com.android.settings.homepage.SettingsHomepageActivity;
import com.android.settings.overlay.FeatureFactory; import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import java.net.URISyntaxException;
import java.util.List; import java.util.List;
/** /**
@@ -57,7 +58,6 @@ public class AvatarViewMixin implements LifecycleObserver {
private static final String KEY_AVATAR_BITMAP = "account_avatar"; private static final String KEY_AVATAR_BITMAP = "account_avatar";
private static final String KEY_ACCOUNT_NAME = "account_name"; private static final String KEY_ACCOUNT_NAME = "account_name";
private static final String EXTRA_ACCOUNT_NAME = "extra.accountName"; private static final String EXTRA_ACCOUNT_NAME = "extra.accountName";
private static final int REQUEST_CODE = 1013;
private final Context mContext; private final Context mContext;
private final ImageView mAvatarView; private final ImageView mAvatarView;
@@ -69,23 +69,32 @@ public class AvatarViewMixin implements LifecycleObserver {
mContext = activity.getApplicationContext(); mContext = activity.getApplicationContext();
mAvatarView = avatarView; mAvatarView = avatarView;
mAvatarView.setOnClickListener(v -> { mAvatarView.setOnClickListener(v -> {
final Intent intent = FeatureFactory.getFactory(mContext) Intent intent;
.getAccountFeatureProvider() try {
.getAccountSettingsDeeplinkIntent(); final String uri = mContext.getResources().getString(
R.string.config_account_intent_uri);
if (intent == null) { intent = Intent.parseUri(uri, Intent.URI_INTENT_SCHEME);
} catch (URISyntaxException e) {
Log.w(TAG, "Error parsing avatar mixin intent, skipping", e);
return; return;
} }
if (!TextUtils.isEmpty(mAccountName)) { if (!TextUtils.isEmpty(mAccountName)) {
//TODO(b/117509285) launch the new page of the MeCard
intent.putExtra(EXTRA_ACCOUNT_NAME, mAccountName); intent.putExtra(EXTRA_ACCOUNT_NAME, mAccountName);
} }
final List<ResolveInfo> matchedIntents =
mContext.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_SYSTEM_ONLY);
if (matchedIntents.isEmpty()) {
Log.w(TAG, "Cannot find any matching action VIEW_ACCOUNT intent.");
return;
}
// Here may have two different UI while start the activity. // 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 adding account UI when device has no any account.
// It will display account information page when intent added the specified account. // It will display account information page when intent added the specified account.
activity.startActivityForResult(intent, REQUEST_CODE); activity.startActivity(intent);
}); });
mAvatarImage = new MutableLiveData<>(); mAvatarImage = new MutableLiveData<>();

View File

@@ -30,6 +30,7 @@ import android.accounts.Account;
import android.content.ContentProvider; import android.content.ContentProvider;
import android.content.ContentResolver; import android.content.ContentResolver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo; import android.content.pm.PackageInfo;
import android.content.pm.ProviderInfo; import android.content.pm.ProviderInfo;
@@ -167,12 +168,22 @@ public class AvatarViewMixinTest {
assertThat(bundle.getString("account_name")).isEqualTo(DUMMY_ACCOUNT); assertThat(bundle.getString("account_name")).isEqualTo(DUMMY_ACCOUNT);
} }
@Test
public void onClickAvatar_withEmptyUri_startActivityShouldNotBeExecuted() {
final SettingsHomepageActivity activity = spy((SettingsHomepageActivity) mController.get());
final AvatarViewMixin avatarViewMixin = new AvatarViewMixin(activity, mImageView);
mImageView.performClick();
verify(activity, never()).startActivity(any(Intent.class));
}
@Implements(value = AccountFeatureProviderImpl.class) @Implements(value = AccountFeatureProviderImpl.class)
public static class ShadowAccountFeatureProviderImpl { public static class ShadowAccountFeatureProviderImpl {
@Implementation @Implementation
protected Account[] getAccounts(Context context) { protected Account[] getAccounts(Context context) {
return new Account[] {new Account(DUMMY_ACCOUNT, DUMMY_DOMAIN)}; return new Account[]{new Account(DUMMY_ACCOUNT, DUMMY_DOMAIN)};
} }
} }
} }