Ensure CW button is disabled when it isn't enabled.
The call waiting UI incorrectly toggles (enables) the CW button when an
error occurs, indicating that it is enabled when that isn't case. When
the page is refreshed, the UI is updated accordingly but ideally, that
shouldn't have to occur on a refresh.
Bug: 328560292
Test: m Telephony (unable to test this manually since I don't have a SIM
that has CW enabled)
Change-Id: I14d04604774a1483870e89ed005d6a5489da0f1a
diff --git a/src/com/android/phone/CallWaitingSwitchPreference.java b/src/com/android/phone/CallWaitingSwitchPreference.java
index 00407f3..a5bc92e 100644
--- a/src/com/android/phone/CallWaitingSwitchPreference.java
+++ b/src/com/android/phone/CallWaitingSwitchPreference.java
@@ -35,6 +35,8 @@
private int mUpdateStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
private int mQueryStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR;
private boolean mUssdMode = false;
+ private boolean mCwEnabled = false;
+ private boolean mCwClicked = false;
public CallWaitingSwitchPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
@@ -60,6 +62,7 @@
PersistableBundle bundle = configManager.getConfigForSubId(phone.getSubId());
mUssdMode = (bundle != null) ? bundle.getBoolean(
CarrierConfigManager.KEY_USE_CALL_WAITING_USSD_BOOL, false) : false;
+ mCwEnabled = false;
if (!skipReading) {
Log.d(LOG_TAG, "init getCallWaitingStatus");
@@ -101,7 +104,9 @@
@Override
protected void onClick() {
super.onClick();
- mTelephonyManager.setCallWaitingEnabled(isChecked(), mExecutor, this::updateStatusCallBack);
+ mCwEnabled = isChecked();
+ mCwClicked = true;
+ mTelephonyManager.setCallWaitingEnabled(mCwEnabled, mExecutor, this::updateStatusCallBack);
if (mTcpListener != null) {
mIsDuringUpdateProcess = true;
mTcpListener.onStarted(this, false);
@@ -145,6 +150,8 @@
if (mTcpListener != null) {
mTcpListener.onError(CallWaitingSwitchPreference.this, error);
}
+ handleCwFallbackOnError();
+ setChecked(mCwEnabled);
} else if (mQueryStatus == TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR
|| (mIsDuringUpdateProcess && (
mUpdateStatus != TelephonyManager.CALL_WAITING_STATUS_ENABLED
@@ -153,14 +160,21 @@
if (mTcpListener != null) {
mTcpListener.onError(CallWaitingSwitchPreference.this, RESPONSE_ERROR);
}
+ handleCwFallbackOnError();
+ setChecked(mCwEnabled);
} else {
- if (mQueryStatus == TelephonyManager.CALL_WAITING_STATUS_ENABLED) {
- setChecked(true);
- } else {
- setChecked(false);
- }
+ mCwEnabled = mQueryStatus == TelephonyManager.CALL_WAITING_STATUS_ENABLED;
+ setChecked(mCwEnabled);
}
mIsDuringUpdateProcess = false;
+ mCwClicked = false;
+ }
+ }
+
+ private void handleCwFallbackOnError() {
+ // Recover initial state before onClick.
+ if (mCwClicked) {
+ mCwEnabled = !mCwEnabled;
}
}
}