OSDN Git Service

Ensure that listener is removed only if it was added
authorPavel Zhamaitsiak <pavelz@google.com>
Fri, 7 Aug 2015 19:02:38 +0000 (12:02 -0700)
committerPavel Zhamaitsiak <pavelz@google.com>
Fri, 7 Aug 2015 19:02:38 +0000 (12:02 -0700)
Bug: 23016088
Change-Id: Ia6f17739ffc841ce8483e9c6c8132a94ecd62200

src/com/android/settings/WifiCallingSettings.java

index 62c7b3e..787ccb4 100644 (file)
@@ -57,6 +57,8 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
     private ListPreference mButtonWfcMode;
     private TextView mEmptyView;
 
+    private boolean mValidListener = false;
+
     private final PhoneStateListener mPhoneStateListener = new PhoneStateListener() {
         /*
          * Enable/disable controls when in/out of a call and depending on
@@ -172,6 +174,8 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
             tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
 
             mSwitchBar.addOnSwitchChangeListener(this);
+
+            mValidListener = true;
         }
 
         // NOTE: Buttons will be enabled/disabled in mPhoneStateListener
@@ -196,7 +200,9 @@ public class WifiCallingSettings extends SettingsPreferenceFragment
 
         final Context context = getActivity();
 
-        if (ImsManager.isWfcEnabledByPlatform(getActivity())) {
+        if (mValidListener) {
+            mValidListener = false;
+
             TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
             tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE);