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>
|
||||
<!-- Title for setting tile leading to account settings [CHAR LIMIT=40]-->
|
||||
<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
|
||||
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>
|
||||
|
@@ -91,7 +91,9 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||
|
||||
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);
|
||||
|
||||
@@ -104,6 +106,7 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
bidiFormatter.unicodeWrap(label));
|
||||
}
|
||||
}
|
||||
}
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
}
|
||||
}
|
||||
|
@@ -249,11 +249,14 @@ public class UserSettings extends SettingsPreferenceFragment
|
||||
mAddUser.useAdminDisabledSummary(false);
|
||||
// Determine if add user/profile button should be visible
|
||||
if (mUserCaps.mCanAddUser && Utils.isDeviceProvisioned(getActivity())) {
|
||||
mAddUser.setVisible(true);
|
||||
mAddUser.setOnPreferenceClickListener(this);
|
||||
// change label to only mention user, if restricted profiles are not supported
|
||||
if (!mUserCaps.mCanAddRestrictedProfile) {
|
||||
mAddUser.setTitle(R.string.user_add_user_menu);
|
||||
}
|
||||
} else {
|
||||
mAddUser.setVisible(false);
|
||||
}
|
||||
final IntentFilter filter = new IntentFilter(Intent.ACTION_USER_REMOVED);
|
||||
filter.addAction(Intent.ACTION_USER_INFO_CHANGED);
|
||||
|
@@ -27,11 +27,13 @@ import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.dashboard.SummaryLoader;
|
||||
import com.android.settingslib.accounts.AuthenticatorHelper;
|
||||
import com.android.settingslib.drawer.CategoryKey;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -41,6 +43,7 @@ import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.annotation.Implementation;
|
||||
import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.annotation.Resetter;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.List;
|
||||
@@ -57,6 +60,11 @@ public class AccountDashboardFragmentTest {
|
||||
mFragment = new AccountDashboardFragment();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
ShadowAuthenticationHelper.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCategory_isAccount() {
|
||||
assertThat(mFragment.getCategoryKey()).isEqualTo(CategoryKey.CATEGORY_ACCOUNT);
|
||||
@@ -66,7 +74,8 @@ public class AccountDashboardFragmentTest {
|
||||
@Config(shadows = {
|
||||
ShadowAuthenticationHelper.class
|
||||
})
|
||||
public void updateSummary_shouldDisplayUpTo3AccountTypes() {
|
||||
public void updateSummary_hasAccount_shouldDisplayUpTo3AccountTypes() {
|
||||
ShadowAuthenticationHelper.setHasAccount(true);
|
||||
final SummaryLoader loader = mock(SummaryLoader.class);
|
||||
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]);
|
||||
}
|
||||
|
||||
@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
|
||||
public void testSearchIndexProvider_shouldIndexResource() {
|
||||
final List<SearchIndexableResource> indexRes =
|
||||
@@ -94,15 +120,24 @@ public class AccountDashboardFragmentTest {
|
||||
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;
|
||||
|
||||
public void __constructor__(Context context, UserHandle userHandle,
|
||||
AuthenticatorHelper.OnAccountsUpdateListener listener) {
|
||||
}
|
||||
|
||||
public static void setHasAccount(boolean hasAccount) {
|
||||
sHasAccount = hasAccount;
|
||||
}
|
||||
|
||||
@Resetter
|
||||
public static void reset() {
|
||||
sHasAccount = true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public String[] getEnabledAccountTypes() {
|
||||
return TYPES;
|
||||
return sHasAccount ? TYPES : null;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
|
Reference in New Issue
Block a user