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); } } }