[SCM] Multi-format 1D/2D barcode image processing library branch, upstream, updated. 24d4480bc48cf9eabf7b2bd2f528248b0e458809

vikrama vikrama at 59b500cc-1b3d-0410-9834-0bbf25fbcc57
Wed Aug 4 01:32:27 UTC 2010


The following commit has been merged in the upstream branch:
commit 01bfbf2e7e85ce75a659913b2f90b155078d4d91
Author: vikrama <vikrama at 59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Date:   Fri Jul 9 05:49:42 2010 +0000

    Some error checking put in. When a new network is created and the
    connection fails, an alert message is displayed, and connection
    attempts cease.  Retrying with a correct barcode works.  Not perfect
    yet, but in my testing I have found this version much better than the
    previous setup: at least errors are detected and the user is informed.
    
    
    
    git-svn-id: http://zxing.googlecode.com/svn/trunk@1470 59b500cc-1b3d-0410-9834-0bbf25fbcc57

diff --git a/android/res/values-ar/strings.xml b/android/res/values-ar/strings.xml
index ef8a716..cdd751b 100644
--- a/android/res/values-ar/strings.xml
+++ b/android/res/values-ar/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">شبكة نوع غير صحيح</string>
   <string name="wifi_ssid_label">اسم الشبكة</string>
   <string name="wifi_type_label">نوع</string>
+  <string name="wifi_connect_failed">فشل شبكة الاتصال</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-cs/strings.xml b/android/res/values-cs/strings.xml
index 0c33274..ad5eaef 100644
--- a/android/res/values-cs/strings.xml
+++ b/android/res/values-cs/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Typ sítě nesprávné</string>
   <string name="wifi_ssid_label">Jméno sítě</string>
   <string name="wifi_type_label">Typ</string>
+  <string name="wifi_connect_failed">Síťové připojení se nezdařilo</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-da/strings.xml b/android/res/values-da/strings.xml
index 2d0084e..ae4b0ec 100644
--- a/android/res/values-da/strings.xml
+++ b/android/res/values-da/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Netværk type forkert</string>
   <string name="wifi_ssid_label">Netværksnavn</string>
   <string name="wifi_type_label">Type</string>
+  <string name="wifi_connect_failed">Netværksforbindelse mislykkedes</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-de/strings.xml b/android/res/values-de/strings.xml
index 2b81626..a116320 100644
--- a/android/res/values-de/strings.xml
+++ b/android/res/values-de/strings.xml
@@ -130,4 +130,5 @@
   <string name="wifi_type_incorrect">Netzwerk-Typ nicht korrekt</string>
   <string name="wifi_ssid_label">Network Name</string>
   <string name="wifi_type_label">Typ</string>
+  <string name="wifi_connect_failed">Network Verbindung fehlgeschlagen</string>
 </resources>
diff --git a/android/res/values-es/strings.xml b/android/res/values-es/strings.xml
index 0de8733..f35c219 100644
--- a/android/res/values-es/strings.xml
+++ b/android/res/values-es/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Red de tipo incorrecto</string>
   <string name="wifi_ssid_label">Nombre de red</string>
   <string name="wifi_type_label">Tipo</string>
+  <string name="wifi_connect_failed">Conexión de red no</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-fi/strings.xml b/android/res/values-fi/strings.xml
index 5a0a533..1646b03 100644
--- a/android/res/values-fi/strings.xml
+++ b/android/res/values-fi/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Verkon tyyppi virheellinen</string>
   <string name="wifi_ssid_label">Verkon nimi</string>
   <string name="wifi_type_label">Tyyppi</string>
+  <string name="wifi_connect_failed">Verkkoyhteys ei</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-fr/strings.xml b/android/res/values-fr/strings.xml
index 4c1da33..f966823 100644
--- a/android/res/values-fr/strings.xml
+++ b/android/res/values-fr/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Réseau de type incorrect</string>
   <string name="wifi_ssid_label">Nom du réseau</string>
   <string name="wifi_type_label">Type</string>
+  <string name="wifi_connect_failed">La connexion réseau a échoué</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-hu/strings.xml b/android/res/values-hu/strings.xml
index a9168cd..65d8bd8 100644
--- a/android/res/values-hu/strings.xml
+++ b/android/res/values-hu/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Hálózati típusú hibás</string>
   <string name="wifi_ssid_label">Hálózat neve</string>
   <string name="wifi_type_label">Típusú</string>
