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;
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);
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;
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();
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();
}
@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 =
AccountDashboardFragment.SEARCH_INDEX_DATA_PROVIDER.getXmlResourcesToIndex(
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
} else if (TextUtils.equals(accountType, TYPES[3])) {
return LABELS[3];
}
- return "no_label";
+ return null;
}
}
}