| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 package org.adblockplus.sbrowser.contentblocker.util; | 18 package org.adblockplus.sbrowser.contentblocker.util; |
| 19 | 19 |
| 20 import org.adblockplus.adblockplussbrowser.R; | |
| 21 | |
| 20 import android.content.Context; | 22 import android.content.Context; |
| 21 import android.net.ConnectivityManager; | 23 import android.net.ConnectivityManager; |
| 22 import android.net.NetworkInfo; | 24 import android.net.NetworkInfo; |
| 23 | 25 |
| 24 public class ConnectivityUtils | 26 public class ConnectivityUtils |
| 25 { | 27 { |
| 26 public static boolean hasWifiConnection(final Context context) | 28 public static boolean hasNonMeteredConnection(final Context context) |
| 27 { | 29 { |
| 28 final ConnectivityManager connManager = (ConnectivityManager) context | 30 final ConnectivityManager connManager = (ConnectivityManager) context |
| 29 .getSystemService(Context.CONNECTIVITY_SERVICE); | 31 .getSystemService(Context.CONNECTIVITY_SERVICE); |
| 30 final NetworkInfo current = connManager.getActiveNetworkInfo(); | 32 final NetworkInfo current = connManager.getActiveNetworkInfo(); |
| 31 return current != null && current.getType() == ConnectivityManager.TYPE_WIFI ; | 33 |
|
diegocarloslima
2018/01/19 13:59:00
I think its interesting to also consider Bluetooth
jens
2018/01/19 14:32:55
Acknowledged.
| |
| 34 if (current != null && current.isConnectedOrConnecting()) | |
| 35 { | |
| 36 switch (current.getType()) | |
| 37 { | |
| 38 case ConnectivityManager.TYPE_BLUETOOTH: | |
| 39 case ConnectivityManager.TYPE_ETHERNET: | |
| 40 case ConnectivityManager.TYPE_WIFI: | |
| 41 case ConnectivityManager.TYPE_WIMAX: | |
| 42 return true; | |
| 43 default: | |
| 44 return false; | |
| 45 } | |
| 46 } | |
| 47 return false; | |
| 32 } | 48 } |
| 33 | 49 |
| 34 public static boolean hasInternetConnection(final Context context) | 50 public static boolean canUseInternet(final Context serviceContext, final boole an acceptMetered) |
|
diegocarloslima
2018/01/23 17:37:16
Small thing, to make it more generic I think that
jens
2018/01/24 09:23:05
Acknowledged.
| |
| 35 { | 51 { |
| 36 final ConnectivityManager connManager = (ConnectivityManager) context | 52 final ConnectivityManager connManager = (ConnectivityManager) serviceContext |
| 37 .getSystemService(Context.CONNECTIVITY_SERVICE); | 53 .getSystemService(Context.CONNECTIVITY_SERVICE); |
| 38 return connManager != null && connManager.getActiveNetworkInfo() != null; | 54 final NetworkInfo current = connManager.getActiveNetworkInfo(); |
|
diegocarloslima
2018/01/19 13:59:00
Seems that connManager.getActiveNetworkInfo().isCo
jens
2018/01/19 14:32:55
Acknowledged.
| |
| 55 if (current == null) | |
| 56 { | |
| 57 return false; | |
| 58 } | |
| 59 | |
| 60 if (current.isConnectedOrConnecting() && acceptMetered) | |
| 61 { | |
| 62 return true; | |
| 63 } | |
| 64 | |
| 65 final boolean wifiOnly = "1".equals(SharedPrefsUtils.getString( | |
| 66 serviceContext, R.string.key_automatic_updates , "1")); | |
| 67 | |
| 68 if (wifiOnly) | |
| 69 { | |
| 70 return hasNonMeteredConnection(serviceContext); | |
| 71 } | |
| 72 return current.isConnectedOrConnecting(); | |
| 39 } | 73 } |
| 40 } | 74 } |
| LEFT | RIGHT |