Misc fixes for account/users fragments
- Hide add user button when it's not functional - Display "No accounts added" under accounts setting when there is no account. Change-Id: Iefede9939d206eb3064fa22bdcfbcb1e826f29ab Fixes: 72643060 Test: robotest Test: 72713118
This commit is contained in:
@@ -6652,6 +6652,8 @@
|
|||||||
<string name="app_and_notification_dashboard_summary">Permissions, default apps</string>
|
<string name="app_and_notification_dashboard_summary">Permissions, default apps</string>
|
||||||
<!-- Title for setting tile leading to account settings [CHAR LIMIT=40]-->
|
<!-- Title for setting tile leading to account settings [CHAR LIMIT=40]-->
|
||||||
<string name="account_dashboard_title">Accounts</string>
|
<string name="account_dashboard_title">Accounts</string>
|
||||||
|
<!-- Summary for account settings tiles when there is no accounts on device [CHAR LIMIT=NONE]-->
|
||||||
|
<string name="account_dashboard_default_summary">No accounts added</string>
|
||||||
<!-- Title for setting tile leading to setting UI which allows user set default app to
|
<!-- Title for setting tile leading to setting UI which allows user set default app to
|
||||||
handle actions such as open web page, making phone calls, default SMS apps [CHAR LIMIT=40]-->
|
handle actions such as open web page, making phone calls, default SMS apps [CHAR LIMIT=40]-->
|
||||||
<string name="app_default_dashboard_title">Default apps</string>
|
<string name="app_default_dashboard_title">Default apps</string>
|
||||||
|
@@ -91,17 +91,20 @@ public class AccountDashboardFragment extends DashboardFragment {
|
|||||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||||
|
|
||||||
CharSequence summary = null;
|
CharSequence summary = null;
|
||||||
|
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
|
for (int i = 0; i < size; i++) {
|
||||||
final int size = Math.min(3, types.length);
|
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
|
||||||
|
if (summary == null) {
|
||||||
for (int i = 0; i < size; i++) {
|
summary = bidiFormatter.unicodeWrap(label);
|
||||||
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
|
} else {
|
||||||
if (summary == null) {
|
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||||
summary = bidiFormatter.unicodeWrap(label);
|
bidiFormatter.unicodeWrap(label));
|
||||||
} else {
|
}
|
||||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
|
||||||
bidiFormatter.unicodeWrap(label));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mSummaryLoader.setSummary(this, summary);
|
mSummaryLoader.setSummary(this, summary);
|
||||||
|
@@ -249,11 +249,14 @@ public class UserSettings extends SettingsPreferenceFragment
|
|||||||
mAddUser.useAdminDisabledSummary(false);
|
mAddUser.useAdminDisabledSummary(false);
|
||||||
// Determine if add user/profile button should be visible
|
// Determine if add user/profile button should be visible
|
||||||
if (mUserCaps.mCanAddUser && Utils.isDeviceProvisioned(getActivity())) {
|
if (mUserCaps.mCanAddUser && Utils.isDeviceProvisioned(getActivity())) {
|
||||||
|
mAddUser.setVisible(true);
|
||||||
mAddUser.setOnPreferenceClickListener(this);
|
mAddUser.setOnPreferenceClickListener(this);
|
||||||
// change label to only mention user, if restricted profiles are not supported
|
// change label to only mention user, if restricted profiles are not supported
|
||||||
if (!mUserCaps.mCanAddRestrictedProfile) {
|
if (!mUserCaps.mCanAddRestrictedProfile) {
|
||||||
mAddUser.setTitle(R.string.user_add_user_menu);
|
mAddUser.setTitle(R.string.user_add_user_menu);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
mAddUser.setVisible(false);
|
||||||
}
|
}
|
||||||
final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
||||||
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
||||||
|
@@ -27,11 +27,13 @@ import android.os.UserHandle;
|
|||||||
import android.provider.SearchIndexableResource;
|
import android.provider.SearchIndexableResource;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.dashboard.SummaryLoader;
|
import com.android.settings.dashboard.SummaryLoader;
|
||||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -41,6 +43,7 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
import org.robolectric.annotation.Implementation;
|
import org.robolectric.annotation.Implementation;
|
||||||
import org.robolectric.annotation.Implements;
|
import org.robolectric.annotation.Implements;
|
||||||
|
import org.robolectric.annotation.Resetter;
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
import org.robolectric.shadows.ShadowApplication;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -57,6 +60,11 @@ public class AccountDashboardFragmentTest {
|
|||||||
mFragment = new AccountDashboardFragment();
|
mFragment = new AccountDashboardFragment();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowAuthenticationHelper.reset();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCategory_isAccount() {
|
public void testCategory_isAccount() {
|
||||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||||
@@ -66,7 +74,8 @@ public class AccountDashboardFragmentTest {
|
|||||||
@Config(shadows = {
|
@Config(shadows = {
|
||||||
ShadowAuthenticationHelper.class
|
ShadowAuthenticationHelper.class
|
||||||
})
|
})
|
||||||
public void updateSummary_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();
|
||||||
|
|
||||||
@@ -77,6 +86,23 @@ public class AccountDashboardFragmentTest {
|
|||||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", " + LABELS[2]);
|
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", " + LABELS[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(shadows = {
|
||||||
|
ShadowAuthenticationHelper.class
|
||||||
|
})
|
||||||
|
public void updateSummary_noAccount_shouldDisplayDefaultSummary() {
|
||||||
|
ShadowAuthenticationHelper.setHasAccount(false);
|
||||||
|
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||||
|
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||||
|
|
||||||
|
final SummaryLoader.SummaryProvider provider = mFragment.SUMMARY_PROVIDER_FACTORY
|
||||||
|
.createSummaryProvider(activity, loader);
|
||||||
|
provider.setListening(true);
|
||||||
|
|
||||||
|
verify(loader).setSummary(provider,
|
||||||
|
activity.getString(R.string.account_dashboard_default_summary));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchIndexProvider_shouldIndexResource() {
|
public void testSearchIndexProvider_shouldIndexResource() {
|
||||||
final List<SearchIndexableResource> indexRes =
|
final List<SearchIndexableResource> indexRes =
|
||||||
@@ -94,15 +120,24 @@ public class AccountDashboardFragmentTest {
|
|||||||
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 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) {
|
||||||
|
sHasAccount = hasAccount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Resetter
|
||||||
|
public static void reset() {
|
||||||
|
sHasAccount = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public String[] getEnabledAccountTypes() {
|
public String[] getEnabledAccountTypes() {
|
||||||
return TYPES;
|
return sHasAccount ? TYPES : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
|
Reference in New Issue
Block a user