From b381ac0bad05dfd9a72d18066417909c6323d647 Mon Sep 17 00:00:00 2001 From: Bonian Chen Date: Tue, 26 May 2020 21:08:59 +0800 Subject: [PATCH] [Settings] Avoid SIM toggle switch loopback API provided by SwitchBar widget would lead to callback when SIM toggle switch operation failure and set UI back. However, set UI back (rollback the UI) would lead to another trigger to SIM toggle switch. This would generate endless events and keep system budy. To avoid from this callback, a check need to be done prior to UI take action. Therefore, changing APIs to fit into this concept. Bug: 155770954 Test: make RunSettingsRoboTests -j ROBOTEST_FILTER=MobileNetworkSwitchControllerTest Change-Id: Iaea1012acdbe449a882ced08b596c64b9f99256f --- .../network/telephony/MobileNetworkSwitchController.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java index a498d474f83..46c5234e4a5 100644 --- a/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java +++ b/src/com/android/settings/network/telephony/MobileNetworkSwitchController.java @@ -75,13 +75,14 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl mSwitchBar.setSwitchBarText(R.string.mobile_network_use_sim_on, R.string.mobile_network_use_sim_off); - mSwitchBar.addOnSwitchChangeListener((switchView, isChecked) -> { + mSwitchBar.getSwitch().setOnBeforeCheckedChangeListener((toggleSwitch, isChecked) -> { // TODO b/135222940: re-evaluate whether to use // mSubscriptionManager#isSubscriptionEnabled if (mSubscriptionManager.isActiveSubscriptionId(mSubId) != isChecked && (!mSubscriptionManager.setSubscriptionEnabled(mSubId, isChecked))) { - mSwitchBar.setChecked(!isChecked); + return true; } + return false; }); update(); } @@ -106,7 +107,7 @@ public class MobileNetworkSwitchController extends BasePreferenceController impl mSwitchBar.hide(); } else { mSwitchBar.show(); - mSwitchBar.setChecked(mSubscriptionManager.isActiveSubscriptionId(mSubId)); + mSwitchBar.setCheckedInternal(mSubscriptionManager.isActiveSubscriptionId(mSubId)); } }