Exemple #1
0
bool CNetworkInterfaceAndroid::IsConnected()
{
  CJNIConnectivityManager connman(CXBMCApp::getSystemService(CJNIContext::CONNECTIVITY_SERVICE));
  CJNINetworkInfo ni = connman.getNetworkInfo(m_network);
  if (!ni)
    return false;

  return ni.isConnected();
}
Exemple #2
0
bool CNetworkInterfaceAndroid::IsWireless()
{
  CJNIConnectivityManager connman(CXBMCApp::getSystemService(CJNIContext::CONNECTIVITY_SERVICE));
  CJNINetworkInfo ni = connman.getNetworkInfo(m_network);
  if (!ni)
    return false;

  int type = ni.getType();
  return !(type == CJNIConnectivityManager::TYPE_ETHERNET || type == CJNIConnectivityManager::TYPE_DUMMY);
}
Exemple #3
0
std::string CNetworkInterfaceAndroid::GetCurrentWirelessEssId()
{
  std::string ret;

  CJNIConnectivityManager connman(CXBMCApp::getSystemService(CJNIContext::CONNECTIVITY_SERVICE));
  CJNINetworkInfo ni = connman.getNetworkInfo(m_network);
  if (!ni)
    return "";

  if (ni.getType() == CJNIConnectivityManager::TYPE_WIFI)
  {
    CJNIWifiManager wm = CXBMCApp::getSystemService("wifi");
    if (wm.isWifiEnabled())
    {
      CJNIWifiInfo wi = wm.getConnectionInfo();
      ret = wi.getSSID();
    }
  }
  return ret;
}
bool CAndroidNetworkManager::ReceiveNetworkEvent(INetworkEventsCallback *callback, const NetworkEventDataPtr data)
{
  // All actions are event-driven. Android broadcasts connection events in the
  // form of subscribed events from XBMCApp. See CXBMCApp::onReceive

  const CJNIIntent intent(*boost::static_pointer_cast<const CJNIIntent>(data));
  std::string action = intent.getAction();
  CLog::Log(LOGDEBUG, "NetworkManager: Received event: %s",action.c_str());

  if (action == CJNIWifiManager::NETWORK_STATE_CHANGED_ACTION)
  {
    GetEthernetConnection();
    GetWifiAccessPoints();
    GetCurrentWifiConnection();
    if(m_currentWifi.get() && m_currentWifi->GetState() == NETWORK_CONNECTION_STATE_CONNECTED)
    {

      // Call the callback before setting the event so that the connection list
      // Is updated before leaving the wifi dialog
      callback->OnConnectionListChange(GetConnections());
      m_wifiConnectionEvent.Set();
    }
    else
      callback->OnConnectionListChange(GetConnections());
  }
  else if(action == CJNIConnectivityManager::CONNECTIVITY_ACTION)
  {
    const CJNINetworkInfo newNetworkInfo = intent.getParcelableExtra(CJNIWifiManager::EXTRA_NETWORK_INFO);
    if (newNetworkInfo)
    {
      int type = newNetworkInfo.getType();
      std::string typeName = newNetworkInfo.getTypeName();
      std::string stateName = newNetworkInfo.getState().name();
      if (type == CJNIConnectivityManager::TYPE_ETHERNET)
      {
        // This one is simple, just pass the new status along to the connection
        GetEthernetConnection();
        if (m_ethernetConnection.get())
        {
          if(m_ethernetConnection->GetState() == NETWORK_CONNECTION_STATE_CONNECTED)
          {
             callback->OnConnectionListChange(GetConnections());
             m_ethernetConnectionEvent.Set();
          }
          else
            callback->OnConnectionListChange(GetConnections());
        }
      }
      else
      {
        GetWifiAccessPoints();
        GetCurrentWifiConnection();
        callback->OnConnectionListChange(GetConnections());
      }
    }
  }
  else if (action == CJNIWifiManager::SCAN_RESULTS_AVAILABLE_ACTION)
  {
    GetWifiAccessPoints();
    callback->OnConnectionListChange(GetConnections());
  }
  else if (action == CJNIWifiManager::SUPPLICANT_STATE_CHANGED_ACTION)
  {
    int error = intent.getIntExtra(CJNIWifiManager::EXTRA_SUPPLICANT_ERROR, 0);
    if (error == 1)
    {
      CLog::Log(LOGDEBUG, "NetworkManager: authentication failed");
      GetCurrentWifiConnection(); 
      callback->OnConnectionListChange(GetConnections());
      m_currentWifi->OnAuthFailed();
      m_wifiConnectionEvent.Set();
    }
  }
  else if (action == CJNIWifiManager::RSSI_CHANGED_ACTION)
  {
    if (!m_currentWifi.get())
      GetCurrentWifiConnection();

    if (m_currentWifi.get())
    {
      int newRSSI = intent.getIntExtra(CJNIWifiManager::EXTRA_NEW_RSSI, 0);
      m_currentWifi->SetStrength(newRSSI);
      callback->OnConnectionChange(m_currentWifi);
    }
  }
  return true;
}