OLD | NEW |
| (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.libadblockplus.android.settings; | |
19 | |
20 import android.net.ConnectivityManager; | |
21 import android.net.NetworkInfo; | |
22 import android.util.Log; | |
23 | |
24 import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; | |
25 import org.adblockplus.libadblockplus.android.Utils; | |
26 | |
27 public class IsAllowedConnectionCallbackImpl implements IsAllowedConnectionCallb
ack | |
28 { | |
29 private static final String TAG = Utils.getTag(IsAllowedConnectionCallbackImpl
.class); | |
30 | |
31 private ConnectivityManager manager; | |
32 | |
33 public IsAllowedConnectionCallbackImpl(ConnectivityManager manager) | |
34 { | |
35 super(); | |
36 this.manager = manager; | |
37 } | |
38 | |
39 @Override | |
40 public boolean isConnectionAllowed(String connection) | |
41 { | |
42 Log.d(TAG, "Checking connection: " + connection); | |
43 | |
44 if (connection == null) | |
45 { | |
46 // required connection type is not specified - any works | |
47 return true; | |
48 } | |
49 | |
50 NetworkInfo info = manager.getActiveNetworkInfo(); | |
51 if (info == null || !info.isConnected()) | |
52 { | |
53 // not connected | |
54 return false; | |
55 } | |
56 | |
57 ConnectionType connectionType = ConnectionType.findByValue(connection); | |
58 if (connectionType == null) | |
59 { | |
60 Log.e(TAG, "Unknown connection type: " + connection); | |
61 return false; | |
62 } | |
63 | |
64 if (!connectionType.isRequiredConnection(manager)) | |
65 { | |
66 Log.w(TAG, "Current connection type is not allowed for web requests"); | |
67 return false; | |
68 } | |
69 | |
70 return true; | |
71 } | |
72 } | |
OLD | NEW |