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.os.UserHandle;
|
||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.text.BidiFormatter;
|
import android.text.BidiFormatter;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
@@ -94,17 +95,21 @@ public class AccountDashboardFragment extends DashboardFragment {
|
|||||||
if (types == null || types.length == 0) {
|
if (types == null || types.length == 0) {
|
||||||
summary = mContext.getString(R.string.account_dashboard_default_summary);
|
summary = mContext.getString(R.string.account_dashboard_default_summary);
|
||||||
} else {
|
} else {
|
||||||
// Show up to 3 account types
|
// Show up to 3 account types, ignore any null value
|
||||||
final int size = Math.min(3, types.length);
|
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]);
|
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
|
||||||
|
if (TextUtils.isEmpty(label)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (summary == null) {
|
if (summary == null) {
|
||||||
summary = bidiFormatter.unicodeWrap(label);
|
summary = bidiFormatter.unicodeWrap(label);
|
||||||
} else {
|
} else {
|
||||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||||
bidiFormatter.unicodeWrap(label));
|
bidiFormatter.unicodeWrap(label));
|
||||||
}
|
}
|
||||||
|
accountToAdd--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSummaryLoader.setSummary(this, summary);
|
mSummaryLoader.setSummary(this, summary);
|
||||||
|
@@ -17,6 +17,9 @@ package com.android.settings.accounts;
|
|||||||
|
|
||||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||||
.ShadowAuthenticationHelper.LABELS;
|
.ShadowAuthenticationHelper.LABELS;
|
||||||
|
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||||
|
.ShadowAuthenticationHelper.TYPES;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
@@ -75,7 +78,6 @@ public class AccountDashboardFragmentTest {
|
|||||||
ShadowAuthenticationHelper.class
|
ShadowAuthenticationHelper.class
|
||||||
})
|
})
|
||||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||||
ShadowAuthenticationHelper.setHasAccount(true);
|
|
||||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||||
|
|
||||||
@@ -91,7 +93,7 @@ public class AccountDashboardFragmentTest {
|
|||||||
ShadowAuthenticationHelper.class
|
ShadowAuthenticationHelper.class
|
||||||
})
|
})
|
||||||
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||||
ShadowAuthenticationHelper.setHasAccount(false);
|
ShadowAuthenticationHelper.setEnabledAccount(null);
|
||||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||||
|
|
||||||
@@ -103,6 +105,24 @@ public class AccountDashboardFragmentTest {
|
|||||||
activity.getString(R.string.account_dashboard_default_summary));
|
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
|
@Test
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
final List<SearchIndexableResource> indexRes =
|
final List<SearchIndexableResource> indexRes =
|
||||||
@@ -118,26 +138,25 @@ public class AccountDashboardFragmentTest {
|
|||||||
public static class ShadowAuthenticationHelper {
|
public static class ShadowAuthenticationHelper {
|
||||||
|
|
||||||
static final String[] TYPES = new String[] {"type1", "type2", "type3", "type4"};
|
static final String[] TYPES = new String[] {"type1", "type2", "type3", "type4"};
|
||||||
static final String[] LABELS = new String[] {"LABEL1", "LABEL2",
|
static final String[] LABELS = new String[] {"LABEL1", "LABEL2", "LABEL3", "LABEL4"};
|
||||||
"LABEL3", "LABEL4"};
|
private static String[] sEnabledAccount = TYPES;
|
||||||
private static boolean sHasAccount = true;
|
|
||||||
|
|
||||||
public void __constructor__(Context context, UserHandle userHandle,
|
public void __constructor__(Context context, UserHandle userHandle,
|
||||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHasAccount(boolean hasAccount) {
|
public static void setEnabledAccount(String[] enabledAccount) {
|
||||||
sHasAccount = hasAccount;
|
sEnabledAccount = enabledAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Resetter
|
@Resetter
|
||||||
public static void reset() {
|
public static void reset() {
|
||||||
sHasAccount = true;
|
sEnabledAccount = TYPES;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public String[] getEnabledAccountTypes() {
|
public String[] getEnabledAccountTypes() {
|
||||||
return sHasAccount ? TYPES : null;
|
return sEnabledAccount;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
@@ -151,7 +170,7 @@ public class AccountDashboardFragmentTest {
|
|||||||
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
} else if (TextUtils.equals(accountType, TYPES[3])) {
|
||||||
return LABELS[3];
|
return LABELS[3];
|
||||||
}
|
}
|
||||||
return "no_label";
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user