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

Delta Between Two Patch Sets: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/ConnectionType.java

Issue 29379647: Issue 4948 - add possibility to not send data depending on connection properties (Closed)
Left Patch Set: updated to 4931 code review patch set 3 and later Created March 21, 2017, 10:28 a.m.
Right Patch Set: updated dependency to binaries, updated comment for allowed connection type Created March 30, 2017, 2:12 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 Eyeo GmbH
Felix Dahlke 2017/03/24 07:37:24 2017 :)
anton 2017/03/24 09:43:11 Yes, i've left it 2016 as i will update 2016 to 20
Felix Dahlke 2017/03/27 14:18:11 Acknowledged.
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.libadblockplus.android.settings; 18 package org.adblockplus.libadblockplus.android.settings;
19 19
20 import android.net.ConnectivityManager; 20 import android.net.ConnectivityManager;
21 21
22 public enum ConnectionType { 22 public enum ConnectionType {
23 23
24 // All WiFi networks 24 // All WiFi networks
25 WIFI( 25 WIFI("wifi")
26 "wifi", 26 {
27 new ConnectionChecker() 27 @Override
28 public boolean isRequiredConnection(ConnectivityManager manager)
28 { 29 {
29 @Override 30 return manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYP E_WIFI;
30 public boolean isRequiredConnection(ConnectivityManager manager) 31 }
31 { 32 },
32 return manager.getActiveNetworkInfo().getType() == ConnectivityManager.T YPE_WIFI;
33 }
34 }),
35 33
36 // Non-metered WiFi networks 34 // Non-metered WiFi networks
37 WIFI_NON_METERED( 35 WIFI_NON_METERED("wifi_non_metered")
38 "wifi_non_metered", 36 {
39 new ConnectionChecker() 37 @Override
38 public boolean isRequiredConnection(ConnectivityManager manager)
40 { 39 {
41 @Override 40 return
42 public boolean isRequiredConnection(ConnectivityManager manager) 41 manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIF I &&
43 { 42 !manager.isActiveNetworkMetered();
44 return
45 manager.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_W IFI &&
46 !manager.isActiveNetworkMetered();
47 } 43 }
48 }), 44 },
49 45
50 // Any connection 46 // Any connection
51 ANY( 47 ANY("any")
52 "any", 48 {
53 new ConnectionChecker() 49 @Override
50 public boolean isRequiredConnection(ConnectivityManager manager)
54 { 51 {
55 @Override 52 return true;
56 public boolean isRequiredConnection(ConnectivityManager manager) 53 }
57 { 54 };
58 return true;
59 }
60 });
61 55
62 private String value; 56 private String value;
63 private ConnectionChecker checker;
64 57
65 public String getValue() 58 public String getValue()
66 { 59 {
67 return value; 60 return value;
68 } 61 }
69 62
70 public ConnectionChecker getChecker() 63 // check if current device connection type is equal to this concrete connectio n type
71 { 64 public abstract boolean isRequiredConnection(ConnectivityManager manager);
72 return checker;
73 }
74 65
75 ConnectionType(String value, ConnectionChecker checker) 66 ConnectionType(String value)
76 { 67 {
77 this.value = value; 68 this.value = value;
78 this.checker = checker;
79 }
80
81 interface ConnectionChecker
82 {
83 boolean isRequiredConnection(ConnectivityManager manager);
84 } 69 }
85 70
86 public static ConnectionType findByValue(String value) 71 public static ConnectionType findByValue(String value)
87 { 72 {
88 if (value == null) 73 if (value == null)
89 { 74 {
90 return null; 75 return null;
91 } 76 }
92 77
93 for (ConnectionType eachConnectionType : ConnectionType.values()) 78 for (ConnectionType eachConnectionType : ConnectionType.values())
94 { 79 {
95 if (eachConnectionType.getValue().equals(value)) 80 if (eachConnectionType.getValue().equals(value))
96 { 81 {
97 return eachConnectionType; 82 return eachConnectionType;
98 } 83 }
99 } 84 }
100 85
101 // not found 86 // not found
102 return null; 87 return null;
103 } 88 }
104 } 89 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld