ソースを参照

Reconnect cancellation of uploads when Wifi is lost to interrupt only-wifi instant uploads

David A. Velasco 9 年 前
コミット
366a1f7c51

+ 0 - 3
AndroidManifest.xml

@@ -194,9 +194,6 @@
 
                 <data android:mimeType="video/*" />
             </intent-filter>
-            <intent-filter>
-                <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
-            </intent-filter>
         </receiver>
         <receiver android:name=".files.BootupBroadcastReceiver" >
             <intent-filter>

+ 1 - 1
src/com/owncloud/android/files/InstantUploadBroadcastReceiver.java

@@ -64,7 +64,7 @@ public class InstantUploadBroadcastReceiver extends BroadcastReceiver {
             handleNewVideoAction(context, intent);
             Log_OC.d(TAG, "OFFICIAL processed: android.hardware.action.NEW_VIDEO");
         } else {
-            Log_OC.e(TAG, "Incorrect intent sent: " + intent.getAction());
+            Log_OC.e(TAG, "Incorrect intent received: " + intent.getAction());
         }
     }
 

+ 39 - 7
src/com/owncloud/android/files/services/ConnectivityActionReceiver.java

@@ -31,6 +31,7 @@ import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
 import android.net.wifi.WifiManager;
 import android.os.Bundle;
+import android.preference.PreferenceManager;
 
 import com.owncloud.android.authentication.AccountUtils;
 import com.owncloud.android.lib.common.utils.Log_OC;
@@ -65,7 +66,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
 
         
         /**
-         * Just checking for State.CONNECTED will is not good enough, as it ends here multiple times.
+         * Just checking for State.CONNECTED will be not good enough, as it ends here multiple times.
          * Work around from:
          * http://stackoverflow.com/
          * questions/17287178/connectivitymanager-getactivenetworkinfo-returning-true-when-internet-is-off
@@ -75,7 +76,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
                 intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
             if(networkInfo.isConnected()) {
                 Log_OC.d(TAG, "Wifi is connected: " + String.valueOf(networkInfo));
-//                wifiConnected(context);
+                wifiConnected(context);
             }
         } else if(intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
             ConnectivityManager cm =
@@ -90,15 +91,31 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
         
     }
 
-//    private void wifiConnected(Context context) {
-//        Log_OC.d(TAG, "FileUploader.retry() called by onReceive()");
-//      FileUploader.retry(context);
-//    }
+    private void wifiConnected(Context context) {
+        //Log_OC.d(TAG, "FileUploader.retry() called by onReceive()");
+        //FileUploader.retry(context);
+        Log_OC.w(TAG, "Automatic retry of uploads on WiFi recovery is temporarily disabled due to dev in progress");
+    }
 
     private void wifiDisconnected(Context context) {
-        
+        boolean instantPictureWiFiOnly = instantPictureUploadViaWiFiOnly(context);
+        boolean instantVideoWiFiOnly = instantVideoUploadViaWiFiOnly(context);
+        if (instantPictureWiFiOnly || instantVideoWiFiOnly) {
+            Account account = AccountUtils.getCurrentOwnCloudAccount(context);
+            if (account == null) {
+                Log_OC.w(TAG, "No account found for instant upload, aborting");
+                return;
+            }
+
+            Intent i = new Intent(context, FileUploader.class);
+            i.putExtra(FileUploader.KEY_ACCOUNT, account);
+            i.putExtra(FileUploader.KEY_CANCEL_ALL, true);
+            // TODO improve with extra options to cancel selected uploads: instant_pictures, instant_videos, ...
+            context.startService(i);
+        }
     }
 
+
     static public void enableActionReceiver(Context context) {
         PackageManager pm = context.getPackageManager();
         ComponentName compName = new ComponentName(context.getApplicationContext(), ConnectivityActionReceiver.class);
@@ -113,4 +130,19 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
                 PackageManager.DONT_KILL_APP);
     }
 
+
+    private static boolean instantPictureUploadViaWiFiOnly(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_upload_on_wifi",
+                false
+        );
+    }
+
+    private static boolean instantVideoUploadViaWiFiOnly(Context context) {
+        return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
+                "instant_video_upload_on_wifi",
+                false
+        );
+    }
+
 }