private void updatePreferenceState() {
    boolean isEnabled = false;
    boolean isOn = AirplaneModeEnabler.isAirplaneModeOn(mContext);
    if (!isOn) {
      // only not in airplane mode and the number of active subscription is 2, enabled.
      if (SubscriptionManager.getInstance().getActiveSubscriptionsCount() == 2) {
        isEnabled = true;
      }
    }

    if (DBG) Log.d(LOG_TAG, "setEnabled: " + isEnabled);
    setEnabled(isEnabled);
  }
  public boolean onPreferenceChange(Preference preference, Object value) {
    int preferredSubscription = Integer.parseInt((String) value);
    if (DBG) Log.d(LOG_TAG, "onPreferenceChange: " + preferredSubscription);

    if (preferredSubscription == mPreferredSubscription) {
      // do nothing but warning
      if (DBG) Log.d(LOG_TAG, "preferred subscription not changed");
    } else if (AirplaneModeEnabler.isAirplaneModeOn(mContext)) {
      // do nothing but warning
      if (DBG) Log.e(LOG_TAG, "error! airplane is on");
    } else {
      mLocalManager.setPreferredSubscription(
          Message.obtain(
              mHandler,
              MultiSimSettingsConstants.EVENT_PREFERRED_SUBSCRIPTION_CHANGED,
              mType,
              preferredSubscription));
    }

    // Don't update UI to opposite state until we're sure
    return false;
  }