Ignore null value in Account settings summary.
If an account type has no valid label, null is returned. Check the value to make sure that it is a valid label before adding it to the summary. Change-Id: I0cf3ef9a976e1a7fe16720da237f416c674791fc Fixes: 73375480 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -22,6 +22,7 @@ import android.content.Context;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.BidiFormatter;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
@@ -94,17 +95,21 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
if (types == null || types.length == 0) {
|
||||
summary = mContext.getString(R.string.account_dashboard_default_summary);
|
||||
} else {
|
||||
// Show up to 3 account types
|
||||
final int size = Math.min(3, types.length);
|
||||
// Show up to 3 account types, ignore any null value
|
||||
int accountToAdd = Math.min(3, types.length);
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
for (int i = 0; i < types.length && accountToAdd > 0; i++) {
|
||||
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
|
||||
if (TextUtils.isEmpty(label)) {
|
||||
continue;
|
||||
}
|
||||
if (summary == null) {
|
||||
summary = bidiFormatter.unicodeWrap(label);
|
||||
} else {
|
||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||
bidiFormatter.unicodeWrap(label));
|
||||
}
|
||||
accountToAdd--;
|
||||
}
|
||||
}
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
|
@@ -17,6 +17,9 @@ package com.android.settings.accounts;
|
||||
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -75,7 +78,6 @@ public class AccountDashboardFragmentTest {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
ShadowAuthenticationHelper.setHasAccount(true);
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
|
||||
@@ -91,7 +93,7 @@ public class AccountDashboardFragmentTest {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||
ShadowAuthenticationHelper.setHasAccount(false);
|
||||
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
|
||||
@@ -103,6 +105,24 @@ public class AccountDashboardFragmentTest {
|
||||
activity.getString(R.string.account_dashboard_default_summary));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_noAccountTypeLabel_shouldNotDisplayNullEntry() {
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
final String[] enabledAccounts = {TYPES[0], "unlabled_account_type", TYPES[1]};
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
final SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
|
||||
.createSummaryProvider(activity, loader);
|
||||
provider.setListening(true);
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
@@ -118,26 +138,25 @@ public class AccountDashboardFragmentTest {
|
||||
public static class ShadowAuthenticationHelper {
|
||||
|
||||
static final String[] TYPES = new String[] {"type1", "type2", "type3", "type4"};
|
||||
static final String[] LABELS = new String[] {"LABEL1", "LABEL2",
|
||||
"LABEL3", "LABEL4"};
|
||||
private static boolean sHasAccount = true;
|
||||
static final String[] LABELS = new String[] {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||
private static String[] sEnabledAccount = TYPES;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
public static void setHasAccount(boolean hasAccount) {
|
||||
sHasAccount = hasAccount;
|
||||
public static void setEnabledAccount(String[] enabledAccount) {
|
||||
sEnabledAccount = enabledAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sHasAccount = true;
|
||||
sEnabledAccount = TYPES;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return sHasAccount ? TYPES : null;
|
||||
return sEnabledAccount;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
@@ -151,7 +170,7 @@ public class AccountDashboardFragmentTest {
|
||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||
return LABELS[3];
|
||||
}
|
||||
return "no_label";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user