Loading src/com/android/settings/WifiCallingSettings.java +77 −23 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.telephony.CarrierConfigManager; import android.telephony.PhoneStateListener; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Switch; Loading Loading @@ -60,16 +62,31 @@ public class WifiCallingSettings extends SettingsPreferenceFragment private ListPreference mButtonWfcMode; private TextView mEmptyView; private int[] mCallState = null; private PhoneStateListener[] mPhoneStateListener = null; private int mPhoneCount; private boolean mValidListener = false; private boolean mEditableWfcMode = true; private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { private void initPhoneStateListeners(int phoneId) { SubscriptionManager subMgr = SubscriptionManager.from(getActivity()); final SubscriptionInfo subInfo = subMgr.getActiveSubscriptionInfoForSimSlotIndex(phoneId); if (subInfo == null) { Log.e(TAG, "initPhoneStateListeners subInfo : " + subInfo + " for phone Id: " + phoneId); return; } int subId = subInfo.getSubscriptionId(); final int i = phoneId; /* * Enable/disable controls when in/out of a call and depending on * TTY mode and TTY support over VoLTE. * @see android.telephony.PhoneStateListener#onCallStateChanged(int, * java.lang.String) */ mPhoneStateListener[phoneId] = new PhoneStateListener(subId) { @Override public void onCallStateChanged(int state, String incomingNumber) { final SettingsActivity activity = (SettingsActivity) getActivity(); Loading @@ -79,16 +96,16 @@ public class WifiCallingSettings extends SettingsPreferenceFragment boolean isWfcEnabled = switchBar.getSwitch().isChecked() && isNonTtyOrTtyOnVolteEnabled; switchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE) && isNonTtyOrTtyOnVolteEnabled); mCallState[i] = state; switchBar.setEnabled(isCallStateIdle() && isNonTtyOrTtyOnVolteEnabled); Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE); if (pref != null) { pref.setEnabled(isWfcEnabled && (state == TelephonyManager.CALL_STATE_IDLE)); pref.setEnabled(isWfcEnabled && isCallStateIdle()); } } }; } @Override public void onActivityCreated(Bundle savedInstanceState) { Loading Loading @@ -182,6 +199,10 @@ public class WifiCallingSettings extends SettingsPreferenceFragment mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only); mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only); } mPhoneCount = TelephonyManager.getDefault().getPhoneCount(); mPhoneStateListener = new PhoneStateListener[mPhoneCount]; mCallState = new int[mPhoneCount]; } @Override Loading @@ -191,8 +212,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment final Context context = getActivity(); if (ImsManager.isWfcEnabledByPlatform(context)) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); registerPhoneStateListeners(context); mSwitchBar.addOnSwitchChangeListener(this); Loading Loading @@ -224,8 +244,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment if (mValidListener) { mValidListener = false; TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); unRegisterPhoneStateListeners(context); mSwitchBar.removeOnSwitchChangeListener(this); } Loading @@ -233,6 +252,30 @@ public class WifiCallingSettings extends SettingsPreferenceFragment context.unregisterReceiver(mIntentReceiver); } private void registerPhoneStateListeners(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); for (int i = 0; i < mPhoneCount; i++) { initPhoneStateListeners(i); if (mPhoneStateListener[i] != null) { Log.d(TAG, "Register for call state change for phone Id: " + i); tm.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_CALL_STATE); } } } private void unRegisterPhoneStateListeners(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); for (int i = 0; i < mPhoneCount; i++) { if (mPhoneStateListener[i] != null) { Log.d(TAG, "unRegister for call state change for phone Id: " + i); tm.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_NONE); mPhoneStateListener[i] = null; } } } /** * Listens to the state change of the switch. */ Loading Loading @@ -299,4 +342,15 @@ public class WifiCallingSettings extends SettingsPreferenceFragment } return resId; } private boolean isCallStateIdle() { boolean callStateIdle = true; for (int i = 0; i < mCallState.length; i++) { if (TelephonyManager.CALL_STATE_IDLE != mCallState[i]) { callStateIdle = false; } } Log.d(TAG, "isCallStateIdle " + callStateIdle); return callStateIdle; } } Loading
src/com/android/settings/WifiCallingSettings.java +77 −23 Original line number Diff line number Diff line Loading @@ -29,6 +29,8 @@ import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; import android.telephony.CarrierConfigManager; import android.telephony.PhoneStateListener; import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.util.Log; import android.widget.Switch; Loading Loading @@ -60,16 +62,31 @@ public class WifiCallingSettings extends SettingsPreferenceFragment private ListPreference mButtonWfcMode; private TextView mEmptyView; private int[] mCallState = null; private PhoneStateListener[] mPhoneStateListener = null; private int mPhoneCount; private boolean mValidListener = false; private boolean mEditableWfcMode = true; private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() { private void initPhoneStateListeners(int phoneId) { SubscriptionManager subMgr = SubscriptionManager.from(getActivity()); final SubscriptionInfo subInfo = subMgr.getActiveSubscriptionInfoForSimSlotIndex(phoneId); if (subInfo == null) { Log.e(TAG, "initPhoneStateListeners subInfo : " + subInfo + " for phone Id: " + phoneId); return; } int subId = subInfo.getSubscriptionId(); final int i = phoneId; /* * Enable/disable controls when in/out of a call and depending on * TTY mode and TTY support over VoLTE. * @see android.telephony.PhoneStateListener#onCallStateChanged(int, * java.lang.String) */ mPhoneStateListener[phoneId] = new PhoneStateListener(subId) { @Override public void onCallStateChanged(int state, String incomingNumber) { final SettingsActivity activity = (SettingsActivity) getActivity(); Loading @@ -79,16 +96,16 @@ public class WifiCallingSettings extends SettingsPreferenceFragment boolean isWfcEnabled = switchBar.getSwitch().isChecked() && isNonTtyOrTtyOnVolteEnabled; switchBar.setEnabled((state == TelephonyManager.CALL_STATE_IDLE) && isNonTtyOrTtyOnVolteEnabled); mCallState[i] = state; switchBar.setEnabled(isCallStateIdle() && isNonTtyOrTtyOnVolteEnabled); Preference pref = getPreferenceScreen().findPreference(BUTTON_WFC_MODE); if (pref != null) { pref.setEnabled(isWfcEnabled && (state == TelephonyManager.CALL_STATE_IDLE)); pref.setEnabled(isWfcEnabled && isCallStateIdle()); } } }; } @Override public void onActivityCreated(Bundle savedInstanceState) { Loading Loading @@ -182,6 +199,10 @@ public class WifiCallingSettings extends SettingsPreferenceFragment mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only); mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only); } mPhoneCount = TelephonyManager.getDefault().getPhoneCount(); mPhoneStateListener = new PhoneStateListener[mPhoneCount]; mCallState = new int[mPhoneCount]; } @Override Loading @@ -191,8 +212,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment final Context context = getActivity(); if (ImsManager.isWfcEnabledByPlatform(context)) { TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE); registerPhoneStateListeners(context); mSwitchBar.addOnSwitchChangeListener(this); Loading Loading @@ -224,8 +244,7 @@ public class WifiCallingSettings extends SettingsPreferenceFragment if (mValidListener) { mValidListener = false; TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); unRegisterPhoneStateListeners(context); mSwitchBar.removeOnSwitchChangeListener(this); } Loading @@ -233,6 +252,30 @@ public class WifiCallingSettings extends SettingsPreferenceFragment context.unregisterReceiver(mIntentReceiver); } private void registerPhoneStateListeners(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); for (int i = 0; i < mPhoneCount; i++) { initPhoneStateListeners(i); if (mPhoneStateListener[i] != null) { Log.d(TAG, "Register for call state change for phone Id: " + i); tm.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_CALL_STATE); } } } private void unRegisterPhoneStateListeners(Context context) { TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); for (int i = 0; i < mPhoneCount; i++) { if (mPhoneStateListener[i] != null) { Log.d(TAG, "unRegister for call state change for phone Id: " + i); tm.listen(mPhoneStateListener[i], PhoneStateListener.LISTEN_NONE); mPhoneStateListener[i] = null; } } } /** * Listens to the state change of the switch. */ Loading Loading @@ -299,4 +342,15 @@ public class WifiCallingSettings extends SettingsPreferenceFragment } return resId; } private boolean isCallStateIdle() { boolean callStateIdle = true; for (int i = 0; i < mCallState.length; i++) { if (TelephonyManager.CALL_STATE_IDLE != mCallState[i]) { callStateIdle = false; } } Log.d(TAG, "isCallStateIdle " + callStateIdle); return callStateIdle; } }