Add logging to track connectivity as seen from the Download Manager.
Jean-Baptiste Queru [Mon, 21 Sep 2009 01:51:28 +0000 (18:51 -0700)]
This is enabled by a separate build-time constant, so that it can
be turned on for everyone without having to use a system property.

BUG=2055624

src/com/android/providers/downloads/Constants.java
src/com/android/providers/downloads/DownloadReceiver.java
src/com/android/providers/downloads/DownloadThread.java

index 993ed78..cae5370 100644 (file)
@@ -140,6 +140,9 @@ public class Constants {
      */
     public static final int RETRY_FIRST_DELAY = 30;
 
+    /** Enable separate connectivity logging */
+    static final boolean LOGX = true;
+
     /** Enable verbose logging - use with "setprop log.tag.DownloadManager VERBOSE" */
     private static final boolean LOCAL_LOGV = true;
     public static final boolean LOGV = Config.LOGV
index c0ccad3..74f2931 100644 (file)
@@ -51,12 +51,22 @@ public class DownloadReceiver extends BroadcastReceiver {
             NetworkInfo info = (NetworkInfo)
                     intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
             if (info != null && info.isConnected()) {
+                if (Constants.LOGX) {
+                    Log.i(Constants.TAG, "Broadcast: Network Up");
+                }
                 context.startService(new Intent(context, DownloadService.class));
+            } else {
+                if (Constants.LOGX) {
+                    Log.i(Constants.TAG, "Broadcast: Network Down");
+                }
             }
         } else if (intent.getAction().equals(Constants.ACTION_RETRY)) {
             if (Constants.LOGVV) {
                 Log.v(Constants.TAG, "Receiver retry");
             }
+            if (Constants.LOGX) {
+                Log.i(Constants.TAG, "Broadcast: Timed Retry");
+            }
             context.startService(new Intent(context, DownloadService.class));
         } else if (intent.getAction().equals(Constants.ACTION_OPEN)
                 || intent.getAction().equals(Constants.ACTION_LIST)) {
index 7703d14..cee34cf 100644 (file)
@@ -201,6 +201,13 @@ http_request_loop:
 
                 HttpResponse response;
                 try {
+                    if (Constants.LOGX) {
+                        if (Helpers.isNetworkAvailable(mContext)) {
+                            Log.i(Constants.TAG, "Starting, Net Up");
+                        } else {
+                            Log.i(Constants.TAG, "Starting, Net Down");
+                        }
+                    }
                     response = client.execute(request);
                 } catch (IllegalArgumentException ex) {
                     if (Constants.LOGV) {
@@ -214,6 +221,13 @@ http_request_loop:
                     request.abort();
                     break http_request_loop;
                 } catch (IOException ex) {
+                    if (Constants.LOGX) {
+                        if (Helpers.isNetworkAvailable(mContext)) {
+                            Log.i(Constants.TAG, "Execute Failed, Net Up");
+                        } else {
+                            Log.i(Constants.TAG, "Execute Failed, Net Down");
+                        }
+                    }
                     if (!Helpers.isNetworkAvailable(mContext)) {
                         finalStatus = Downloads.STATUS_RUNNING_PAUSED;
                     } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) {
@@ -442,6 +456,13 @@ http_request_loop:
                     try {
                         entityStream = response.getEntity().getContent();
                     } catch (IOException ex) {
+                        if (Constants.LOGX) {
+                            if (Helpers.isNetworkAvailable(mContext)) {
+                                Log.i(Constants.TAG, "GetContent Failed, Net Up");
+                            } else {
+                                Log.i(Constants.TAG, "GetContent Failed, Net Down");
+                            }
+                        }
                         if (!Helpers.isNetworkAvailable(mContext)) {
                             finalStatus = Downloads.STATUS_RUNNING_PAUSED;
                         } else if (mInfo.mNumFailed < Constants.MAX_RETRIES) {
@@ -468,6 +489,13 @@ http_request_loop:
                         try {
                             bytesRead = entityStream.read(data);
                         } catch (IOException ex) {
+                            if (Constants.LOGX) {
+                                if (Helpers.isNetworkAvailable(mContext)) {
+                                    Log.i(Constants.TAG, "Read Failed, Net Up");
+                                } else {
+                                    Log.i(Constants.TAG, "Read Failed, Net Down");
+                                }
+                            }
                             ContentValues values = new ContentValues();
                             values.put(Downloads.COLUMN_CURRENT_BYTES, bytesSoFar);
                             mContext.getContentResolver().update(contentUri, values, null, null);