@Override
    public void onActualStateChange(Context context, Intent intent) {

      if (!WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(intent.getAction())) {
        return;
      }
      int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, -1);
      int widgetState = wifiApStateToFiveState(wifiState);
      setCurrentState(context, widgetState);
    }
Ejemplo n.º 2
0
    @Override
    public void onReceive(Context content, Intent intent) {
      String action = intent.getAction();
      /// M:
      Xlog.d(TAG, "TetherChangeReceiver - onReceive, action is " + action);

      if (action.equals(ConnectivityManager.ACTION_TETHER_STATE_CHANGED)) {
        // TODO - this should understand the interface types
        ArrayList<String> available =
            intent.getStringArrayListExtra(ConnectivityManager.EXTRA_AVAILABLE_TETHER);
        ArrayList<String> active =
            intent.getStringArrayListExtra(ConnectivityManager.EXTRA_ACTIVE_TETHER);
        ArrayList<String> errored =
            intent.getStringArrayListExtra(ConnectivityManager.EXTRA_ERRORED_TETHER);

        /** M: for bug solving, ALPS00331223 */
        mUsbUnTetherDone = intent.getBooleanExtra("UnTetherDone", false);
        mUsbTetherDone = intent.getBooleanExtra("TetherDone", false);
        mUsbTetherFail = intent.getBooleanExtra("TetherFail", false);

        /// M: print log
        Xlog.d(
            TAG,
            "mUsbUnTetherDone? :"
                + mUsbUnTetherDone
                + " , mUsbTetherDonel? :"
                + mUsbTetherDone
                + " , tether fail? :"
                + mUsbTetherFail);
        updateState(
            available.toArray(new String[available.size()]),
            active.toArray(new String[active.size()]),
            errored.toArray(new String[errored.size()]));
      } else if (action.equals(Intent.ACTION_MEDIA_SHARED)) {
        mMassStorageActive = true;
        updateState();
      } else if (action.equals(Intent.ACTION_MEDIA_UNSHARED)) {
        mMassStorageActive = false;
        updateState();
      } else if (action.equals(UsbManager.ACTION_USB_STATE)) {
        mUsbConnected = intent.getBooleanExtra(UsbManager.USB_CONNECTED, false);
        /// M: @{
        mUsbConfigured = intent.getBooleanExtra(UsbManager.USB_CONFIGURED, false);
        mUsbHwDisconnected = intent.getBooleanExtra("USB_HW_DISCONNECTED", false);
        mIsPcKnowMe = intent.getBooleanExtra("USB_IS_PC_KNOW_ME", true);

        Xlog.d(
            TAG,
            "TetherChangeReceiver - ACTION_USB_STATE mUsbConnected: "
                + mUsbConnected
                + ", mUsbConfigured:  "
                + mUsbConfigured
                + ", mUsbHwDisconnected: "
                + mUsbHwDisconnected);
        /// @}
        updateState();
      } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
        if (mBluetoothEnableForTether) {
          switch (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)) {
            case BluetoothAdapter.STATE_ON:
              BluetoothPan bluetoothPan = mBluetoothPan.get();
              if (bluetoothPan != null) {
                bluetoothPan.setBluetoothTethering(true);
                mBluetoothEnableForTether = false;
              }
              /// M: @{
              BluetoothDun bluetoothDun = BluetoothDunGetProxy();
              if (bluetoothDun != null) {
                bluetoothDun.setBluetoothTethering(true);
                mBluetoothEnableForTether = false;
              }
              /// @}
              break;

            case BluetoothAdapter.STATE_OFF:
            case BluetoothAdapter.ERROR:
              mBluetoothEnableForTether = false;
              break;

            default:
              // ignore transition states
          }
        }
        updateState();
      } else if (action.equals(USB_DATA_STATE)) {
        String dataApnKey = intent.getStringExtra(PhoneConstants.DATA_APN_KEY);
        PhoneConstants.DataState state =
            Enum.valueOf(
                PhoneConstants.DataState.class, intent.getStringExtra(PhoneConstants.STATE_KEY));
        Xlog.d(TAG, "receive USB_DATA_STATE");
        Xlog.d(TAG, "dataApnKey = " + dataApnKey + ", state = " + state);
        if ("internet".equals(dataApnKey)) {
          if (state == PhoneConstants.DataState.CONNECTED) {
            mUsbInternetSharing = true;
          } else {
            mUsbInternetSharing = false;
          }
          updateState();
        }
      } else if (WifiManager.WIFI_AP_STATE_CHANGED_ACTION.equals(action)) {
        /// M: update ipv4 & ipv6 preference @{
        int state =
            intent.getIntExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED);
        if ((state == WifiManager.WIFI_AP_STATE_ENABLED
                || state == WifiManager.WIFI_AP_STATE_DISABLED)
            && FeatureOption.MTK_TETHERINGIPV6_SUPPORT) {
          updateIpv6Preference();
        }
        /// @}
      } else if (action.equals(BluetoothPan.ACTION_CONNECTION_STATE_CHANGED)
          || action.equals(BluetoothDun.STATE_CHANGED_ACTION)) {
        updateState();
      }
    }