From 24aa3b35046549dc672e5d52ae11ee2a3b6be057 Mon Sep 17 00:00:00 2001 From: Antony Sargent Date: Thu, 4 Apr 2019 10:10:31 -0700 Subject: [PATCH] Fix 'Advanced' collapse point on Network & internet page On the Network & internet page, we want to collapse all the prefs into 'Advanced' that appear after 'Data Saver'. The mechanism for specifying where the collapse point starts is just a static count, and it doesn't really understand the concept of dynamically added preferences like the ones we add at the top when the device is in DSDS mode. To fix this in the short term, this CL makes the header that manages these prefs manually adjust the count as needed. In the future we'd like to have a better mechanism for this added in the support library. Fixes: 128855968 Test: make RunSettingsRoboTests Change-Id: I4509726ff29bc71e1f0b3d4a2f60dffe4b1dd7ac --- res/xml/network_and_internet_v2.xml | 3 ++- .../network/MultiNetworkHeaderController.java | 18 +++++++++++++- .../network/SubscriptionsPreferenceController.java | 2 +- .../network/MultiNetworkHeaderControllerTest.java | 28 ++++++++++++++++++++++ .../SubscriptionsPreferenceControllerTest.java | 8 ++++++- 5 files changed, 55 insertions(+), 4 deletions(-) diff --git a/res/xml/network_and_internet_v2.xml b/res/xml/network_and_internet_v2.xml index f004d06450..0d9e2ea133 100644 --- a/res/xml/network_and_internet_v2.xml +++ b/res/xml/network_and_internet_v2.xml @@ -18,7 +18,8 @@ xmlns:android="http://schemas.android.com/apk/res/android" xmlns:settings="http://schemas.android.com/apk/res-auto" android:key="network_and_internet_screen" - android:title="@string/network_dashboard_title"> + android:title="@string/network_dashboard_title" + settings:initialExpandedChildrenCount="6"> values = captor.getAllValues(); assertThat(values.get(values.size()-1)).isEqualTo(Boolean.TRUE); + + ArgumentCaptor expandedCountCaptor = ArgumentCaptor.forClass(Integer.class); + verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture()); + assertThat(expandedCountCaptor.getValue()).isEqualTo( + EXPANDED_CHILDREN_COUNT + mPreferenceCategory.getPreferenceCount()); } @Test @@ -148,5 +158,23 @@ public class MultiNetworkHeaderControllerTest { verify(mPreferenceCategory, atLeastOnce()).setVisible(captor.capture()); List values = captor.getAllValues(); assertThat(values.get(values.size()-1)).isEqualTo(Boolean.FALSE); + + ArgumentCaptor expandedCountCaptor = ArgumentCaptor.forClass(Integer.class); + verify(mPreferenceScreen).setInitialExpandedChildrenCount(expandedCountCaptor.capture()); + assertThat(expandedCountCaptor.getValue()).isEqualTo(EXPANDED_CHILDREN_COUNT); + } + + @Test + public void onChildUpdated_noExpandedChildCountAndAvailable_doesNotSetExpandedCount() { + when(mPreferenceScreen.getInitialExpandedChildrenCount()).thenReturn(Integer.MAX_VALUE); + + when(mSubscriptionsController.isAvailable()).thenReturn(false); + mHeaderController.init(mLifecycle); + mHeaderController.displayPreference(mPreferenceScreen); + + when(mSubscriptionsController.isAvailable()).thenReturn(true); + mHeaderController.onChildrenUpdated(); + + verify(mPreferenceScreen, never()).setInitialExpandedChildrenCount(anyInt()); } } diff --git a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index a484745744..97966b3420 100644 --- a/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -20,6 +20,7 @@ import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; import static com.google.common.truth.Truth.assertThat; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; @@ -186,19 +187,24 @@ public class SubscriptionsPreferenceControllerTest { } @Test - public void onSubscriptionsChanged_countBecameOne_eventFired() { + public void onSubscriptionsChanged_countBecameOne_eventFiredAndPrefsRemoved() { final SubscriptionInfo sub1 = mock(SubscriptionInfo.class); final SubscriptionInfo sub2 = mock(SubscriptionInfo.class); + when(sub1.getSubscriptionId()).thenReturn(1); + when(sub2.getSubscriptionId()).thenReturn(2); SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1, sub2)); mController.onResume(); mController.displayPreference(mScreen); assertThat(mController.isAvailable()).isTrue(); + verify(mPreferenceCategory, times(2)).addPreference(any(Preference.class)); final int updateCountBeforeSubscriptionChange = mOnChildUpdatedCount; SubscriptionUtil.setAvailableSubscriptionsForTesting(Arrays.asList(sub1)); mController.onSubscriptionsChanged(); assertThat(mController.isAvailable()).isFalse(); assertThat(mOnChildUpdatedCount).isEqualTo(updateCountBeforeSubscriptionChange + 1); + + verify(mPreferenceCategory, times(2)).removePreference(any(Preference.class)); } -- 2.11.0