Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: adblockplussbrowser/src/main/java/org/adblockplus/sbrowser/contentblocker/util/ConnectivityUtils.java

Issue 29673565: Issue 6066 - Implement 'force update' functionality for subscriptions (Closed)
Patch Set: Fixes Created Jan. 23, 2018, 3:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-present eyeo GmbH
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
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/>.
16 */
17
18 package org.adblockplus.sbrowser.contentblocker.util;
19
20 import org.adblockplus.adblockplussbrowser.R;
21
22 import android.content.Context;
23 import android.net.ConnectivityManager;
24 import android.net.NetworkInfo;
25
26 public class ConnectivityUtils
27 {
28 public static boolean hasNonMeteredConnection(final Context context)
29 {
30 final ConnectivityManager connManager = (ConnectivityManager) context
31 .getSystemService(Context.CONNECTIVITY_SERVICE);
32 final NetworkInfo current = connManager.getActiveNetworkInfo();
33
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;
48 }
49
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.
51 {
52 final ConnectivityManager connManager = (ConnectivityManager) serviceContext
53 .getSystemService(Context.CONNECTIVITY_SERVICE);
54 final NetworkInfo current = connManager.getActiveNetworkInfo();
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();
73 }
74 }
OLDNEW

Powered by Google App Engine
This is Rietveld