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

Side by Side Diff: libadblockplus-android/src/org/adblockplus/libadblockplus/android/IsAllowedConnectionCallbackImpl.java

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

Powered by Google App Engine
This is Rietveld