Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f8ae3a1 authored by Aayush Gupta's avatar Aayush Gupta
Browse files

Merge branch '5272-activity-no-network-restriction' into 'v1-oreo'

Update network checking method in commonUtils

Closes e/backlog#5272

See merge request !111
parents b19fb809 8ff33e82
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -101,7 +101,7 @@ public class AccountsActivity extends AppCompatActivity {
            }
        };

        if (!CommonUtils.haveNetworkConnection(this, account)) {
        if (!CommonUtils.haveNetworkConnection(this, true)) {
            handleNoInternetConnection();
            return;
        }
+2 −1
Original line number Diff line number Diff line
@@ -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 );
        }
+2 −1
Original line number Diff line number Diff line
@@ -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

+11 −3
Original line number Diff line number Diff line
@@ -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)
+2 −1
Original line number Diff line number Diff line
@@ -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();
        }