Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-26001

Android custom Module : Unable to connect WIFI of Android 8 devices

    Details

    • Type: Bug
    • Status: Closed
    • Priority: None
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Android
    • Labels:
    • Environment:
    • Story Points:
      8
    • Sprint:
      2018 Sprint 11 SDK, 2018 Sprint 12 SDK

      Description

      We are using below code to connect to Android device Wifi programatically. This code is working fine Android devices 7 and below. Same code is not working in Android 8. We have developed sample app in Android studio where we are able to connect to WIFI using wifiManager manager class. Due to this we are suspecting this issue might exists only if we using Appcelerator module. Details are mentioned after the code.
      Code used to connect :

      List scanResultList = getScanningResults();
      int res =0;
      for (ScanResult result : scanResultList) {
       
      if (result.SSID.equals(networkSSID)) {
       
      try
      {
      WifiConfiguration wifiConfiguration = createAPConfiguration(
      networkSSID, networkPasskey, securityMode);
      this.wifiManager.setWifiEnabled(true);
      if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
      wifiConfiguration.SSID = networkSSID;
      // int pri = 99;
      //wifiConfiguration.priority = wifiConfiguration.priority + 1;
      } else {
      wifiConfiguration.SSID = "\"" + networkSSID + "\"";
      wifiConfiguration.priority = 40;
      }
      while(!this.wifiManager.pingSupplicant())
      {
      Thread.sleep(1000);
      }
      res = this.wifiManager.addNetwork(wifiConfiguration);
      Log.i("WIFI_Connect", "# addNetwork returned " + res);
      if (res == -1) {
      // Get existed network id if it is already added to WiFi network
      this.wifiManager.updateNetwork(wifiConfiguration);
      res = getExistingNetworkId(networkSSID);
      Log.d("WIFI_Connect", "getExistingNetworkId: " + res);
      }
      this.wifiManager.disconnect();
      this.wifiManager.enableNetwork(res, true);
      //this.wifiManager.saveConfiguration();
      this.wifiManager.reconnect();
      return res;
      }catch(Exception ex)
      {
      Log.i("", "AddDynamicWifi--savewifi--Exception--" + ex);
      return 1;
      }
      }
      }
       
      return -1;
       
       
      private WifiConfiguration createAPConfiguration(String networkSSID,
      String networkPass, String capabilities) {
      this.wifiConfig.allowedKeyManagement.clear();
      WifiConfiguration wifiConfiguration = new WifiConfiguration();
      wifiConfiguration.allowedKeyManagement.clear();
      wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
      //wifiConfiguration.priority = 40;
      wifiConfiguration.SSID = String.format("\"%s\"",
      new Object[] { networkSSID });
       
      Log.i("networkSSID", "=======" + wifiConfiguration.SSID);
       
      if (capabilities.toUpperCase().contains("WEP")) {
      Log.i("rht", "Configuring WEP");
      wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.RSN);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.WPA);
      wifiConfiguration.allowedAuthAlgorithms
      .set(WifiConfiguration.AuthAlgorithm.OPEN);
      wifiConfiguration.allowedAuthAlgorithms
      .set(WifiConfiguration.AuthAlgorithm.SHARED);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.CCMP);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.TKIP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP40);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP104);
       
      /* if (networkPass.matches("^[0-9a-fA-F]+$")) {
      wifiConfiguration.wepKeys[0] = networkPass;
      } else {
      wifiConfiguration.wepKeys[0] = "\"".concat(networkPass).concat(
      "\"");
      }*/
      wifiConfiguration.wepKeys[0] = String.format("\"%s\"",
      new Object[] { networkPass });
      Log.i("networkSSID", "=======" + wifiConfiguration.wepKeys[0]);
      wifiConfiguration.wepTxKeyIndex = 0;
       
      } else if (capabilities.toUpperCase().contains("WPA")) {
      Log.i("rht", "Configuring WPA");
      wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.WPA);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.WPA);
      wifiConfiguration.allowedAuthAlgorithms
      .set(WifiConfiguration.AuthAlgorithm.OPEN);
      wifiConfiguration.allowedKeyManagement
      .set(WifiConfiguration.KeyMgmt.WPA_PSK);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.CCMP);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.TKIP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP40);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP104);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.CCMP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.TKIP);
      wifiConfiguration.preSharedKey = String.format("\"%s\"",
      new Object[] { networkPass });
      Log.i("network password WPA", "=======" + wifiConfiguration.preSharedKey);
      //wifiConfiguration.preSharedKey = "\"" + networkPass + "\"";
       
      } else if (capabilities.toUpperCase().contains("PSK")) {
      Log.i("rht", "Configuring PSK");
      wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
      wifiConfiguration.preSharedKey = String.format("\"%s\"",
      new Object[] { networkPass });
      Log.i("network password PSK", "=======" + wifiConfiguration.preSharedKey);
      wifiConfiguration.hiddenSSID = true;
      wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.TKIP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.CCMP);
      wifiConfiguration.allowedKeyManagement
      .set(WifiConfiguration.KeyMgmt.WPA_PSK);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.TKIP);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.CCMP);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.RSN);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.WPA);
       
      } else {
       
      Log.i("rht", "Configuring OPEN network");
      wifiConfiguration.allowedKeyManagement
      .set(WifiConfiguration.KeyMgmt.NONE);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.RSN);
      wifiConfiguration.allowedProtocols
      .set(WifiConfiguration.Protocol.WPA);
      wifiConfiguration.allowedAuthAlgorithms.clear();
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.CCMP);
      wifiConfiguration.allowedPairwiseCiphers
      .set(WifiConfiguration.PairwiseCipher.TKIP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP40);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.WEP104);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.CCMP);
      wifiConfiguration.allowedGroupCiphers
      .set(WifiConfiguration.GroupCipher.TKIP);
      }
       
      return wifiConfiguration;
       
      }
      
      

      Please take a look on attached zip file.

      Note Our App which is consuming this module is targeted for Titanium SDK 5.5.1.GA.

      Let me know if you need more information.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                aislam Aminul Islam (Inactive)
              • Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-6323
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration