diff --git a/res/layout/udfps_enroll_enrolling.xml b/res/layout/udfps_enroll_enrolling.xml index 03b6528b32e..6b3382cb606 100644 --- a/res/layout/udfps_enroll_enrolling.xml +++ b/res/layout/udfps_enroll_enrolling.xml @@ -20,7 +20,47 @@ android:id="@+id/setup_wizard_layout" android:layout_width="match_parent" android:layout_height="match_parent" - android:layout="@layout/sud_glif_blank_template" style="?attr/fingerprint_layout_theme"> + + + + + + + + + + + + + diff --git a/res/layout/udfps_enroll_layout.xml b/res/layout/udfps_enroll_layout.xml deleted file mode 100644 index 833858911d2..00000000000 --- a/res/layout/udfps_enroll_layout.xml +++ /dev/null @@ -1,77 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/res/xml/display_settings.xml b/res/xml/display_settings.xml index 8df5696a0c4..27bf0ba206f 100644 --- a/res/xml/display_settings.xml +++ b/res/xml/display_settings.xml @@ -20,7 +20,7 @@ android:key="display_settings_screen" android:title="@string/display_settings" settings:keywords="@string/keywords_display" - settings:initialExpandedChildrenCount="5"> + settings:initialExpandedChildrenCount="6"> diff --git a/res/xml/transcode_settings.xml b/res/xml/transcode_settings.xml index b142d318392..c5a9763e4b5 100644 --- a/res/xml/transcode_settings.xml +++ b/res/xml/transcode_settings.xml @@ -35,4 +35,9 @@ android:key="transcode_default" android:title="@string/transcode_default" settings:controller="com.android.settings.development.transcode.TranscodeDefaultOptionPreferenceController" /> + + diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java index 78abb58bd80..1b2a6a5f071 100644 --- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java +++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java @@ -144,12 +144,7 @@ public class FingerprintEnrollEnrolling extends BiometricsEnrollEnrolling { mCanAssumeUdfps = props.size() == 1 && props.get(0).isAnyUdfpsType(); if (mCanAssumeUdfps) { - // Use a custom layout since animations, etc must be based off of the sensor's physical - // location. setContentView(R.layout.udfps_enroll_enrolling); - final UdfpsEnrollLayout udfpsEnrollLayout = (UdfpsEnrollLayout) getLayoutInflater() - .inflate(R.layout.udfps_enroll_layout, null /* root */); - getLayout().addView(udfpsEnrollLayout); } else { setContentView(R.layout.fingerprint_enroll_enrolling); } diff --git a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java index 8097adc701f..394b6733786 100644 --- a/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java +++ b/src/com/android/settings/biometrics/fingerprint/SetupFingerprintEnrollFindSensor.java @@ -36,11 +36,6 @@ import com.android.settings.password.ChooseLockSettingsHelper; public class SetupFingerprintEnrollFindSensor extends FingerprintEnrollFindSensor { - @Override - protected int getContentView() { - return R.layout.fingerprint_enroll_find_sensor; - } - @Override protected Intent getFingerprintEnrollingIntent() { Intent intent = new Intent(this, SetupFingerprintEnrollEnrolling.class); diff --git a/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollLayout.java b/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollLayout.java deleted file mode 100644 index 7923d27a01d..00000000000 --- a/src/com/android/settings/biometrics/fingerprint/UdfpsEnrollLayout.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.settings.biometrics.fingerprint; - -import android.content.Context; -import android.hardware.fingerprint.FingerprintManager; -import android.hardware.fingerprint.FingerprintSensorPropertiesInternal; -import android.util.AttributeSet; -import android.view.View; -import android.view.WindowInsets; -import android.view.WindowManager; -import android.widget.LinearLayout; - -import com.android.settings.R; - -public class UdfpsEnrollLayout extends LinearLayout { - - private static final String TAG = "UdfpsEnrollLayout"; - - public UdfpsEnrollLayout(Context context, AttributeSet attrs) { - super(context, attrs); - } - - @Override - public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec); - } -} diff --git a/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java b/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java index 78352d33cd1..d5d40254fa8 100644 --- a/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java +++ b/src/com/android/settings/development/ForcePeakRefreshRatePreferenceController.java @@ -122,7 +122,7 @@ public class ForcePeakRefreshRatePreferenceController extends DeveloperOptionsPr private float findPeakRefreshRate(Display.Mode[] modes) { float peakRefreshRate = DEFAULT_REFRESH_RATE; for (Display.Mode mode : modes) { - if (Math.round(mode.getRefreshRate()) > DEFAULT_REFRESH_RATE) { + if (Math.round(mode.getRefreshRate()) > peakRefreshRate) { peakRefreshRate = mode.getRefreshRate(); } } diff --git a/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java new file mode 100644 index 00000000000..e51f8ad5b63 --- /dev/null +++ b/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceController.java @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.development.transcode; + +import android.content.Context; +import android.os.SystemProperties; + +import com.android.internal.annotations.VisibleForTesting; +import com.android.settings.core.TogglePreferenceController; + +/** + * The controller (in the Media transcoding settings) indicating the user's preference to show + * or hide the transcoding notifications. + */ +public class TranscodeNotificationPreferenceController extends TogglePreferenceController { + @VisibleForTesting + static final String TRANSCODE_NOTIFICATION_SYS_PROP_KEY = + "persist.sys.fuse.transcode_notification"; + + public TranscodeNotificationPreferenceController(Context context, String preferenceKey) { + super(context, preferenceKey); + } + + @Override + public boolean isChecked() { + return SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, true); + } + + @Override + public boolean setChecked(boolean isChecked) { + SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, String.valueOf(isChecked)); + return true; + } + + @Override + public int getAvailabilityStatus() { + return AVAILABLE; + } +} diff --git a/src/com/android/settings/display/PeakRefreshRatePreferenceController.java b/src/com/android/settings/display/PeakRefreshRatePreferenceController.java index 10cab1c9e27..36e085a068f 100644 --- a/src/com/android/settings/display/PeakRefreshRatePreferenceController.java +++ b/src/com/android/settings/display/PeakRefreshRatePreferenceController.java @@ -129,10 +129,11 @@ public class PeakRefreshRatePreferenceController extends TogglePreferenceControl mDeviceConfigDisplaySettings.stopListening(); } - private float findPeakRefreshRate(Display.Mode[] modes) { + @VisibleForTesting + float findPeakRefreshRate(Display.Mode[] modes) { float peakRefreshRate = DEFAULT_REFRESH_RATE; for (Display.Mode mode : modes) { - if (Math.round(mode.getRefreshRate()) > DEFAULT_REFRESH_RATE) { + if (Math.round(mode.getRefreshRate()) > peakRefreshRate) { peakRefreshRate = mode.getRefreshRate(); } } diff --git a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java index 257810c595d..122e13ab05b 100644 --- a/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java +++ b/src/com/android/settings/fuelgauge/batterysaver/BatterySaverButtonPreferenceController.java @@ -88,8 +88,8 @@ public class BatterySaverButtonPreferenceController extends @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); - mPreference = (MainSwitchPreference) screen.findPreference(getPreferenceKey()); - mPreference.setTitle(mContext.getString(R.string.battery_saver_main_switch_title)); + mPreference = screen.findPreference(getPreferenceKey()); + mPreference.setTitle(mContext.getString(R.string.battery_saver_master_switch_title)); mPreference.addOnSwitchChangeListener(this); mPreference.updateStatus(isChecked()); } diff --git a/src/com/android/settings/network/SubscriptionsPreferenceController.java b/src/com/android/settings/network/SubscriptionsPreferenceController.java index d028c5835e2..392ccc6aba5 100644 --- a/src/com/android/settings/network/SubscriptionsPreferenceController.java +++ b/src/com/android/settings/network/SubscriptionsPreferenceController.java @@ -35,6 +35,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; +import android.text.Html; import android.util.ArraySet; import androidx.annotation.VisibleForTesting; @@ -255,14 +256,17 @@ public class SubscriptionsPreferenceController extends AbstractPreferenceControl mUpdateListener.onChildrenUpdated(); } - private String getMobilePreferenceSummary(int subId) { + private CharSequence getMobilePreferenceSummary(int subId) { String result = mSubsPrefCtrlInjector.getNetworkType( mContext, mConfig, mTelephonyDisplayInfo, subId); + if (!mTelephonyManager.isDataEnabled()) { + return mContext.getString(R.string.mobile_data_off_summary); + } if (!result.isEmpty() && mSubsPrefCtrlInjector.isActiveCellularNetwork(mContext)) { result = mContext.getString(R.string.preference_summary_default_combination, mContext.getString(R.string.mobile_data_connection_active), result); } - return result; + return Html.fromHtml(result, Html.FROM_HTML_MODE_LEGACY); } private Drawable getIcon(int subId) { diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java index 9e7a3a8b2a5..5680bf60140 100644 --- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java +++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java @@ -35,6 +35,7 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.network.AllowedNetworkTypesListener; +import com.android.settings.network.SubscriptionsChangeListener; import com.android.settings.network.telephony.TelephonyConstants.TelephonyManagerConstants; import java.util.ArrayList; @@ -47,7 +48,8 @@ import java.util.stream.Stream; */ public class EnabledNetworkModePreferenceController extends TelephonyBasePreferenceController implements - ListPreference.OnPreferenceChangeListener, LifecycleObserver { + ListPreference.OnPreferenceChangeListener, LifecycleObserver, + SubscriptionsChangeListener.SubscriptionsChangeListenerClient { private static final String LOG_TAG = "EnabledNetworkMode"; private AllowedNetworkTypesListener mAllowedNetworkTypesListener; @@ -56,9 +58,11 @@ public class EnabledNetworkModePreferenceController extends private TelephonyManager mTelephonyManager; private CarrierConfigManager mCarrierConfigManager; private PreferenceEntriesBuilder mBuilder; + private SubscriptionsChangeListener mSubscriptionsListener; public EnabledNetworkModePreferenceController(Context context, String key) { super(context, key); + mSubscriptionsListener = new SubscriptionsChangeListener(context, this); } @Override @@ -85,6 +89,7 @@ public class EnabledNetworkModePreferenceController extends @OnLifecycleEvent(ON_START) public void onStart() { + mSubscriptionsListener.start(); if (mAllowedNetworkTypesListener == null) { return; } @@ -93,6 +98,7 @@ public class EnabledNetworkModePreferenceController extends @OnLifecycleEvent(ON_STOP) public void onStop() { + mSubscriptionsListener.stop(); if (mAllowedNetworkTypesListener == null) { return; } @@ -196,11 +202,14 @@ public class EnabledNetworkModePreferenceController extends PreferenceEntriesBuilder(Context context, int subId) { this.mContext = context; this.mSubId = subId; - mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class); mTelephonyManager = mContext.getSystemService(TelephonyManager.class) .createForSubscriptionId(mSubId); + updateConfig(); + } + public void updateConfig() { + mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId); final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId); mAllowed5gNetworkType = checkSupportedRadioBitmask( mTelephonyManager.getAllowedNetworkTypesForReason( @@ -214,6 +223,11 @@ public class EnabledNetworkModePreferenceController extends && carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL); mShow4gForLTE = carrierConfig != null && carrierConfig.getBoolean( CarrierConfigManager.KEY_SHOW_4G_FOR_LTE_DATA_ICON_BOOL); + Log.d(LOG_TAG, "PreferenceEntriesBuilder: subId" + mSubId + + ",Supported5gRadioAccessFamily :" + mSupported5gRadioAccessFamily + + ",mAllowed5gNetworkType :" + mAllowed5gNetworkType + + ",IsGlobalCdma :" + mIsGlobalCdma + + ",Show4gForLTE :" + mShow4gForLTE); } void setPreferenceEntries() { @@ -818,4 +832,13 @@ public class EnabledNetworkModePreferenceController extends } } + + @Override + public void onAirplaneModeChanged(boolean airplaneModeEnabled) { + } + + @Override + public void onSubscriptionsChanged() { + mBuilder.updateConfig(); + } } diff --git a/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java index cae7d896916..aaeeea4f368 100644 --- a/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/display/PeakRefreshRatePreferenceControllerTest.java @@ -24,6 +24,7 @@ import static com.google.common.truth.Truth.assertThat; import android.content.Context; import android.provider.Settings; +import android.view.Display; import androidx.preference.SwitchPreference; @@ -102,6 +103,21 @@ public class PeakRefreshRatePreferenceControllerTest { assertThat(mController.isChecked()).isFalse(); } + @Test + public void findPeakRefreshRate_moreThanOneHigherThanDefault() { + Display.Mode lower = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE - 1); + Display.Mode def = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE); + Display.Mode higher = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE + 1); + Display.Mode higher1 = new Display.Mode(0, 0, 0, DEFAULT_REFRESH_RATE + 2); + + assertThat(mController.findPeakRefreshRate( + new Display.Mode[] {lower, def, higher, higher1})) + .isEqualTo(DEFAULT_REFRESH_RATE + 2); + assertThat(mController.findPeakRefreshRate( + new Display.Mode[] {lower, def, higher1, higher})) + .isEqualTo(DEFAULT_REFRESH_RATE + 2); + } + private void enableSmoothDisplayPreference() { mController.mPeakRefreshRate = 88f; diff --git a/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java new file mode 100644 index 00000000000..0903c72a099 --- /dev/null +++ b/tests/unit/src/com/android/settings/development/transcode/TranscodeNotificationPreferenceControllerTest.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2021 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.development.transcode; + +import static com.android.settings.development.transcode.TranscodeNotificationPreferenceController.TRANSCODE_NOTIFICATION_SYS_PROP_KEY; + +import static com.google.common.truth.Truth.assertThat; + +import android.content.Context; +import android.os.SystemProperties; + +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import com.android.settings.core.BasePreferenceController; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class TranscodeNotificationPreferenceControllerTest { + private TranscodeNotificationPreferenceController mUnderTest; + + @Before + public void setUp() { + Context context = ApplicationProvider.getApplicationContext(); + mUnderTest = new TranscodeNotificationPreferenceController(context, "notification_key"); + } + + @Test + public void isChecked_whenSysPropSet_shouldReturnTrue() { + SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, "true"); + assertThat(mUnderTest.isChecked()).isTrue(); + } + + @Test + public void isChecked_whenSysPropUnset_shouldReturnFalse() { + SystemProperties.set(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, "false"); + assertThat(mUnderTest.isChecked()).isFalse(); + } + + @Test + public void setChecked_withTrue_shouldSetSysProp() { + mUnderTest.setChecked(true); + assertThat( + SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, false)).isTrue(); + } + + @Test + public void setChecked_withFalse_shouldUnsetSysProp() { + mUnderTest.setChecked(false); + assertThat( + SystemProperties.getBoolean(TRANSCODE_NOTIFICATION_SYS_PROP_KEY, true)).isFalse(); + } + + @Test + public void getAvailabilityStatus_shouldReturn_isAvailable() { + assertThat(mUnderTest.getAvailabilityStatus()).isEqualTo( + BasePreferenceController.AVAILABLE); + } +} diff --git a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java index ef3f130911f..6b31342d31e 100644 --- a/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/SubscriptionsPreferenceControllerTest.java @@ -16,7 +16,6 @@ package com.android.settings.network; -import static android.telephony.SignalStrength.NUM_SIGNAL_STRENGTH_BINS; import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GOOD; import static android.telephony.SignalStrength.SIGNAL_STRENGTH_GREAT; import static android.telephony.SubscriptionManager.INVALID_SUBSCRIPTION_ID; @@ -24,6 +23,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.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq;; import static org.mockito.Mockito.doReturn; @@ -47,6 +47,7 @@ import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyDisplayInfo; import android.telephony.TelephonyManager; +import android.text.Html; import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleRegistry; @@ -371,14 +372,14 @@ public class SubscriptionsPreferenceControllerTest { final Preference pref = new Preference(mContext); final Drawable greatDrawWithoutCutOff = mock(Drawable.class); doReturn(greatDrawWithoutCutOff).when(sInjector) - .getIcon(mContext, 4, NUM_SIGNAL_STRENGTH_BINS, true); + .getIcon(any(), anyInt(), anyInt(), anyBoolean()); mController.setIcon(pref, 1, true /* isDefaultForData */); assertThat(pref.getIcon()).isEqualTo(greatDrawWithoutCutOff); final Drawable greatDrawWithCutOff = mock(Drawable.class); doReturn(greatDrawWithCutOff).when(sInjector) - .getIcon(mContext, 4, NUM_SIGNAL_STRENGTH_BINS, true); + .getIcon(any(), anyInt(), anyInt(), anyBoolean()); mController.setIcon(pref, 2, false /* isDefaultForData */); assertThat(pref.getIcon()).isEqualTo(greatDrawWithCutOff); } @@ -416,7 +417,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void displayPreference_providerAndHasMultiSimAndActive_connectedAndRat() { - final String expectedSummary = "Connected / 5G"; + final CharSequence expectedSummary = + Html.fromHtml("Connected / 5G", Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); @@ -426,6 +428,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); @@ -435,8 +438,11 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest - public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { - final String expectedSummary = "5G"; + public void displayPreference_providerAndHasMultiSimButMobileDataOff_notAutoConnect() { + final String dataOffSummary = + ResourcesUtils.getResourcesString(mContext, "mobile_data_off_summary"); + final CharSequence expectedSummary = + Html.fromHtml(dataOffSummary, Html.FROM_HTML_MODE_LEGACY); final String networkType = "5G"; final List sub = setupMockSubscriptions(2); doReturn(true).when(sInjector).isProviderModelEnabled(mContext); @@ -449,6 +455,27 @@ public class SubscriptionsPreferenceControllerTest { mController.onResume(); mController.displayPreference(mPreferenceScreen); + assertThat(mPreferenceCategory.getPreference(0).getSummary()) + .isEqualTo(expectedSummary.toString()); + } + + @Test + @UiThreadTest + public void displayPreference_providerAndHasMultiSimAndNotActive_showRatOnly() { + final CharSequence expectedSummary = Html.fromHtml("5G", Html.FROM_HTML_MODE_LEGACY); + final String networkType = "5G"; + final List sub = setupMockSubscriptions(2); + doReturn(true).when(sInjector).isProviderModelEnabled(mContext); + doReturn(sub.get(0)).when(mSubscriptionManager).getDefaultDataSubscriptionInfo(); + setupGetIconConditions(sub.get(0).getSubscriptionId(), false, true, + TelephonyManager.DATA_CONNECTED, ServiceState.STATE_IN_SERVICE); + doReturn(networkType) + .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); + + mController.onResume(); + mController.displayPreference(mPreferenceScreen); + assertThat(mPreferenceCategory.getPreference(0).getSummary()).isEqualTo(expectedSummary); } @@ -467,7 +494,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void onTelephonyDisplayInfoChanged_providerAndHasMultiSimAndActive_connectedAndRat() { - final String expectedSummary = "Connected / LTE"; + final CharSequence expectedSummary = + Html.fromHtml("Connected / LTE", Html.FROM_HTML_MODE_LEGACY); final String networkType = "LTE"; final List sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = @@ -480,6 +508,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); @@ -491,7 +520,8 @@ public class SubscriptionsPreferenceControllerTest { @Test @UiThreadTest public void onTelephonyDisplayInfoChanged_providerAndHasMultiSimAndNotActive_showRat() { - final String expectedSummary = "LTE"; + final CharSequence expectedSummary = + Html.fromHtml("LTE", Html.FROM_HTML_MODE_LEGACY); final String networkType = "LTE"; final List sub = setupMockSubscriptions(2); final TelephonyDisplayInfo telephonyDisplayInfo = @@ -504,6 +534,7 @@ public class SubscriptionsPreferenceControllerTest { doReturn(mock(MobileMappings.Config.class)).when(sInjector).getConfig(mContext); doReturn(networkType) .when(sInjector).getNetworkType(any(), any(), any(), anyInt()); + when(mTelephonyManager.isDataEnabled()).thenReturn(true); mController.onResume(); mController.displayPreference(mPreferenceScreen); diff --git a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java index 9b9bb1131d3..293a19dad09 100644 --- a/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java +++ b/tests/unit/src/com/android/settings/network/telephony/Enable2gPreferenceControllerTest.java @@ -22,6 +22,8 @@ import static com.google.common.truth.Truth.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import android.content.Context; @@ -117,4 +119,27 @@ public final class Enable2gPreferenceControllerTest { assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE); } + + @Test + public void onPreferenceChange_update() { + // Set "Enable 2G" flag to "on" + when(mTelephonyManager.getAllowedNetworkTypesForReason( + TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G)).thenReturn( + (long) (TelephonyManager.NETWORK_TYPE_BITMASK_GSM + | TelephonyManager.NETWORK_TYPE_BITMASK_LTE)); + + // Setup state to allow disabling + doReturn(true).when(mTelephonyManager).isRadioInterfaceCapabilitySupported( + mTelephonyManager.CAPABILITY_ALLOWED_NETWORK_TYPES_USED); + mPersistableBundle.putBoolean(CarrierConfigManager.KEY_HIDE_ENABLE_2G, + false); + + // Disable 2G + boolean changed = mController.setChecked(false); + assertThat(changed).isEqualTo(true); + + verify(mTelephonyManager, times(1)).setAllowedNetworkTypesForReason( + TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_ENABLE_2G, + TelephonyManager.NETWORK_TYPE_BITMASK_LTE); + } }