Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6663bed7 authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

Account settings: Fix duplicate title and extra padding.

This change reverts the change in
I3981ce73fef63f06a40e61e894481d24284614ba to add a PreferenceCategory
for the accounts after merging the page with autofill settings. That was
done to get the Accounts heading to display for the personal/work
profile view.
This change instead sets the title on the existing PreferenceCategory
that's created dynamically in the Controller.

Removing the extra PreferenceCategory also fixes the padding.

Fix: 183677515
Bug: 183677706
Test: manual - with single profile, with personal/work profiles
Test: make -j RunSettingsRoboTests \
 ROBOTEST_FILTER="com.android.settings.accounts.AccountPreferenceControllerTest"
Change-Id: Ib7fe6f97b93b81d5a5897280cdd6bbad1b75f3a9
parent 899845b1
Loading
Loading
Loading
Loading
+19 −25
Original line number Diff line number Diff line
@@ -45,11 +45,6 @@
        </com.android.settings.widget.GearPreference>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="accounts_category"
        android:order="100"
        android:title="@string/account_settings">

    <PreferenceCategory
        android:key="dashboard_tile_placeholder"
        android:order="130"/>
@@ -73,6 +68,5 @@
        android:title="@string/account_settings_menu_auto_sync_personal"
        android:summary="@string/auto_sync_account_summary"
        android:order="204"/>
    </PreferenceCategory>

</PreferenceScreen>
+13 −19
Original line number Diff line number Diff line
@@ -46,11 +46,6 @@
        </com.android.settings.widget.GearPreference>
    </PreferenceCategory>

    <PreferenceCategory
        android:key="accounts_category"
        android:order="100"
        android:title="@string/account_settings">

    <PreferenceCategory
        android:key="dashboard_tile_placeholder"
        android:order="130"/>
@@ -67,6 +62,5 @@
        android:title="@string/account_settings_menu_auto_sync_personal"
        android:summary="@string/auto_sync_account_summary"
        android:order="210"/>
    </PreferenceCategory>

</PreferenceScreen>
+14 −20
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
    <com.android.settings.widget.WorkOnlyCategory
        android:key="autofill_work_app_defaults"
        android:order="30"
        android:title="@string/default_for_work">
        android:title="@string/autofill_app">

        <com.android.settings.widget.GearPreference
            android:fragment="com.android.settings.applications.defaultapps.DefaultAutofillPicker"
@@ -46,11 +46,6 @@
        </com.android.settings.widget.GearPreference>
    </com.android.settings.widget.WorkOnlyCategory>

    <PreferenceCategory
        android:key="accounts_category"
        android:order="100"
        android:title="@string/account_settings">

    <PreferenceCategory
        android:key="dashboard_tile_placeholder"
        android:order="130"/>
@@ -67,6 +62,5 @@
        android:title="@string/account_settings_menu_auto_sync_work"
        android:summary="@string/auto_sync_account_summary"
        android:order="210"/>
    </PreferenceCategory>

</PreferenceScreen>
+3 −5
Original line number Diff line number Diff line
@@ -80,7 +80,6 @@ public class AccountPreferenceController extends AbstractPreferenceController
    private static final int ORDER_NEXT_TO_LAST = 1001;
    private static final int ORDER_NEXT_TO_NEXT_TO_LAST = 1000;

    private static final String PREF_KEY_ACCOUNTS = "accounts_category";
    private static final String PREF_KEY_ADD_ACCOUNT = "add_account";
    private static final String PREF_KEY_REMOVE_PROFILE = "remove_profile";
    private static final String PREF_KEY_WORK_PROFILE_SETTING = "work_profile_setting";
@@ -324,6 +323,7 @@ public class AccountPreferenceController extends AbstractPreferenceController
                mHelper.createAccessiblePreferenceCategory(
                        mFragment.getPreferenceManager().getContext());
        preferenceGroup.setOrder(mAccountProfileOrder++);
        preferenceGroup.setTitle(R.string.account_settings); // default title; may be modified below
        if (isSingleProfile()) {
            preferenceGroup.setTitle(context.getString(R.string.account_for_section_header,
                    BidiFormatter.getInstance().unicodeWrap(userInfo.name)));
@@ -349,10 +349,8 @@ public class AccountPreferenceController extends AbstractPreferenceController
            }
        }
        final PreferenceScreen screen = mFragment.getPreferenceScreen();
        final PreferenceGroup accounts =
                screen == null ? null : screen.findPreference(PREF_KEY_ACCOUNTS);
        if (accounts != null) {
            accounts.addPreference(preferenceGroup);
        if (screen != null) {
            screen.addPreference(preferenceGroup);
        }
        profileData.preferenceGroup = preferenceGroup;
        if (userInfo.isEnabled()) {
+0 −10
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import android.os.UserManager;
import android.text.TextUtils;

import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
@@ -73,13 +72,9 @@ import java.util.List;
        ShadowSettingsLibUtils.class})
public class AccountPreferenceControllerTest {

    private static final String PREF_KEY_ACCOUNTS = "accounts_category";

    @Mock(answer = RETURNS_DEEP_STUBS)
    private PreferenceScreen mScreen;
    @Mock(answer = RETURNS_DEEP_STUBS)
    private PreferenceCategory mAccountsCategory;
    @Mock(answer = RETURNS_DEEP_STUBS)
    private UserManager mUserManager;
    @Mock(answer = RETURNS_DEEP_STUBS)
    private SettingsPreferenceFragment mFragment;
@@ -100,9 +95,6 @@ public class AccountPreferenceControllerTest {
        shadowApp.setSystemService(Context.ACCOUNT_SERVICE, mAccountManager);

        when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
        // This is a bit ugly, but hard to avoid because of how the mocks are used in these tests.
        // TODO: Refactor these tests to not use RETURNS_DEEP_STUBS.
        when(mScreen.findPreference(PREF_KEY_ACCOUNTS)).thenReturn(mScreen);
        when(mFragment.getPreferenceManager().getContext()).thenReturn(mContext);
        when(mAccountManager.getAuthenticatorTypesAsUser(anyInt()))
                .thenReturn(new AuthenticatorDescription[0]);
@@ -174,7 +166,6 @@ public class AccountPreferenceControllerTest {
        // First time resume will build the UI
        mController.onResume();
        reset(mScreen);
        when(mScreen.findPreference(PREF_KEY_ACCOUNTS)).thenReturn(mScreen);

        mController.onResume();
        verify(mScreen, never()).addPreference(any(PreferenceGroup.class));
@@ -193,7 +184,6 @@ public class AccountPreferenceControllerTest {
        // add a new profile
        infos.add(new UserInfo(2, "user 2", UserInfo.FLAG_MANAGED_PROFILE));
        reset(mScreen);
        when(mScreen.findPreference(PREF_KEY_ACCOUNTS)).thenReturn(mScreen);

        mController.onResume();
        verify(mScreen, times(1)).addPreference(any(PreferenceGroup.class));