+  <string name="wifi_connect_failed">Hálózati kapcsolat nem</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-it/strings.xml b/android/res/values-it/strings.xml
index 8a86d58..05ea4fd 100644
--- a/android/res/values-it/strings.xml
+++ b/android/res/values-it/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Tipo di rete non corretto</string>
   <string name="wifi_ssid_label">Nome di rete</string>
   <string name="wifi_type_label">Tipo</string>
+  <string name="wifi_connect_failed">La connessione di rete non riuscita</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-ja-rJP/strings.xml b/android/res/values-ja-rJP/strings.xml
index cabc6cd..c46820f 100644
--- a/android/res/values-ja-rJP/strings.xml
+++ b/android/res/values-ja-rJP/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">ネットワーク型不正</string>
   <string name="wifi_ssid_label">ネットワーク名</string>
   <string name="wifi_type_label">タイプ</string>
+  <string name="wifi_connect_failed">ネットワーク接続が失敗しました。</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-nl/strings.xml b/android/res/values-nl/strings.xml
index 4064592..3a083ee 100644
--- a/android/res/values-nl/strings.xml
+++ b/android/res/values-nl/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Netwerk soort onjuiste</string>
   <string name="wifi_ssid_label">Network Name</string>
   <string name="wifi_type_label">Type</string>
+  <string name="wifi_connect_failed">Netwerk verbinding is mislukt</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-pl/strings.xml b/android/res/values-pl/strings.xml
index 36fcb57..9ccfb0d 100644
--- a/android/res/values-pl/strings.xml
+++ b/android/res/values-pl/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Typ sieci nieprawidłowe</string>
   <string name="wifi_ssid_label">Nazwa sieci</string>
   <string name="wifi_type_label">Typ</string>
+  <string name="wifi_connect_failed">Połączenie sieciowe nie</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-pt/strings.xml b/android/res/values-pt/strings.xml
index 2729d57..24cdea1 100644
--- a/android/res/values-pt/strings.xml
+++ b/android/res/values-pt/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Rede de tipo incorreto</string>
   <string name="wifi_ssid_label">Nome da Rede</string>
   <string name="wifi_type_label">Tipo</string>
+  <string name="wifi_connect_failed">A conexão de rede não</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-ru/strings.xml b/android/res/values-ru/strings.xml
index 85045e5..1aadb72 100644
--- a/android/res/values-ru/strings.xml
+++ b/android/res/values-ru/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Тип сети неправильный</string>
   <string name="wifi_ssid_label">Имя сети</string>
   <string name="wifi_type_label">Тип</string>
+  <string name="wifi_connect_failed">Подключение к сети не удалось</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-sv/strings.xml b/android/res/values-sv/strings.xml
index 8437c6d..6608fef 100644
--- a/android/res/values-sv/strings.xml
+++ b/android/res/values-sv/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">Nätverkstyp felaktig</string>
   <string name="wifi_ssid_label">Nätverksnamn</string>
   <string name="wifi_type_label">Typ</string>
+  <string name="wifi_connect_failed">Nätverksanslutning misslyckades</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-zh-rCN/strings.xml b/android/res/values-zh-rCN/strings.xml
index ece2f94..2eed42b 100644
--- a/android/res/values-zh-rCN/strings.xml
+++ b/android/res/values-zh-rCN/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">网络类型不正确</string>
   <string name="wifi_ssid_label">网络名称</string>
   <string name="wifi_type_label">类型</string>
+  <string name="wifi_connect_failed">网络连接失败</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values-zh-rTW/strings.xml b/android/res/values-zh-rTW/strings.xml
index 2f41725..feefe43 100644
--- a/android/res/values-zh-rTW/strings.xml
+++ b/android/res/values-zh-rTW/strings.xml
@@ -129,5 +129,6 @@
   <string name="wifi_type_incorrect">網絡類型不正確</string>
   <string name="wifi_ssid_label">網絡名稱</string>
   <string name="wifi_type_label">類型</string>
+  <string name="wifi_connect_failed">網絡連接失敗</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
 </resources>
