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/IsAllowedConnectionCallbackImpl.java

Issue 29671734: Issue 6265 - Create shared AdblockEngine instance in AdblockWebView in background (Closed)
Left Patch Set: addressed Diego's comments Created Jan. 19, 2018, 12:23 p.m.
Right Patch Set: Sergey's comments Created Jan. 22, 2018, 6:19 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
LEFTRIGHT
(no file at all)
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 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld