Don't override expand count when page is opened from search
Change-Id: Ie1afcbc5f87793a4e07ec851f7c1cd205e9d67d2
Fixes: 70235975
Test: robotests
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index a5f7c45..f99b894 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -83,15 +83,22 @@
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
-
+ final Bundle arguments = getArguments();
if (FeatureFlagUtils.isEnabled(getContext(), DEVICE_INFO_V2) || true) {
- // Increase the number of children when the device contains more than 1 sim.
- final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(
- Context.TELEPHONY_SERVICE);
- final int numberOfChildren = Math.max(SIM_PREFERENCES_COUNT,
- SIM_PREFERENCES_COUNT * telephonyManager.getPhoneCount())
- + NON_SIM_PREFERENCES_COUNT;
- getPreferenceScreen().setInitialExpandedChildrenCount(numberOfChildren);
+ // Do not override initial expand children count if we come from
+ // search (EXTRA_FRAGMENT_ARG_KEY is set) - we need to display every if entry point
+ // is search.
+ if (arguments == null
+ || !arguments.containsKey(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY)) {
+
+ // Increase the number of children when the device contains more than 1 sim.
+ final TelephonyManager telephonyManager = (TelephonyManager) getSystemService(
+ Context.TELEPHONY_SERVICE);
+ final int numberOfChildren = Math.max(SIM_PREFERENCES_COUNT,
+ SIM_PREFERENCES_COUNT * telephonyManager.getPhoneCount())
+ + NON_SIM_PREFERENCES_COUNT;
+ getPreferenceScreen().setInitialExpandedChildrenCount(numberOfChildren);
+ }
}
}
diff --git a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
index 0bd8933..7e69172 100644
--- a/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/DeviceInfoSettingsTest.java
@@ -18,6 +18,7 @@
import static com.android.settings.DeviceInfoSettings.NON_SIM_PREFERENCES_COUNT;
import static com.android.settings.DeviceInfoSettings.SIM_PREFERENCES_COUNT;
+import static com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
@@ -28,6 +29,7 @@
import android.app.Activity;
import android.content.Context;
import android.os.Build;
+import android.os.Bundle;
import android.os.SystemProperties;
import android.support.v7.preference.PreferenceScreen;
import android.telephony.TelephonyManager;
@@ -121,6 +123,19 @@
@Test
@Config(shadows = {SettingsShadowResources.SettingsShadowTheme.class,
SettingsShadowSystemProperties.class})
+ public void onCreate_fromSearch_shouldNotOverrideInitialExpandedCount() {
+ final Bundle args = new Bundle();
+ args.putString(EXTRA_FRAGMENT_ARG_KEY, "search_key");
+ mSettings.setArguments(args);
+
+ mSettings.onCreate(null /* icicle */);
+
+ verify(mScreen).setInitialExpandedChildrenCount(Integer.MAX_VALUE);
+ }
+
+ @Test
+ @Config(shadows = {SettingsShadowResources.SettingsShadowTheme.class,
+ SettingsShadowSystemProperties.class})
public void onCreate_singleSim_shouldAddSingleSimCount() {
SystemProperties.set(FeatureFlagUtils.FFLAG_OVERRIDE_PREFIX + FeatureFlags.DEVICE_INFO_V2,
"true");