diff --git a/android/res/values/strings.xml b/android/res/values/strings.xml
index b2538f7..6245756 100755
--- a/android/res/values/strings.xml
+++ b/android/res/values/strings.xml
@@ -127,6 +127,7 @@
   <string name="wifi_modifying_network">Modifying Network</string>
   <string name="wifi_ssid_missing">Network name missing</string>
   <string name="wifi_type_incorrect">Network type incorrect</string>
+  <string name="wifi_connect_failed">Network connection failed</string>  
   <string name="wifi_ssid_label">Network Name</string>
   <string name="wifi_type_label">Type</string>
   <string name="zxing_url">http://code.google.com/p/zxing</string>
diff --git a/android/src/com/google/zxing/client/android/result/WifiResultHandler.java b/android/src/com/google/zxing/client/android/result/WifiResultHandler.java
index fa5b7ca..41dd9fd 100644
--- a/android/src/com/google/zxing/client/android/result/WifiResultHandler.java
+++ b/android/src/com/google/zxing/client/android/result/WifiResultHandler.java
@@ -17,7 +17,6 @@
 package com.google.zxing.client.android.result;
 
 import android.app.Activity;
-
 import com.google.zxing.client.android.R;
 import com.google.zxing.client.result.ParsedResult;
 import com.google.zxing.client.result.WifiParsedResult;
