Merge "Set some preferences to disabled when device is in call." into r-keystone-qcom-dev
diff --git a/src/com/android/settings/network/telephony/Enabled5GPreferenceController.java b/src/com/android/settings/network/telephony/Enabled5GPreferenceController.java
index 08b3c18..6e4dccc 100755
--- a/src/com/android/settings/network/telephony/Enabled5GPreferenceController.java
+++ b/src/com/android/settings/network/telephony/Enabled5GPreferenceController.java
@@ -39,9 +39,11 @@
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
+import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@@ -64,9 +66,12 @@
private static final String TAG = "Enable5g";
Preference mPreference;
+ private PhoneCallStateListener mPhoneStateListener;
private CarrierConfigManager mCarrierConfigManager;
private PersistableBundle mCarrierConfig;
private TelephonyManager mTelephonyManager;
+ @VisibleForTesting
+ Integer mCallState;
private ContentObserver mPreferredNetworkModeObserver;
private ContentObserver mSubsidySettingsObserver;
@@ -95,6 +100,10 @@
}
public Enabled5GPreferenceController init(int subId) {
+ if (mPhoneStateListener == null) {
+ mPhoneStateListener = new PhoneCallStateListener();
+ }
+
if (SubscriptionManager.isValidSubscriptionId(mSubId) && mSubId == subId) {
return this;
}
@@ -136,6 +145,9 @@
mPreferredNetworkModeObserver);
mContext.registerReceiver(mDefaultDataChangedReceiver,
new IntentFilter(TelephonyIntents.ACTION_DEFAULT_DATA_SUBSCRIPTION_CHANGED));
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.register(mContext, mSubId);
+ }
}
@Override
@@ -146,6 +158,9 @@
if (mDefaultDataChangedReceiver != null) {
mContext.unregisterReceiver(mDefaultDataChangedReceiver);
}
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.unregister();
+ }
}
@Override
@@ -158,6 +173,7 @@
Settings.Global.PREFERRED_NETWORK_MODE + mSubId,
TelephonyManager.DEFAULT_PREFERRED_NETWORK_MODE));
switchPreference.setChecked(isNrNetworkModeType(preferredNetworkBitMask));
+ switchPreference.setEnabled(isCallStateIdle());
}
@Override
@@ -209,4 +225,42 @@
}
return false;
}
+
+ boolean isCallStateIdle() {
+ boolean callStateIdle = true;
+ if (mCallState != null && mCallState != TelephonyManager.CALL_STATE_IDLE) {
+ callStateIdle = false;
+ }
+ Log.d(TAG, "isCallStateIdle:" + callStateIdle);
+ return callStateIdle;
+ }
+
+ private class PhoneCallStateListener extends PhoneStateListener {
+
+ PhoneCallStateListener() {
+ super(Looper.getMainLooper());
+ }
+
+ private TelephonyManager mTelephonyManager;
+
+ @Override
+ public void onCallStateChanged(int state, String incomingNumber) {
+ mCallState = state;
+ updateState(mPreference);
+ }
+
+ public void register(Context context, int subId) {
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
+ if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
+ }
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
+
+ }
+
+ public void unregister() {
+ mCallState = null;
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
+ }
+ }
}
diff --git a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
index 1504fe5..f9eba23 100644
--- a/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/EnabledNetworkModePreferenceController.java
@@ -26,10 +26,12 @@
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
+import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
@@ -61,6 +63,9 @@
private TelephonyManager mTelephonyManager;
private CarrierConfigManager mCarrierConfigManager;
private PreferenceEntriesBuilder mBuilder;
+ private PhoneCallStateListener mPhoneStateListener;
+ @VisibleForTesting
+ Integer mCallState;
// Local cache for Primary Card and Subsidy Lock related vendor properties. Reading these
// properties are a costly affair since they involve two IPC calls, an AIDL and another HIDL.
@@ -100,6 +105,10 @@
if (mPreferredNetworkModeObserver == null || mSubsidySettingsObserver == null) {
return;
}
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.register(mContext, mSubId);
+ }
+
loadPrimaryCardAndSubsidyLockValues();
mPreferredNetworkModeObserver.register(mContext, mSubId);
if (mIsSubsidyLockFeatureEnabled) {
@@ -114,6 +123,9 @@
if (mPreferredNetworkModeObserver == null) {
return;
}
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.unregister();
+ }
mPreferredNetworkModeObserver.unregister(mContext);
if (mSubsidySettingsObserver != null) {
mContext.getContentResolver().unregisterContentObserver(mSubsidySettingsObserver);
@@ -139,6 +151,7 @@
listPreference.setEntryValues(mBuilder.getEntryValues());
listPreference.setValue(Integer.toString(mBuilder.getSelectedEntryValue()));
listPreference.setSummary(mBuilder.getSummary());
+ listPreference.setEnabled(isCallStateIdle());
}
@Override
@@ -163,6 +176,9 @@
mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
mBuilder = new PreferenceEntriesBuilder(mContext, mSubId);
+ if (mPhoneStateListener == null) {
+ mPhoneStateListener = new PhoneCallStateListener();
+ }
if (mPreferredNetworkModeObserver == null) {
mPreferredNetworkModeObserver = new PreferredNetworkModeContentObserver(
new Handler(Looper.getMainLooper()));
@@ -879,4 +895,42 @@
Log.d(LOG_TAG, "mIsSubsidyLockFeatureEnabled: " + mIsSubsidyLockFeatureEnabled);
}
}
+
+ private boolean isCallStateIdle() {
+ boolean callStateIdle = true;
+ if (mCallState != null && mCallState != TelephonyManager.CALL_STATE_IDLE) {
+ callStateIdle = false;
+ }
+ Log.d(LOG_TAG, "isCallStateIdle:" + callStateIdle);
+ return callStateIdle;
+ }
+
+ private class PhoneCallStateListener extends PhoneStateListener {
+
+ PhoneCallStateListener() {
+ super(Looper.getMainLooper());
+ }
+
+ private TelephonyManager mTelephonyManager;
+
+ @Override
+ public void onCallStateChanged(int state, String incomingNumber) {
+ mCallState = state;
+ updateState(mPreference);
+ }
+
+ public void register(Context context, int subId) {
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
+ if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
+ }
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
+
+ }
+
+ public void unregister() {
+ mCallState = null;
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
+ }
+ }
}
diff --git a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
index 7a4b05e..774c3f0 100644
--- a/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
+++ b/src/com/android/settings/network/telephony/PreferredNetworkModePreferenceController.java
@@ -26,10 +26,12 @@
import android.os.PersistableBundle;
import android.provider.Settings;
import android.telephony.CarrierConfigManager;
+import android.telephony.PhoneStateListener;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.util.Log;
+import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleObserver;
import androidx.lifecycle.OnLifecycleEvent;
@@ -54,6 +56,9 @@
private PersistableBundle mPersistableBundle;
private boolean mIsGlobalCdma;
private Preference mPreference;
+ private PhoneCallStateListener mPhoneStateListener;
+ @VisibleForTesting
+ Integer mCallState;
// Local cache for Primary Card and Subsidy Lock related vendor properties. Reading these
// properties are a costly affair since they involve two IPC calls, an AIDL and another HIDL.
@@ -111,6 +116,10 @@
@OnLifecycleEvent(ON_START)
public void onStart() {
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.register(mContext, mSubId);
+ }
+
loadPrimaryCardAndSubsidyLockValues();
if (mIsSubsidyLockFeatureEnabled) {
mContext.getContentResolver().registerContentObserver(
@@ -124,6 +133,9 @@
@OnLifecycleEvent(ON_STOP)
public void onStop() {
+ if (mPhoneStateListener != null) {
+ mPhoneStateListener.unregister();
+ }
if (mSubsidySettingsObserver != null) {
mContext.getContentResolver().unregisterContentObserver(mSubsidySettingsObserver);
}
@@ -146,6 +158,7 @@
updatePreferenceEntries(listPreference);
listPreference.setValue(Integer.toString(networkMode));
listPreference.setSummary(getPreferredNetworkModeSummaryResId(networkMode));
+ listPreference.setEnabled(isCallStateIdle());
}
@Override
@@ -167,6 +180,9 @@
public void init(Lifecycle lifecycle, int subId) {
mSubId = subId;
+ if (mPhoneStateListener == null) {
+ mPhoneStateListener = new PhoneCallStateListener();
+ }
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
mTelephonyManager = mContext.getSystemService(TelephonyManager.class)
.createForSubscriptionId(mSubId);
@@ -345,4 +361,42 @@
Log.d(LOG_TAG, "mIsSubsidyLockFeatureEnabled: " + mIsSubsidyLockFeatureEnabled);
}
}
+
+ private boolean isCallStateIdle() {
+ boolean callStateIdle = true;
+ if (mCallState != null && mCallState != TelephonyManager.CALL_STATE_IDLE) {
+ callStateIdle = false;
+ }
+ Log.d(LOG_TAG, "isCallStateIdle:" + callStateIdle);
+ return callStateIdle;
+ }
+
+ private class PhoneCallStateListener extends PhoneStateListener {
+
+ PhoneCallStateListener() {
+ super(Looper.getMainLooper());
+ }
+
+ private TelephonyManager mTelephonyManager;
+
+ @Override
+ public void onCallStateChanged(int state, String incomingNumber) {
+ mCallState = state;
+ updateState(mPreference);
+ }
+
+ public void register(Context context, int subId) {
+ mTelephonyManager = context.getSystemService(TelephonyManager.class);
+ if (SubscriptionManager.isValidSubscriptionId(subId)) {
+ mTelephonyManager = mTelephonyManager.createForSubscriptionId(subId);
+ }
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_CALL_STATE);
+
+ }
+
+ public void unregister() {
+ mCallState = null;
+ mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
+ }
+ }
}