Index: components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java |
diff --git a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java |
index 82edfcbf0e9839dd7bf565803efd15d5df77bcfb..5d908c90e4d7b5f978691cffd443c32a26898717 100644 |
--- a/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java |
+++ b/components/invalidation/impl/android/java/src/org/chromium/components/invalidation/InvalidationClientService.java |
@@ -22,6 +22,7 @@ import com.google.ipc.invalidation.external.client.types.ObjectId; |
import com.google.protos.ipc.invalidation.Types.ClientType; |
import org.chromium.base.ApplicationStatus; |
+import org.chromium.base.BuildInfo; |
import org.chromium.base.CollectionUtil; |
import org.chromium.base.ContextUtils; |
import org.chromium.base.Log; |
@@ -317,12 +318,21 @@ public class InvalidationClientService extends AndroidListener { |
private void startClient() { |
byte[] clientName = InvalidationClientNameProvider.get().getInvalidatorClientName(); |
Intent startIntent = AndroidListener.createStartIntent(this, CLIENT_TYPE, clientName); |
+ |
+ if (shouldRestrictBackgroundServices()) { |
+ Log.e(TAG, "Failed to start client"); |
+ return; |
+ } |
startService(startIntent); |
setIsClientStarted(true); |
} |
/** Stops the notification client. */ |
private void stopClient() { |
+ if (shouldRestrictBackgroundServices()) { |
+ Log.e(TAG, "Failed to stop client"); |
+ return; |
+ } |
startService(AndroidListener.createStopIntent(this)); |
setIsClientStarted(false); |
setClientId(null); |
@@ -540,4 +550,9 @@ public class InvalidationClientService extends AndroidListener { |
private static void setIsClientStarted(boolean isStarted) { |
sIsClientStarted = isStarted; |
} |
+ |
+ private boolean shouldRestrictBackgroundServices() { |
+ // Restricts the use of background services when not in foreground. See crbug.com/680812. |
+ return BuildInfo.isGreaterThanN() && !isChromeInForeground(); |
Nicolas Zea
2017/03/30 18:39:35
Looks like this will actually return true when the
Khushal
2017/03/30 19:13:16
This looks like an error. It should be isAtLeastO.
|
+ } |
} |