From cfac1d3a61bc6b3430ebfd287b69693070539558 Mon Sep 17 00:00:00 2001 From: Martin Carpella Date: Tue, 26 Apr 2016 20:01:50 +0200 Subject: [PATCH] Fix checks for intent actions (fixes #625) --- .../syncthingandroid/test/syncthing/NetworkReceiverTest.java | 3 ++- .../nutomic/syncthingandroid/syncthing/BatteryReceiver.java | 4 ++++ .../nutomic/syncthingandroid/syncthing/NetworkReceiver.java | 3 +-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java index 65c532e4..7d3c90ec 100644 --- a/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java +++ b/src/androidTest/java/com/nutomic/syncthingandroid/test/syncthing/NetworkReceiverTest.java @@ -1,6 +1,7 @@ package com.nutomic.syncthingandroid.test.syncthing; import android.content.Intent; +import android.net.ConnectivityManager; import android.preference.PreferenceManager; import android.test.AndroidTestCase; import android.test.suitebuilder.annotation.MediumTest; @@ -40,7 +41,7 @@ public class NetworkReceiverTest extends AndroidTestCase { .edit() .putBoolean(SyncthingService.PREF_ALWAYS_RUN_IN_BACKGROUND, true) .commit(); - mReceiver.onReceive(mContext, new Intent(Intent.ACTION_POWER_CONNECTED)); + mReceiver.onReceive(mContext, new Intent(ConnectivityManager.CONNECTIVITY_ACTION)); assertEquals(1, mContext.getReceivedIntents().size()); Intent receivedIntent = mContext.getReceivedIntents().get(0); diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/BatteryReceiver.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/BatteryReceiver.java index c1f7ad3f..f3f76589 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/BatteryReceiver.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/BatteryReceiver.java @@ -14,6 +14,10 @@ public class BatteryReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { + if (!Intent.ACTION_POWER_CONNECTED.equals(intent.getAction()) + && !Intent.ACTION_POWER_DISCONNECTED.equals(intent.getAction())) + return; + if (!SyncthingService.alwaysRunInBackground(context)) return; diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java index bca450f0..121c6bd0 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/NetworkReceiver.java @@ -16,8 +16,7 @@ public class NetworkReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { - if (!intent.getAction().equals(Intent.ACTION_POWER_CONNECTED) && - !intent.getAction().equals(Intent.ACTION_POWER_DISCONNECTED)) + if (!ConnectivityManager.CONNECTIVITY_ACTION.equals(intent.getAction())) return; if (!SyncthingService.alwaysRunInBackground(context))