@@ -52,7 +51,7 @@ public final class WifiResultHandler extends ResultHandler {
   @Override
   public void handleButtonPress(int index) {
     // Get the underlying wifi config
-    WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+    final WifiParsedResult wifiResult = (WifiParsedResult) getResult();
     if (index == 0) {
       wifiConnect(wifiResult);
     }
@@ -61,7 +60,7 @@ public final class WifiResultHandler extends ResultHandler {
   // Display the name of the network and the network type to the user.
   @Override
   public CharSequence getDisplayContents() {
-    WifiParsedResult wifiResult = (WifiParsedResult) getResult();
+    final WifiParsedResult wifiResult = (WifiParsedResult) getResult();
     StringBuffer contents = new StringBuffer();
     final String wifiLabel = parent.getString(R.string.wifi_ssid_label);
     ParsedResult.maybeAppend(wifiLabel + "\n" + wifiResult.getSsid(), contents);
diff --git a/android/src/com/google/zxing/client/android/wifi/ConnectedReceiver.java b/android/src/com/google/zxing/client/android/wifi/ConnectedReceiver.java
deleted file mode 100644
index c34fa91..0000000
--- a/android/src/com/google/zxing/client/android/wifi/ConnectedReceiver.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2010 ZXing authors
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.google.zxing.client.android.wifi;
-
-import android.app.Activity;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.widget.TextView;
-
-import com.google.zxing.client.android.R;
-
-/**
- * Get a broadcast when the network is connected, and kill the activity.
- */
-final class ConnectedReceiver extends BroadcastReceiver {
-
-  private final Activity parent;
-  private final TextView statusView;
-
-  ConnectedReceiver(Activity wifiActivity, TextView statusView) {
-    this.parent = wifiActivity;
-    this.statusView = statusView;
-  }
-
-  @Override
-  public void onReceive(Context context, Intent intent) {
-    if (intent.getAction().equals(android.net.ConnectivityManager.CONNECTIVITY_ACTION)) {
-      ConnectivityManager con = (ConnectivityManager) parent.getSystemService(Context.CONNECTIVITY_SERVICE);
-      final NetworkInfo[] s = con.getAllNetworkInfo();
-      for (NetworkInfo i : s){
-        if (i.getTypeName().contentEquals("WIFI")){
-          NetworkInfo.State state = i.getState();
-          if (state == NetworkInfo.State.CONNECTED){
-            statusView.setText(R.string.wifi_connected);
-            Runnable delayKill = new Killer(parent);
-            delayKill.run();
-          }
-        }
-      }
-    }
-  }
-}
diff --git a/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java b/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java
index 4cc5c84..fe15108 100644
--- a/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java
+++ b/android/src/com/google/zxing/client/android/wifi/NetworkUtil.java
@@ -77,4 +77,4 @@ final class NetworkUtil {
     return (length == 10 || length == 26 || length == 58) && isHex(wepKey);
   }
 
-}
+}
\ No newline at end of file
diff --git a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java b/android/src/com/google/zxing/client/android/wifi/WifiActivity.java
index 391dd66..f39b732 100644
--- a/android/src/com/google/zxing/client/android/wifi/WifiActivity.java
+++ b/android/src/com/google/zxing/client/android/wifi/WifiActivity.java
@@ -33,19 +33,33 @@ import com.google.zxing.client.android.R;
 
 /**
  * A new activity showing the progress of Wifi connection
- *
- * TODO(viki): Tell the user when the network is not available here
- * TODO(viki): Incorrect password, could not connect, give an error
  * 
  * @author Vikram Aggarwal
  */
 public class WifiActivity extends Activity  {
 
   private static final String TAG = WifiActivity.class.getSimpleName();
-
   private WifiManager wifiManager;
   private TextView statusView;
-  private ConnectedReceiver connectedReceiver;
+  private WifiReceiver wifiReceiver;
+  private boolean receiverRegistered;
+  private int networkId;
+  private static int errorCount;
+  private IntentFilter mWifiStateFilter;
+
+  static {
+    errorCount = 0;
+  }
+
+  public void gotError(){
+    final int maxErrorCount = 3;
+    errorCount++;
+    Log.d(TAG, "Encountered another error.  Errorcount = " + errorCount);
+    if (errorCount > maxErrorCount){
+      errorCount = 0;
+      doError(R.string.wifi_connect_failed);
+    }
+  }
 
   public enum NetworkType {
     NETWORK_WEP, NETWORK_WPA, NETWORK_NOPASS, NETWORK_INVALID,
@@ -76,13 +90,23 @@ public class WifiActivity extends Activity  {
 
   private int doError(int resource_string) {
     statusView.setText(resource_string);
+    // Give up on the connection
+    wifiManager.disconnect();
+    if (networkId > 0) {
+      wifiManager.removeNetwork(networkId);
+      networkId = -1;
+    }
+    if (receiverRegistered) {
+      unregisterReceiver(wifiReceiver);
+      receiverRegistered = false;
+    }
     return -1;
   }
 
   private WifiConfiguration changeNetworkCommon(NetworkSetting input){
     statusView.setText(R.string.wifi_creating_network);
     Log.d(TAG, "Adding new configuration: \nSSID: " + input.getSsid() + "\nType: " + input.getNetworkType());
-    WifiConfiguration config = new WifiConfiguration();
+    final WifiConfiguration config = new WifiConfiguration();
 
     config.allowedAuthAlgorithms.clear();
     config.allowedGroupCiphers.clear();
@@ -103,11 +127,12 @@ public class WifiActivity extends Activity  {
 
   // Adding a WEP network
   private int changeNetworkWEP(NetworkSetting input) {
-    WifiConfiguration config = changeNetworkCommon(input);
-    if (NetworkUtil.isHexWepKey(input.getPassword())) {
-      config.wepKeys[0] = input.getPassword();
+    final WifiConfiguration config = changeNetworkCommon(input);
+    final String pass = input.getPassword();
+    if (NetworkUtil.isHexWepKey(pass)) {
+      config.wepKeys[0] = pass;
     } else {
-      config.wepKeys[0] = NetworkUtil.convertToQuotedString(input.getPassword());
+      config.wepKeys[0] = NetworkUtil.convertToQuotedString(pass);
     }
     config.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.SHARED);
     config.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
@@ -121,7 +146,7 @@ public class WifiActivity extends Activity  {
 
   // Adding a WPA or WPA2 network
   private int changeNetworkWPA(NetworkSetting input) {
-    WifiConfiguration config = changeNetworkCommon(input);
+    final WifiConfiguration config = changeNetworkCommon(input);
     final String pass = input.getPassword();
     // Hex passwords that are 64 bits long are not to be quoted.
     if (pass.matches("[0-9A-Fa-f]{64}")){
@@ -144,8 +169,8 @@ public class WifiActivity extends Activity  {
 
   // Adding an open, unsecured network
   private int changeNetworkUnEncrypted(NetworkSetting input){
-    WifiConfiguration config = changeNetworkCommon(input);
     Log.d(TAG, "Empty password prompting a simple account setting");
+    WifiConfiguration config = changeNetworkCommon(input);
     config.wepKeys[0] = "";
     config.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
     config.wepTxKeyIndex = 0;
@@ -158,7 +183,7 @@ public class WifiActivity extends Activity  {
    */
   private WifiConfiguration findNetworkInExistingConfig(String ssid){
     final List <WifiConfiguration> existingConfigs = wifiManager.getConfiguredNetworks();
-    for (WifiConfiguration existingConfig : existingConfigs) {
+    for (final WifiConfiguration existingConfig : existingConfigs) {
       if (existingConfig.SSID.equals(ssid)) {
         return existingConfig;
       }
@@ -182,7 +207,6 @@ public class WifiActivity extends Activity  {
     setContentView(R.layout.network);
     statusView = (TextView) findViewById(R.id.networkStatus);
 
-    // TODO(vikrama): Error checking here, to ensure ssid exists.
     NetworkType networkT;
     if (networkType.equals("WPA")) {
       networkT = NetworkType.NETWORK_WPA;
@@ -191,17 +215,25 @@ public class WifiActivity extends Activity  {
     } else if (networkType.equals("nopass")) {
      networkT = NetworkType.NETWORK_NOPASS;
     } else {
-      // Got an incorrect network type.  Give an error
       doError(R.string.wifi_type_incorrect);
       return;
     }
 
     // This is not available before onCreate
     wifiManager = (WifiManager) this.getSystemService(WIFI_SERVICE);
+    // Start WiFi, otherwise nothing will work
+    wifiManager.setWifiEnabled(true);
 
     // So we know when the network changes
-    connectedReceiver = new ConnectedReceiver(this, statusView);
-    registerReceiver(connectedReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
+    wifiReceiver = new WifiReceiver(wifiManager, this, statusView, ssid);
+
+    // The order matters!
+    mWifiStateFilter = new IntentFilter(WifiManager.WIFI_STATE_CHANGED_ACTION);
+    mWifiStateFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
+    mWifiStateFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
+    mWifiStateFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
+    registerReceiver(wifiReceiver, mWifiStateFilter);
+    receiverRegistered = true;
 
     if (password == null) {
       password = "";
@@ -211,11 +243,28 @@ public class WifiActivity extends Activity  {
     changeNetwork(setting);
   }
 
+  public void pause() {
+    if (receiverRegistered) {
+      unregisterReceiver(wifiReceiver);
+      receiverRegistered = false;
+    }
+  }
+
+  public void resume() {
+    if (wifiReceiver != null && mWifiStateFilter != null && !receiverRegistered) {
+      registerReceiver(wifiReceiver, mWifiStateFilter);
+      receiverRegistered = true;
+    }
+  }
+
   @Override
   protected void onDestroy() {
-    if (connectedReceiver != null) {
-      unregisterReceiver(connectedReceiver);
-      connectedReceiver = null;
+    if (wifiReceiver != null) {
+      if (receiverRegistered) {
+	unregisterReceiver(wifiReceiver);
+	receiverRegistered = false;
+      }
+      wifiReceiver = null;
     }
     super.onDestroy();
   }
@@ -227,18 +276,29 @@ public class WifiActivity extends Activity  {
    * @return network ID of the connected network.
    */
   private int updateNetwork(WifiConfiguration config, boolean disableOthers){
-    int networkId;
-    if (findNetworkInExistingConfig(config.SSID) == null){
+    final int FAILURE = -1;
+    WifiConfiguration found = findNetworkInExistingConfig(config.SSID);
+    wifiManager.disconnect();
+    if (found == null){
       statusView.setText(R.string.wifi_creating_network);
-      networkId = wifiManager.addNetwork(config);
     } else {
       statusView.setText(R.string.wifi_modifying_network);
-      networkId = wifiManager.updateNetwork(config);
-    }
-    if (networkId == -1 || !wifiManager.enableNetwork(networkId, disableOthers)) {
-      return -1;
+      Log.d(TAG, "Removing network " + found.networkId);
+      wifiManager.removeNetwork(found.networkId);
+      wifiManager.saveConfiguration();
+     }
+    networkId = wifiManager.addNetwork(config);
+    Log.d(TAG, "Inserted/Modified network " + networkId);
+    if (networkId < 0)
+      return FAILURE;
+
+    // Try to disable the current network and start a new one.
+    if (!wifiManager.enableNetwork(networkId, disableOthers)) {
+      networkId = -1;
+      return FAILURE;
     }
-    wifiManager.saveConfiguration();
+    errorCount = 0;
+    wifiManager.reassociate();
     return networkId;
   }
 }
\ No newline at end of file

-- 
Multi-format 1D/2D barcode image processing library



More information about the Pkg-google-commits mailing list