Browse Source

delay instant upload when metered wifi is used

tobiasKaminsky 8 years ago
parent
commit
c5159e9246

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

@@ -140,7 +140,7 @@ public class ConnectivityActionReceiver extends BroadcastReceiver {
                     networkType == ConnectivityManager.TYPE_WIFI;
 
             if (couldBeWifiAction) {
-                if (ConnectivityUtils.isAppConnectedViaWiFi(context)) {
+                if (ConnectivityUtils.isAppConnectedViaUnmeteredWiFi(context)) {
                     Log_OC.d(TAG, "WiFi connected");
                     wifiConnected(context);
                 } else {

+ 1 - 1
src/com/owncloud/android/operations/UploadFileOperation.java

@@ -464,7 +464,7 @@ public class UploadFileOperation extends SyncOperation {
         );
         return (
             (delayInstantPicture || delayInstantVideo) &&
-            !ConnectivityUtils.isAppConnectedViaWiFi(mContext)
+            !ConnectivityUtils.isAppConnectedViaUnmeteredWiFi(mContext)
         );
     }
 

+ 4 - 2
src/com/owncloud/android/utils/ConnectivityUtils.java

@@ -22,6 +22,7 @@ package com.owncloud.android.utils;
 import android.content.Context;
 import android.net.ConnectivityManager;
 import android.net.NetworkInfo;
+import android.support.v4.net.ConnectivityManagerCompat;
 
 import com.owncloud.android.lib.common.utils.Log_OC;
 
@@ -29,12 +30,13 @@ public class ConnectivityUtils {
 
     private final static String TAG = ConnectivityUtils.class.getName();
 
-    public static boolean isAppConnectedViaWiFi(Context context) {
+    public static boolean isAppConnectedViaUnmeteredWiFi(Context context) {
         ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
         boolean result =
                 cm != null && cm.getActiveNetworkInfo() != null
                 && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
-                && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED;
+                && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED
+                && !ConnectivityManagerCompat.isActiveNetworkMetered(cm);
         Log_OC.d(TAG, "is AppConnectedViaWifi returns " + result);
         return result;
     }