OSDN Git Service

Check for network connectivity before attempting to check for updates
authorChainsDD <chainsdd@gmail.com>
Tue, 24 Aug 2010 22:24:55 +0000 (17:24 -0500)
committerChainsDD <chainsdd@gmail.com>
Tue, 24 Aug 2010 22:24:55 +0000 (17:24 -0500)
AndroidManifest.xml
res/values/strings.xml
src/com/noshufou/android/su/Updater.java

index a3dbd29..16733e5 100644 (file)
@@ -54,6 +54,7 @@
 
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET" />
+       <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        
     <uses-permission android:name="com.noshufou.android.su.RESPOND" />
     
index 386bebd..0080962 100644 (file)
@@ -16,6 +16,7 @@
     <string name="su_not_updated">An error occurred and su was not updated. A zip file (su-2.3.1-bin-signed.zip) has been placed on your sdcard, please reboot into recovery mode and flash it to update your su binary.</string>
     <string name="su_up_to_date">su is up to date</string>
     <string name="checking">Checking...</string>
+    <string name="no_connection">No network connection. Could not check for updates</string>
     
     <string name="tab_apps">Apps</string>
     <string name="tab_log">Log</string>
index 6f4a18d..e8f7422 100644 (file)
@@ -20,6 +20,8 @@ import org.json.JSONObject;
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.net.ConnectivityManager;
+import android.net.NetworkInfo;
 import android.os.AsyncTask;
 import android.os.Environment;
 import android.os.Build.VERSION;
@@ -40,8 +42,15 @@ public class Updater {
     }
     
     public void doUpdate() {
-        // Get the process started, it all goes from here.
-        new DownloadFileTask().execute("http://dl.dropbox.com/u/6408470/Superuser/manifest.json");
+        ConnectivityManager cm =
+                (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
+        if (cm.getActiveNetworkInfo() == null
+                || cm.getActiveNetworkInfo().getState() == NetworkInfo.State.DISCONNECTED) {
+            Toast.makeText(mContext, R.string.no_connection, Toast.LENGTH_SHORT).show();
+        } else {
+            // Get the process started, it all goes from here.
+            new DownloadFileTask().execute("http://dl.dropbox.com/u/6408470/Superuser/manifest.json");
+        }
     }
 
     private void postManifest() {