From b29e7eb000521ef805cad2562d8049bd610af2a5 Mon Sep 17 00:00:00 2001 From: Erik Duisters Date: Wed, 7 Nov 2018 18:06:46 +0100 Subject: [PATCH] Need to dynamically register broadcast receiver for ConnectivityManager.CONNECTIVITY_ACTION broadcast on API >= 24 Summary: On android versions >= 24 manifest registered broadcast receivers for ConnectivityManager.CONNECTIVITY_ACTION will not receive the broadcast, see: https://developer.android.com/reference/android/net/ConnectivityManager#CONNECTIVITY_ACTION Test Plan: Run app on phone with API > 24 without this patch and this broadcast will not be received any longer Run app on phone with API > 24 with this patch and this broadcast will be received again Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Subscribers: albertvaka, kdeconnect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D16738 --- src/org/kde/kdeconnect/BackgroundService.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/kde/kdeconnect/BackgroundService.java b/src/org/kde/kdeconnect/BackgroundService.java index 0b0b83bd..07bbec2f 100644 --- a/src/org/kde/kdeconnect/BackgroundService.java +++ b/src/org/kde/kdeconnect/BackgroundService.java @@ -28,6 +28,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; +import android.net.ConnectivityManager; import android.os.Binder; import android.os.Build; import android.os.IBinder; @@ -37,7 +38,6 @@ import android.util.Log; import org.kde.kdeconnect.Backends.BaseLink; import org.kde.kdeconnect.Backends.BaseLinkProvider; -//import org.kde.kdeconnect.Backends.BluetoothBackend.BluetoothLinkProvider; import org.kde.kdeconnect.Backends.LanBackend.LanLinkProvider; import org.kde.kdeconnect.Helpers.NotificationHelper; import org.kde.kdeconnect.Helpers.SecurityHelpers.RsaHelper; @@ -53,6 +53,8 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +//import org.kde.kdeconnect.Backends.BluetoothBackend.BluetoothLinkProvider; + public class BackgroundService extends Service { private static final int FOREGROUND_NOTIFICATION_ID = 1; @@ -273,6 +275,10 @@ public class BackgroundService extends Service { // Register screen on listener IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); + // See: https://developer.android.com/reference/android/net/ConnectivityManager.html#CONNECTIVITY_ACTION + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); + } registerReceiver(new KdeConnectBroadcastReceiver(), filter); Log.i("KDE/BackgroundService", "Service not started yet, initializing...");