示例#1
0
  private void updateBluetoothState(String[] available, String[] tethered, String[] errored) {
    /// M:   @{
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
      mBtErrorIpv4 = ConnectivityManager.TETHER_ERROR_NO_ERROR;
      mBtErrorIpv6 = ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR;
      for (String s : available) {
        for (String regex : mBluetoothRegexs) {
          if (s.matches(regex) && cm != null) {
            if (mBtErrorIpv4 == ConnectivityManager.TETHER_ERROR_NO_ERROR) {
              mBtErrorIpv4 = (cm.getLastTetherError(s) & 0x0f);
            }
            if (mBtErrorIpv6 == ConnectivityManager.TETHER_ERROR_IPV6_NO_ERROR) {
              mBtErrorIpv6 = (cm.getLastTetherError(s) & 0xf0);
            }
          }
        }
      }
    }
    /// @}

    boolean bluetoothErrored = false;
    for (String s : errored) {
      for (String regex : mBluetoothRegexs) {
        if (s.matches(regex)) {
          bluetoothErrored = true;
        }
      }
    }

    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter == null) {
      return;
    }
    int btState = adapter.getState();
    Xlog.d(TAG, "btState = " + btState);
    if (btState == BluetoothAdapter.STATE_TURNING_OFF) {
      mBluetoothTether.setEnabled(false);
      mBluetoothTether.setSummary(R.string.bluetooth_turning_off);
    } else if (btState == BluetoothAdapter.STATE_TURNING_ON) {
      mBluetoothTether.setEnabled(false);
      mBluetoothTether.setSummary(R.string.bluetooth_turning_on);
    } else {
      BluetoothPan bluetoothPan = mBluetoothPan.get();
      /// M:
      BluetoothDun bluetoothDun = BluetoothDunGetProxy();
      if (btState == BluetoothAdapter.STATE_ON
          && ((bluetoothPan != null && bluetoothPan.isTetheringOn())
              || (bluetoothDun != null && bluetoothDun.isTetheringOn()))) {
        mBluetoothTether.setChecked(true);
        mBluetoothTether.setEnabled(true);
        int bluetoothTethered = 0;
        if (bluetoothPan != null && bluetoothPan.isTetheringOn()) {
          bluetoothTethered = bluetoothPan.getConnectedDevices().size();
          Xlog.d(TAG, "bluetooth Tethered PAN devices = " + bluetoothTethered);
        }
        if (bluetoothDun != null && bluetoothDun.isTetheringOn()) {
          bluetoothTethered += bluetoothDun.getConnectedDevices().size();
          Xlog.d(TAG, "bluetooth tethered total devices = " + bluetoothTethered);
        }

        if (bluetoothTethered > 1) {
          String summary =
              getString(R.string.bluetooth_tethering_devices_connected_subtext, bluetoothTethered);
          if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
            /// M:
            mBluetoothTether.setSummary(summary + getIPV6String(mBtErrorIpv4, mBtErrorIpv6));
          } else {
            mBluetoothTether.setSummary(summary);
          }
        } else if (bluetoothTethered == 1) {
          /// M: @{
          String summary = getString(R.string.bluetooth_tethering_device_connected_subtext);
          if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
            mBluetoothTether.setSummary(summary + getIPV6String(mBtErrorIpv4, mBtErrorIpv6));
          } else {
            mBluetoothTether.setSummary(summary);
          }
          /// @}
        } else if (bluetoothErrored) {
          mBluetoothTether.setSummary(R.string.bluetooth_tethering_errored_subtext);
        } else {
          /// M: @{
          String summary = getString(R.string.bluetooth_tethering_available_subtext);
          if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
            mBluetoothTether.setSummary(summary + getIPV6String(mBtErrorIpv4, mBtErrorIpv6));
          } else {
            mBluetoothTether.setSummary(summary);
          }
          /// @}
        }
      } else {
        mBluetoothTether.setEnabled(true);
        mBluetoothTether.setChecked(false);
        mBluetoothTether.setSummary(R.string.bluetooth_tethering_off_subtext);
      }
    }
  }
示例#2
0
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    addPreferencesFromResource(R.xml.tether_prefs);

    /// M: get plugin
    mExt = Utils.getApnSettingsPlugin(getActivity());

    final Activity activity = getActivity();
    BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
    if (adapter != null) {
      adapter.getProfileProxy(
          activity.getApplicationContext(), mProfileServiceListener, BluetoothProfile.PAN);
    }
    /// M: @{
    mBluetoothDunProxy =
        new BluetoothDun(getActivity().getApplicationContext(), mDunServiceListener);
    mWifiTether = (HotspotSwitchPreference) findPreference(WIFI_SWITCH_SETTINGS);
    mWifiTether.setChecked(false);
    /// @}

    mUsbTether = (CheckBoxPreference) findPreference(USB_TETHER_SETTINGS);
    mBluetoothTether = (CheckBoxPreference) findPreference(ENABLE_BLUETOOTH_TETHERING);

    mTetherIpv6 = (ListPreference) findPreference(TETHERED_IPV6);
    ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    /// M: @{
    mUsbTetherType = (ListPreference) findPreference(USB_TETHERING_TYPE);
    if (!FeatureOption.MTK_TETHERING_EEM_SUPPORT) {
      getPreferenceScreen().removePreference(mUsbTetherType);
    }

    /// @}
    mUsbRegexs = cm.getTetherableUsbRegexs();
    mWifiRegexs = cm.getTetherableWifiRegexs();
    mBluetoothRegexs = cm.getTetherableBluetoothRegexs();

    final boolean usbAvailable = mUsbRegexs.length != 0;
    final boolean wifiAvailable = mWifiRegexs.length != 0;
    final boolean bluetoothAvailable = mBluetoothRegexs.length != 0;

    if (!usbAvailable || Utils.isMonkeyRunning()) {
      getPreferenceScreen().removePreference(mUsbTether);
      getPreferenceScreen().removePreference(mUsbTetherType);
    }

    if (wifiAvailable && !Utils.isMonkeyRunning()) {
      mWifiApEnabler = new WifiApEnabler(activity, mWifiTether);
      mWifiApEnabler.setTetherSettings(this);
    } else {
      getPreferenceScreen().removePreference(mWifiTether);
    }

    if (!bluetoothAvailable) {
      getPreferenceScreen().removePreference(mBluetoothTether);
    } else {
      BluetoothPan pan = mBluetoothPan.get();
      /// M:
      BluetoothDun dun = BluetoothDunGetProxy();
      if ((pan != null && pan.isTetheringOn()) || (dun != null && dun.isTetheringOn())) {
        mBluetoothTether.setChecked(true);
      } else {
        mBluetoothTether.setChecked(false);
      }
    }

    /// M: add tether apn settings
    mExt.customizeTetherApnSettings(getPreferenceScreen());

    mProvisionApp =
        getResources()
            .getStringArray(com.android.internal.R.array.config_mobile_hotspot_provision_app);

    mView = new WebView(activity);

    /// M: @{
    if (FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
      if (mTetherIpv6 != null) {
        mTetherIpv6.setOnPreferenceChangeListener(this);
      }
    } else {
      getPreferenceScreen().removePreference(mTetherIpv6);
    }
    getMountService();
    /// @}
  }