Browse Source

Explicit default values for network timeouts; fixed null pointer in message broadcasted when a download can't finish

David A. Velasco 12 years ago
parent
commit
9d3208ea03

+ 4 - 6
src/eu/alefzero/owncloud/files/services/FileDownloader.java

@@ -164,16 +164,14 @@ public class FileDownloader extends Service implements OnDatatransferProgressLis
             }
         }
         
-        if (!download_result) {
-            tmpFile.delete();
-        }
-        
         mNotificationMngr.cancel(1);
         Intent end = new Intent(DOWNLOAD_FINISH_MESSAGE);
-        end.putExtra(EXTRA_REMOTE_PATH, mRemotePath);
-        end.putExtra(EXTRA_FILE_PATH, newFile.getAbsolutePath());
         end.putExtra(EXTRA_DOWNLOAD_RESULT, download_result);
         end.putExtra(ACCOUNT_NAME, mAccount.name);
+        end.putExtra(EXTRA_REMOTE_PATH, mRemotePath);
+        if (download_result) {
+            end.putExtra(EXTRA_FILE_PATH, newFile.getAbsolutePath());
+        }
         sendBroadcast(end);
 
         if (download_result) {

+ 20 - 1
src/eu/alefzero/webdav/WebdavClient.java

@@ -57,6 +57,13 @@ public class WebdavClient extends HttpClient {
     private Credentials mCredentials;
     final private static String TAG = "WebdavClient";
     private static final String USER_AGENT = "Android-ownCloud";
+    
+    /** Default timeout for waiting data from the server: 10 seconds */
+    public static final int DEFAULT_DATA_TIMEOUT = 10000;
+    
+    /** Default timeout for establishing a connection: infinite */
+    public static final int DEFAULT_CONNECTION_TIMEOUT = 0;
+    
     private OnDatatransferProgressListener mDataTransferListener;
     static private MultiThreadedHttpConnectionManager mConnManager = null;
     
@@ -76,6 +83,8 @@ public class WebdavClient extends HttpClient {
      * @return
      */
     public WebdavClient (Account account, Context context) {
+        setDefaultTimeouts();
+        
         OwnCloudVersion ownCloudVersion = new OwnCloudVersion(AccountManager.get(context).getUserData(account,
                 AccountAuthenticator.KEY_OC_VERSION));
         String baseUrl = AccountManager.get(context).getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL);
@@ -84,13 +93,15 @@ public class WebdavClient extends HttpClient {
         String password = AccountManager.get(context).getPassword(account);
         
         mUri = Uri.parse(baseUrl + webDavPath);
-Log.e("ASD", ""+username);
+        Log.e("ASD", ""+username);
         setCredentials(username, password);
     }
     
     public WebdavClient() {
         super(getMultiThreadedConnManager());
         
+        setDefaultTimeouts();
+        
         getParams().setParameter(HttpMethodParams.USER_AGENT, USER_AGENT);
         getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
         allowSelfsignedCertificates();
@@ -107,6 +118,14 @@ Log.e("ASD", ""+username);
             mCredentials = new UsernamePasswordCredentials(username, password);
         return mCredentials;
     }
+    
+    /**
+     * Sets the connection and wait-for-data timeouts to be applied by default.
+     */
+    private void setDefaultTimeouts() {
+        getParams().setSoTimeout(DEFAULT_DATA_TIMEOUT);
+        getHttpConnectionManager().getParams().setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
+    }
 
     public void allowSelfsignedCertificates() {
         // https