Index: libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/IsAllowedConnectionCallbackImpl.java |
diff --git a/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/IsAllowedConnectionCallbackImpl.java b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/IsAllowedConnectionCallbackImpl.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5a709d8825aa639d72cdb5973a834be148e0d7d7 |
--- /dev/null |
+++ b/libadblockplus-android-settings/src/org/adblockplus/libadblockplus/android/settings/IsAllowedConnectionCallbackImpl.java |
@@ -0,0 +1,73 @@ |
+/* |
+ * This file is part of Adblock Plus <https://adblockplus.org/>, |
+ * Copyright (C) 2006-2016 Eyeo GmbH |
+ * |
+ * Adblock Plus is free software: you can redistribute it and/or modify |
+ * it under the terms of the GNU General Public License version 3 as |
+ * published by the Free Software Foundation. |
+ * |
+ * Adblock Plus is distributed in the hope that it will be useful, |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
+ * GNU General Public License for more details. |
+ * |
+ * You should have received a copy of the GNU General Public License |
+ * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
+ */ |
+ |
+package org.adblockplus.libadblockplus.android.settings; |
+ |
+import android.content.Context; |
+import android.net.ConnectivityManager; |
+import android.net.NetworkInfo; |
+import android.util.Log; |
+ |
+import org.adblockplus.libadblockplus.IsAllowedConnectionCallback; |
+import org.adblockplus.libadblockplus.android.Utils; |
+ |
+public class IsAllowedConnectionCallbackImpl extends IsAllowedConnectionCallback |
+{ |
+ private static final String TAG = Utils.getTag(IsAllowedConnectionCallbackImpl.class); |
+ |
+ private ConnectivityManager manager; |
+ |
+ public IsAllowedConnectionCallbackImpl(Context context) |
+ { |
+ super(); |
+ this.manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); |
+ } |
+ |
+ @Override |
+ public boolean isConnectionAllowed(String connection) |
+ { |
+ Log.d(TAG, "Checking connection: " + connection); |
+ |
+ if (connection == null) |
+ { |
+ // required connection type is not specified - any works |
+ return true; |
+ } |
+ |
+ NetworkInfo info = manager.getActiveNetworkInfo(); |
+ if (info == null || !info.isConnected()) |
+ { |
+ // not connected |
+ return false; |
+ } |
+ |
+ ConnectionType connectionType = ConnectionType.findByValue(connection); |
+ if (connectionType == null) |
+ { |
+ Log.e(TAG, "Unknown connection type: " + connection); |
+ return false; |
+ } |
+ |
+ if (!connectionType.getChecker().isRequiredConnection(manager)) |
+ { |
+ Log.w(TAG, "Current connection type is not allowed for subscription updates"); |
+ return false; |
+ } |
+ |
+ return true; |
+ } |
+} |