diff --git a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java index d5deafc38bdb9fa75b270803924e78793ece4973..1b9362224bce245b68161c0753259c77698ce439 100644 --- a/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java +++ b/app/src/main/java/foundation/e/drive/activity/AccountsActivity.java @@ -101,7 +101,7 @@ public class AccountsActivity extends AppCompatActivity { } }; - if (!CommonUtils.haveNetworkConnection(this, account)) { + if (!CommonUtils.haveNetworkConnection(this, true)) { handleNoInternetConnection(); return; } diff --git a/app/src/main/java/foundation/e/drive/services/ObserverService.java b/app/src/main/java/foundation/e/drive/services/ObserverService.java index af672a3c3cf9e1c900fe2f78205f1e8037edaf46..567dd17b85111e2199380a82ea72aa2c86e3b49a 100644 --- a/app/src/main/java/foundation/e/drive/services/ObserverService.java +++ b/app/src/main/java/foundation/e/drive/services/ObserverService.java @@ -135,8 +135,9 @@ public class ObserverService extends Service implements OnRemoteOperationListene return super.onStartCommand( intent, flags, startId ); } + final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(mAccount); //check for the case where intent has been launched by initializerService - if (!CommonUtils.haveNetworkConnection(this, mAccount)) { + if (!CommonUtils.haveNetworkConnection(this, meteredNetworkAllowed)) { Log.w(TAG, "There is no Internet connexion."); return super.onStartCommand( intent, flags, startId ); } diff --git a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java index 19073ef5e73542846f8cb76922adeaa207546a9f..b05476ac3d3793dd58b7345b2060ae580431f692 100644 --- a/app/src/main/java/foundation/e/drive/services/SynchronizationService.java +++ b/app/src/main/java/foundation/e/drive/services/SynchronizationService.java @@ -118,7 +118,8 @@ public class SynchronizationService extends Service implements OnRemoteOperation private void startWorker(int threadIndex){ if (syncedRequestQueue.isEmpty()) return; - if (!threadWorkingState[threadIndex] && CommonUtils.haveNetworkConnection(getApplicationContext(), account)) { //check if the thread corresponding to threadIndex isn't already working + final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); + if (!threadWorkingState[threadIndex] && CommonUtils.haveNetworkConnection(getApplicationContext(), meteredNetworkAllowed)) { //check if the thread corresponding to threadIndex isn't already working final SyncRequest request = this.syncedRequestQueue.poll(); //return null if deque is empty diff --git a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java index 0c1bf7f1eb389436beef6d457668542de5c33995..72484925b03e626d66e341742fafa30ca625e510 100644 --- a/app/src/main/java/foundation/e/drive/utils/CommonUtils.java +++ b/app/src/main/java/foundation/e/drive/utils/CommonUtils.java @@ -167,6 +167,15 @@ public abstract class CommonUtils { return ContentResolver.getSyncAutomatically(account, SETTINGSYNC_PROVIDER_AUTHORITY); } + /** + * Read accountManager settings + * @param account + * @return true if usage of metered connection is allowed + */ + public static boolean isMeteredNetworkAllowed(Account account){ + return ContentResolver.getSyncAutomatically(account, METERED_NETWORK_ALLOWED_AUTHORITY); + } + /** * @param context app context * @return Owncloud client instance or null @@ -216,16 +225,15 @@ public abstract class CommonUtils { * Tell if there is internet connection * * @param context Activity or service which are calling this method + * @param meteredNetworkAllowed true if service can use metered network / false either * @return True if there is connection, false either */ - public static boolean haveNetworkConnection(Context context, Account account) { + public static boolean haveNetworkConnection(Context context, boolean meteredNetworkAllowed) { Log.i(TAG, "haveNetworkConnection()"); final ConnectivityManager cm = context.getSystemService(ConnectivityManager.class); final NetworkCapabilities capabilities = cm.getNetworkCapabilities(cm.getActiveNetwork()); - final boolean meteredNetworkAllowed = ContentResolver.getSyncAutomatically(account, METERED_NETWORK_ALLOWED_AUTHORITY); - if (capabilities != null && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) && capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED) diff --git a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java index 3459551a49e82d1ab35a5418a7325c03b499d686..38ec32f06445505f260f340b9a78913bb5525db6 100644 --- a/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java +++ b/app/src/main/java/foundation/e/drive/work/CreateRemoteFolderWorker.java @@ -61,7 +61,8 @@ public class CreateRemoteFolderWorker extends Worker { return Result.failure(); } - if (!CommonUtils.haveNetworkConnection(context, account)) { + final boolean meteredNetworkAllowed = CommonUtils.isMeteredNetworkAllowed(account); + if (!CommonUtils.haveNetworkConnection(context, meteredNetworkAllowed)) { Log.e(TAG, "Can't create remote folder because there is no usable connection"); return Result.retry(); }