750 lines
36 KiB
Diff
750 lines
36 KiB
Diff
From: Wengling Chen <feiyu2817@gmail.com>
|
|
Date: Sat, 2 Nov 2019 07:56:44 +0100
|
|
Subject: Remove dependency on com.google.android.gms.gcm
|
|
|
|
It also disalbes Snippets, auto-update of offline pages and launching browser from background service.
|
|
The snippets are already disabled in native codes, this will disable it on Java level.
|
|
---
|
|
chrome/android/BUILD.gn | 3 -
|
|
.../chrome/browser/BackgroundSyncLauncher.java | 17 +----
|
|
.../chrome/browser/ChromeBackgroundService.java | 79 +------------------
|
|
.../invalidation/InvalidationController.java | 1 +
|
|
.../browser/ntp/snippets/SnippetsLauncher.java | 2 +-
|
|
.../services/gcm/ChromeGcmListenerService.java | 58 +-------------
|
|
components/background_task_scheduler/BUILD.gn | 3 -
|
|
.../BackgroundTaskGcmTaskService.java | 63 +--------------
|
|
.../BackgroundTaskSchedulerFactory.java | 6 +-
|
|
.../BackgroundTaskSchedulerGcmNetworkManager.java | 14 +---
|
|
third_party/android_deps/BUILD.gn | 15 ----
|
|
third_party/cacheinvalidation/BUILD.gn | 1 -
|
|
.../client/android2/AndroidManifestUpdatedGcm.xml | 20 -----
|
|
.../android2/channel/AndroidGcmController.java | 42 +---------
|
|
.../channel/AndroidInstanceIDListenerService.java | 13 +---
|
|
.../channel/GcmRegistrationTaskService.java | 89 +---------------------
|
|
16 files changed, 14 insertions(+), 412 deletions(-)
|
|
|
|
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
|
|
--- a/chrome/android/BUILD.gn
|
|
+++ b/chrome/android/BUILD.gn
|
|
@@ -272,7 +272,6 @@ android_library("chrome_java") {
|
|
"$google_play_services_package:google_play_services_cast_framework_java",
|
|
"$google_play_services_package:google_play_services_cast_java",
|
|
"$google_play_services_package:google_play_services_fido_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_iid_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
@@ -798,7 +797,6 @@ android_library("chrome_test_java") {
|
|
"$google_play_services_package:google_play_services_cast_framework_java",
|
|
"$google_play_services_package:google_play_services_cast_java",
|
|
"$google_play_services_package:google_play_services_fido_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_iid_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
@@ -1543,7 +1541,6 @@ android_library("browser_java_test_support") {
|
|
]
|
|
deps = [
|
|
":chrome_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"//base:base_java",
|
|
"//base:base_java_test_support",
|
|
"//chrome/android/public/profiles:java",
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncher.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncher.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/BackgroundSyncLauncher.java
|
|
@@ -41,7 +41,7 @@ public class BackgroundSyncLauncher {
|
|
* Automatic GCM use is disabled by tests, and also by this class if it is determined on
|
|
* creation that the installed Play Services library is out of date.
|
|
*/
|
|
- private static boolean sGCMEnabled = true;
|
|
+ private static boolean sGCMEnabled;
|
|
|
|
@VisibleForTesting
|
|
protected AsyncTask<Void> mLaunchBrowserIfStoppedTask;
|
|
@@ -140,20 +140,7 @@ public class BackgroundSyncLauncher {
|
|
*/
|
|
@CalledByNative
|
|
private static boolean shouldDisableBackgroundSync() {
|
|
- // Check to see if Play Services is up to date, and disable GCM if not.
|
|
- // This will not automatically set {@link sGCMEnabled} to true, in case it has been
|
|
- // disabled in tests.
|
|
- if (sGCMEnabled) {
|
|
- boolean isAvailable = true;
|
|
- if (!ExternalAuthUtils.canUseGooglePlayServices()) {
|
|
- setGCMEnabled(false);
|
|
- Log.i(TAG, "Disabling Background Sync because Play Services is not up to date.");
|
|
- isAvailable = false;
|
|
- }
|
|
- RecordHistogram.recordBooleanHistogram(
|
|
- "BackgroundSync.LaunchTask.PlayServicesAvailable", isAvailable);
|
|
- }
|
|
- return !sGCMEnabled;
|
|
+ return true;
|
|
}
|
|
|
|
@VisibleForTesting
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeBackgroundService.java
|
|
@@ -6,10 +6,6 @@ package org.chromium.chrome.browser;
|
|
|
|
import android.content.Context;
|
|
|
|
-import com.google.android.gms.gcm.GcmNetworkManager;
|
|
-import com.google.android.gms.gcm.GcmTaskService;
|
|
-import com.google.android.gms.gcm.TaskParams;
|
|
-
|
|
import org.chromium.base.Log;
|
|
import org.chromium.base.VisibleForTesting;
|
|
import org.chromium.base.library_loader.ProcessInitException;
|
|
@@ -27,67 +23,9 @@ import org.chromium.content_public.browser.UiThreadTaskTraits;
|
|
* browser needs to be launched for scheduled tasks, or in response to changing network or power
|
|
* conditions.
|
|
*/
|
|
-public class ChromeBackgroundService extends GcmTaskService {
|
|
+public class ChromeBackgroundService {
|
|
private static final String TAG = "BackgroundService";
|
|
|
|
- @Override
|
|
- @VisibleForTesting
|
|
- public int onRunTask(final TaskParams params) {
|
|
- final String taskTag = params.getTag();
|
|
- final Context context = this;
|
|
- PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
|
|
- switch (taskTag) {
|
|
- case BackgroundSyncLauncher.TASK_TAG:
|
|
- handleBackgroundSyncEvent(context, taskTag);
|
|
- break;
|
|
-
|
|
- case OfflinePageUtils.TASK_TAG:
|
|
- // Offline pages are migrating to BackgroundTaskScheduler, therefore getting
|
|
- // a task through ChromeBackgroundSerivce should cause a rescheduling using
|
|
- // the new component.
|
|
- rescheduleOfflinePages();
|
|
- break;
|
|
-
|
|
- case SnippetsLauncher.TASK_TAG_WIFI:
|
|
- case SnippetsLauncher.TASK_TAG_FALLBACK:
|
|
- handleSnippetsOnPersistentSchedulerWakeUp(context, taskTag);
|
|
- break;
|
|
-
|
|
- // This is only for tests.
|
|
- case ServiceManagerStartupUtils.TASK_TAG:
|
|
- handleServicificationStartupTask(context, taskTag);
|
|
- break;
|
|
-
|
|
- default:
|
|
- Log.i(TAG, "Unknown task tag " + taskTag);
|
|
- break;
|
|
- }
|
|
- });
|
|
-
|
|
- return GcmNetworkManager.RESULT_SUCCESS;
|
|
- }
|
|
-
|
|
- private void handleBackgroundSyncEvent(Context context, String tag) {
|
|
- if (!BackgroundSyncLauncher.hasInstance()) {
|
|
- // Start the browser. The browser's BackgroundSyncManager (for the active profile) will
|
|
- // start, check the network, and run any necessary sync events. This task runs with a
|
|
- // wake lock, but has a three minute timeout, so we need to start the browser in its
|
|
- // own task.
|
|
- // TODO(jkarlin): Protect the browser sync event with a wake lock.
|
|
- // See crbug.com/486020.
|
|
- launchBrowser(context, tag);
|
|
- }
|
|
- }
|
|
-
|
|
- private void handleSnippetsOnPersistentSchedulerWakeUp(Context context, String tag) {
|
|
- if (!SnippetsLauncher.hasInstance()) launchBrowser(context, tag);
|
|
- snippetsOnPersistentSchedulerWakeUp();
|
|
- }
|
|
-
|
|
- private void handleServicificationStartupTask(Context context, String tag) {
|
|
- launchBrowser(context, tag);
|
|
- }
|
|
-
|
|
@VisibleForTesting
|
|
protected void snippetsOnPersistentSchedulerWakeUp() {
|
|
SnippetsBridge.onPersistentSchedulerWakeUp();
|
|
@@ -115,23 +53,8 @@ public class ChromeBackgroundService extends GcmTaskService {
|
|
protected void rescheduleBackgroundSyncTasksOnUpgrade() {
|
|
}
|
|
|
|
- private void handleSnippetsOnBrowserUpgraded() {
|
|
- if (SnippetsLauncher.shouldNotifyOnBrowserUpgraded()) {
|
|
- if (!SnippetsLauncher.hasInstance()) {
|
|
- launchBrowser(this, /*tag=*/""); // The |tag| doesn't matter here.
|
|
- }
|
|
- snippetsOnBrowserUpgraded();
|
|
- }
|
|
- }
|
|
-
|
|
/** Reschedules offline pages (using appropriate version of Background Task Scheduler). */
|
|
protected void rescheduleOfflinePages() {
|
|
BackgroundScheduler.getInstance().reschedule();
|
|
}
|
|
-
|
|
- @Override
|
|
- public void onInitializeTasks() {
|
|
- rescheduleBackgroundSyncTasksOnUpgrade();
|
|
- handleSnippetsOnBrowserUpgraded();
|
|
- }
|
|
}
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationController.java b/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationController.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationController.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/invalidation/InvalidationController.java
|
|
@@ -167,6 +167,7 @@ public class InvalidationController implements ApplicationStatus.ApplicationStat
|
|
|
|
// Ensure GCM has been initialized.
|
|
ensureGcmIsInitialized();
|
|
+ if (!mGcmInitialized) return;
|
|
|
|
// Do not apply changes to {@link #mSessionInvalidationsEnabled} yet because the timer task
|
|
// may be scheduled far into the future.
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ntp/snippets/SnippetsLauncher.java
|
|
@@ -35,7 +35,7 @@ public class SnippetsLauncher {
|
|
// If it is non-null then the browser is running.
|
|
private static SnippetsLauncher sInstance;
|
|
|
|
- private boolean mGCMEnabled = true;
|
|
+ private boolean mGCMEnabled;
|
|
|
|
/**
|
|
* Create a SnippetsLauncher object, which is owned by C++.
|
|
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/ChromeGcmListenerService.java b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/ChromeGcmListenerService.java
|
|
--- a/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/ChromeGcmListenerService.java
|
|
+++ b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/ChromeGcmListenerService.java
|
|
@@ -11,7 +11,6 @@ import android.os.Bundle;
|
|
import android.os.SystemClock;
|
|
import android.text.TextUtils;
|
|
|
|
-import com.google.android.gms.gcm.GcmListenerService;
|
|
import com.google.ipc.invalidation.ticl.android2.channel.AndroidGcmController;
|
|
|
|
import org.chromium.base.ContextUtils;
|
|
@@ -35,62 +34,9 @@ import org.chromium.content_public.browser.UiThreadTaskTraits;
|
|
/**
|
|
* Receives Downstream messages and status of upstream messages from GCM.
|
|
*/
|
|
-public class ChromeGcmListenerService extends GcmListenerService {
|
|
+public class ChromeGcmListenerService {
|
|
private static final String TAG = "ChromeGcmListener";
|
|
|
|
- @Override
|
|
- public void onCreate() {
|
|
- ProcessInitializationHandler.getInstance().initializePreNative();
|
|
- super.onCreate();
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void onMessageReceived(final String from, final Bundle data) {
|
|
- boolean hasCollapseKey = !TextUtils.isEmpty(data.getString("collapse_key"));
|
|
- GcmUma.recordDataMessageReceived(ContextUtils.getApplicationContext(), hasCollapseKey);
|
|
-
|
|
- String invalidationSenderId = AndroidGcmController.get(this).getSenderId();
|
|
- if (from.equals(invalidationSenderId)) {
|
|
- AndroidGcmController.get(this).onMessageReceived(data);
|
|
- return;
|
|
- }
|
|
-
|
|
- // Dispatch the message to the GCM Driver for native features.
|
|
- PostTask.runOrPostTask(UiThreadTaskTraits.DEFAULT, () -> {
|
|
- GCMMessage message = null;
|
|
- try {
|
|
- message = new GCMMessage(from, data);
|
|
- } catch (IllegalArgumentException e) {
|
|
- Log.e(TAG, "Received an invalid GCM Message", e);
|
|
- return;
|
|
- }
|
|
-
|
|
- scheduleOrDispatchMessageToDriver(message);
|
|
- });
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void onMessageSent(String msgId) {
|
|
- Log.d(TAG, "Message sent successfully. Message id: " + msgId);
|
|
- GcmUma.recordGcmUpstreamHistogram(
|
|
- ContextUtils.getApplicationContext(), GcmUma.UMA_UPSTREAM_SUCCESS);
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void onSendError(String msgId, String error) {
|
|
- Log.w(TAG, "Error in sending message. Message id: " + msgId + " Error: " + error);
|
|
- GcmUma.recordGcmUpstreamHistogram(
|
|
- ContextUtils.getApplicationContext(), GcmUma.UMA_UPSTREAM_SEND_FAILED);
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void onDeletedMessages() {
|
|
- // TODO(johnme): Ask GCM to include the subtype in this event.
|
|
- Log.w(TAG, "Push messages were deleted, but we can't tell the Service Worker as we don't"
|
|
- + "know what subtype (app ID) it occurred for.");
|
|
- GcmUma.recordDeletedMessages(ContextUtils.getApplicationContext());
|
|
- }
|
|
-
|
|
/**
|
|
* Returns if we deliver the GCMMessage with a background service by calling
|
|
* Context#startService. This will only work if Android has put us in a whitelist to allow
|
|
@@ -225,8 +171,6 @@ public class ChromeGcmListenerService extends GcmListenerService {
|
|
|
|
try {
|
|
ChromeBrowserInitializer.getInstance(applicationContext).handleSynchronousStartup();
|
|
- GCMDriver.dispatchMessage(message);
|
|
-
|
|
} catch (ProcessInitException e) {
|
|
Log.e(TAG, "ProcessInitException while starting the browser process");
|
|
|
|
diff --git a/components/background_task_scheduler/BUILD.gn b/components/background_task_scheduler/BUILD.gn
|
|
--- a/components/background_task_scheduler/BUILD.gn
|
|
+++ b/components/background_task_scheduler/BUILD.gn
|
|
@@ -54,7 +54,6 @@ if (is_android) {
|
|
":scheduled_task_java",
|
|
"$google_play_services_package:google_play_services_base_java",
|
|
"$google_play_services_package:google_play_services_basement_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
"//content/public/android:content_java",
|
|
@@ -78,7 +77,6 @@ if (is_android) {
|
|
":background_task_scheduler_task_ids_java",
|
|
"$google_play_services_package:google_play_services_base_java",
|
|
"$google_play_services_package:google_play_services_basement_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
"//base:base_java_test_support",
|
|
@@ -109,7 +107,6 @@ if (is_android) {
|
|
"$google_play_services_package:google_play_services_auth_base_java",
|
|
"$google_play_services_package:google_play_services_base_java",
|
|
"$google_play_services_package:google_play_services_basement_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
"//base:base_java_test_support",
|
|
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskGcmTaskService.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskGcmTaskService.java
|
|
--- a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskGcmTaskService.java
|
|
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskGcmTaskService.java
|
|
@@ -6,10 +6,6 @@ package org.chromium.components.background_task_scheduler;
|
|
|
|
import android.os.Build;
|
|
|
|
-import com.google.android.gms.gcm.GcmNetworkManager;
|
|
-import com.google.android.gms.gcm.GcmTaskService;
|
|
-import com.google.android.gms.gcm.TaskParams;
|
|
-
|
|
import org.chromium.base.ContextUtils;
|
|
import org.chromium.base.Log;
|
|
import org.chromium.base.ThreadUtils;
|
|
@@ -20,7 +16,7 @@ import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
/** Delegates calls out to various tasks that need to run in the background. */
|
|
-public class BackgroundTaskGcmTaskService extends GcmTaskService {
|
|
+public class BackgroundTaskGcmTaskService {
|
|
private static final String TAG = "BkgrdTaskGcmTS";
|
|
|
|
private BackgroundTaskSchedulerGcmNetworkManager.Clock mClock = System::currentTimeMillis;
|
|
@@ -90,63 +86,6 @@ public class BackgroundTaskGcmTaskService extends GcmTaskService {
|
|
}
|
|
|
|
@Override
|
|
- public int onRunTask(TaskParams params) {
|
|
- final TaskParameters taskParams =
|
|
- BackgroundTaskSchedulerGcmNetworkManager.getTaskParametersFromTaskParams(params);
|
|
-
|
|
- final BackgroundTask backgroundTask =
|
|
- BackgroundTaskSchedulerFactory.getBackgroundTaskFromTaskId(taskParams.getTaskId());
|
|
- if (backgroundTask == null) {
|
|
- Log.w(TAG, "Failed to start task. Could not instantiate BackgroundTask class.");
|
|
- // Cancel task if the BackgroundTask class is not found anymore. We assume this means
|
|
- // that the task has been deprecated.
|
|
- BackgroundTaskSchedulerFactory.getScheduler().cancel(
|
|
- ContextUtils.getApplicationContext(), taskParams.getTaskId());
|
|
- return GcmNetworkManager.RESULT_FAILURE;
|
|
- }
|
|
-
|
|
- if (BackgroundTaskSchedulerGcmNetworkManager.didTaskExpire(
|
|
- params, mClock.currentTimeMillis())) {
|
|
- BackgroundTaskSchedulerUma.getInstance().reportTaskExpired(taskParams.getTaskId());
|
|
- return GcmNetworkManager.RESULT_FAILURE;
|
|
- }
|
|
-
|
|
- final Waiter waiter = new Waiter(Waiter.MAX_TIMEOUT_SECONDS);
|
|
-
|
|
- final AtomicBoolean taskNeedsBackgroundProcessing = new AtomicBoolean();
|
|
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
|
- @Override
|
|
- public void run() {
|
|
- BackgroundTaskSchedulerUma.getInstance().reportTaskStarted(taskParams.getTaskId());
|
|
- taskNeedsBackgroundProcessing.set(
|
|
- backgroundTask.onStartTask(ContextUtils.getApplicationContext(), taskParams,
|
|
- new TaskFinishedCallbackGcmTaskService(waiter)));
|
|
- }
|
|
- });
|
|
-
|
|
- if (!taskNeedsBackgroundProcessing.get()) return GcmNetworkManager.RESULT_SUCCESS;
|
|
-
|
|
- waiter.startWaiting();
|
|
-
|
|
- if (waiter.isRescheduleNeeded()) return GcmNetworkManager.RESULT_RESCHEDULE;
|
|
- if (!waiter.hasTaskTimedOut()) return GcmNetworkManager.RESULT_SUCCESS;
|
|
-
|
|
- final AtomicBoolean taskNeedsRescheduling = new AtomicBoolean();
|
|
- ThreadUtils.runOnUiThreadBlocking(new Runnable() {
|
|
- @Override
|
|
- public void run() {
|
|
- BackgroundTaskSchedulerUma.getInstance().reportTaskStopped(taskParams.getTaskId());
|
|
- taskNeedsRescheduling.set(backgroundTask.onStopTask(
|
|
- ContextUtils.getApplicationContext(), taskParams));
|
|
- }
|
|
- });
|
|
-
|
|
- if (taskNeedsRescheduling.get()) return GcmNetworkManager.RESULT_RESCHEDULE;
|
|
-
|
|
- return GcmNetworkManager.RESULT_SUCCESS;
|
|
- }
|
|
-
|
|
- @Override
|
|
public void onInitializeTasks() {
|
|
// Ignore the event on OSs supporting JobScheduler.
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) return;
|
|
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
|
|
--- a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
|
|
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerFactory.java
|
|
@@ -17,11 +17,7 @@ public final class BackgroundTaskSchedulerFactory {
|
|
private static BackgroundTaskFactory sBackgroundTaskFactory;
|
|
|
|
static BackgroundTaskSchedulerDelegate getSchedulerDelegateForSdk(int sdkInt) {
|
|
- if (sdkInt >= Build.VERSION_CODES.M) {
|
|
- return new BackgroundTaskSchedulerJobService();
|
|
- } else {
|
|
- return new BackgroundTaskSchedulerGcmNetworkManager();
|
|
- }
|
|
+ return new BackgroundTaskSchedulerJobService(); /* minSDK is 24 */
|
|
}
|
|
|
|
/**
|
|
diff --git a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerGcmNetworkManager.java b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerGcmNetworkManager.java
|
|
--- a/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerGcmNetworkManager.java
|
|
+++ b/components/background_task_scheduler/android/java/src/org/chromium/components/background_task_scheduler/BackgroundTaskSchedulerGcmNetworkManager.java
|
|
@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
|
* An implementation of {@link BackgroundTaskSchedulerDelegate} that uses the Play Services
|
|
* {@link GcmNetworkManager} to schedule jobs.
|
|
*/
|
|
-class BackgroundTaskSchedulerGcmNetworkManager implements BackgroundTaskSchedulerDelegate {
|
|
+class BackgroundTaskSchedulerGcmNetworkManager {
|
|
private static final String TAG = "BkgrdTaskSchedGcmNM";
|
|
|
|
/** Delta time for expiration checks, after the end time. */
|
|
@@ -34,18 +34,6 @@ class BackgroundTaskSchedulerGcmNetworkManager implements BackgroundTaskSchedule
|
|
sClock = clock;
|
|
}
|
|
|
|
- @Override
|
|
- public boolean schedule(Context context, @NonNull TaskInfo taskInfo) {
|
|
- ThreadUtils.assertOnUiThread();
|
|
-
|
|
- return false;
|
|
- }
|
|
-
|
|
- @Override
|
|
- public void cancel(Context context, int taskId) {
|
|
- ThreadUtils.assertOnUiThread();
|
|
- }
|
|
-
|
|
private static String taskIdToTaskTag(int taskId) {
|
|
return Integer.toString(taskId);
|
|
}
|
|
diff --git a/third_party/android_deps/BUILD.gn b/third_party/android_deps/BUILD.gn
|
|
--- a/third_party/android_deps/BUILD.gn
|
|
+++ b/third_party/android_deps/BUILD.gn
|
|
@@ -844,21 +844,6 @@ android_aar_prebuilt("google_play_services_fido_java") {
|
|
}
|
|
|
|
# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
|
|
-android_aar_prebuilt("google_play_services_gcm_java") {
|
|
- aar_path = "libs/com_google_android_gms_play_services_gcm/play-services-gcm-15.0.1.aar"
|
|
- info_path = "libs/com_google_android_gms_play_services_gcm/com_google_android_gms_play_services_gcm.info"
|
|
- deps = [
|
|
- ":google_play_services_base_java",
|
|
- ":google_play_services_basement_java",
|
|
- ":google_play_services_iid_java",
|
|
- ":google_play_services_stats_java",
|
|
- ]
|
|
-
|
|
- # Removing drawables from GMS .aars as they are unused bloat.
|
|
- strip_drawables = true
|
|
-}
|
|
-
|
|
-# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
|
|
android_aar_prebuilt("google_play_services_iid_java") {
|
|
aar_path = "libs/com_google_android_gms_play_services_iid/play-services-iid-15.0.1.aar"
|
|
info_path = "libs/com_google_android_gms_play_services_iid/com_google_android_gms_play_services_iid.info"
|
|
diff --git a/third_party/cacheinvalidation/BUILD.gn b/third_party/cacheinvalidation/BUILD.gn
|
|
--- a/third_party/cacheinvalidation/BUILD.gn
|
|
+++ b/third_party/cacheinvalidation/BUILD.gn
|
|
@@ -137,7 +137,6 @@ if (is_android) {
|
|
jacoco_never_instrument = true
|
|
deps = [
|
|
":cacheinvalidation_proto_java",
|
|
- "$google_play_services_package:google_play_services_gcm_java",
|
|
"$google_play_services_package:google_play_services_iid_java",
|
|
"$google_play_services_package:google_play_services_tasks_java",
|
|
"//base:base_java",
|
|
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifestUpdatedGcm.xml b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifestUpdatedGcm.xml
|
|
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifestUpdatedGcm.xml
|
|
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifestUpdatedGcm.xml
|
|
@@ -24,17 +24,6 @@
|
|
<receiver android:exported="false"
|
|
android:name="com.google.ipc.invalidation.ticl2.android2.AndroidInternalScheduler$AlarmReceiver"/>
|
|
|
|
- <!-- GCM Broadcast Receiver -->
|
|
- <receiver android:exported="true"
|
|
- android:name="com.google.android.gms.gcm.GcmReceiver"
|
|
- android:permission="com.google.android.c2dm.permission.SEND">
|
|
- <intent-filter>
|
|
- <action android:name="com.google.android.c2dm.intent.RECEIVE" />
|
|
- <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
|
|
- <category android:name="com.google.ipc.invalidation.client2.android2"/>
|
|
- </intent-filter>
|
|
- </receiver>
|
|
-
|
|
<!-- InstanceID Listener Service -->
|
|
<service android:exported="false"
|
|
android:name="com.google.ipc.invalidation.ticl2.android2.channel.AndroidInstanceIDListenerService">
|
|
@@ -42,14 +31,5 @@
|
|
<action android:name="com.google.android.gms.iid.InstanceID"/>
|
|
</intent-filter>
|
|
</service>
|
|
-
|
|
- <!-- GcmTaskService for registration -->
|
|
- <service android:name="com.google.ipc.invalidation.ticl2.android2.channel.GcmRegistrationTaskService"
|
|
- android:exported="true"
|
|
- android:permission="com.google.android.gms.permission.BIND_NETWORK_TASK_SERVICE" >
|
|
- <intent-filter>
|
|
- <action android:name="com.google.android.gms.gcm.ACTION_TASK_READY" />
|
|
- </intent-filter>
|
|
- </service>
|
|
</application>
|
|
</manifest>
|
|
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidGcmController.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidGcmController.java
|
|
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidGcmController.java
|
|
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidGcmController.java
|
|
@@ -15,8 +15,6 @@
|
|
*/
|
|
package com.google.ipc.invalidation.ticl.android2.channel;
|
|
|
|
-import com.google.android.gms.gcm.GcmNetworkManager;
|
|
-import com.google.android.gms.gcm.OneoffTask;
|
|
import com.google.ipc.invalidation.common.GcmSharedConstants;
|
|
import com.google.ipc.invalidation.external.client.SystemResources.Logger;
|
|
import com.google.ipc.invalidation.external.client.android.service.AndroidLogger;
|
|
@@ -50,7 +48,7 @@ public class AndroidGcmController {
|
|
|
|
private static AndroidGcmController androidGcmController;
|
|
|
|
- private GcmNetworkManager gcmNetworkManager;
|
|
+// private GcmNetworkManager gcmNetworkManager;
|
|
|
|
private Context context;
|
|
|
|
@@ -64,33 +62,13 @@ public class AndroidGcmController {
|
|
public static AndroidGcmController get(Context context) {
|
|
synchronized (lock) {
|
|
if (androidGcmController == null) {
|
|
- androidGcmController =
|
|
- new AndroidGcmController(context, GcmNetworkManager.getInstance(context));
|
|
+ androidGcmController = null;
|
|
}
|
|
}
|
|
return androidGcmController;
|
|
}
|
|
|
|
/**
|
|
- * Override AndroidGcmController with a custom GcmNetworkManager in tests. This overrides the
|
|
- * existing instance of AndroidGcmController if any.
|
|
- *
|
|
- * @param context the application context.
|
|
- * @param gcmNetworkManager the custom GcmNetworkManager to use.
|
|
- */
|
|
- public static void overrideAndroidGcmControllerForTests(
|
|
- Context context, GcmNetworkManager gcmNetworkManager) {
|
|
- synchronized (lock) {
|
|
- androidGcmController = new AndroidGcmController(context, gcmNetworkManager);
|
|
- }
|
|
- }
|
|
-
|
|
- private AndroidGcmController(Context context, GcmNetworkManager gcmNetworkManager) {
|
|
- this.context = context;
|
|
- this.gcmNetworkManager = gcmNetworkManager;
|
|
- }
|
|
-
|
|
- /**
|
|
* Returns true if no registration token is stored or the current application version is higher
|
|
* than the version for the token stored.
|
|
*/
|
|
@@ -142,21 +120,7 @@ public class AndroidGcmController {
|
|
return;
|
|
}
|
|
|
|
- OneoffTask registrationTask =
|
|
- new OneoffTask.Builder()
|
|
- .setExecutionWindow(0, 1)
|
|
- .setTag(AndroidChannelConstants.GCM_REGISTRATION_TASK_SERVICE_TAG)
|
|
- .setService(GcmRegistrationTaskService.class)
|
|
- .build();
|
|
-
|
|
- try {
|
|
- gcmNetworkManager.schedule(registrationTask);
|
|
- } catch (IllegalArgumentException exception) {
|
|
- // Scheduling the service can throw an exception due to a framework error on Android when
|
|
- // the the look up for the GCMTaskService being scheduled to be run fails.
|
|
- // See crbug/548314.
|
|
- logger.warning("Failed to schedule GCM registration task. Exception: %s", exception);
|
|
- }
|
|
+ logger.warning("Failed to schedule GCM registration task.");
|
|
}
|
|
|
|
/**
|
|
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidInstanceIDListenerService.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidInstanceIDListenerService.java
|
|
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidInstanceIDListenerService.java
|
|
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidInstanceIDListenerService.java
|
|
@@ -15,7 +15,6 @@
|
|
*/
|
|
package com.google.ipc.invalidation.ticl.android2.channel;
|
|
|
|
-import com.google.android.gms.iid.InstanceIDListenerService;
|
|
import com.google.ipc.invalidation.external.client.SystemResources.Logger;
|
|
import com.google.ipc.invalidation.external.client.android.service.AndroidLogger;
|
|
|
|
@@ -23,16 +22,6 @@ import com.google.ipc.invalidation.external.client.android.service.AndroidLogger
|
|
* Implementation of {@link InstanceIDListenerService} to receive notifications from GCM to
|
|
* update the registration token.
|
|
*/
|
|
-public class AndroidInstanceIDListenerService extends InstanceIDListenerService {
|
|
+public class AndroidInstanceIDListenerService {
|
|
private static final Logger logger = AndroidLogger.forTag("InstanceIDListener");
|
|
-
|
|
- /**
|
|
- * Called when the token needs to updated. {@link AndroidGcmController#fetchToken} clears the
|
|
- * current token and schedules a task to fetch a new token.
|
|
- */
|
|
- @Override
|
|
- public void onTokenRefresh() {
|
|
- logger.info("Received token refresh request");
|
|
- AndroidGcmController.get(this).fetchToken();
|
|
- }
|
|
}
|
|
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/GcmRegistrationTaskService.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/GcmRegistrationTaskService.java
|
|
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/GcmRegistrationTaskService.java
|
|
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/GcmRegistrationTaskService.java
|
|
@@ -15,11 +15,6 @@
|
|
*/
|
|
package com.google.ipc.invalidation.ticl.android2.channel;
|
|
|
|
-import com.google.android.gms.gcm.GcmNetworkManager;
|
|
-import com.google.android.gms.gcm.GcmTaskService;
|
|
-import com.google.android.gms.gcm.GoogleCloudMessaging;
|
|
-import com.google.android.gms.gcm.TaskParams;
|
|
-import com.google.android.gms.iid.InstanceID;
|
|
import com.google.ipc.invalidation.common.GcmSharedConstants;
|
|
import com.google.ipc.invalidation.external.client.SystemResources.Logger;
|
|
import com.google.ipc.invalidation.external.client.android.service.AndroidLogger;
|
|
@@ -42,88 +37,6 @@ import java.io.IOException;
|
|
* failure to fetch the token, the task is rescheduled using the GcmNetworkManager which uses
|
|
* exponential back-offs to control when the task is executed.
|
|
*/
|
|
-public class GcmRegistrationTaskService extends GcmTaskService {
|
|
+public class GcmRegistrationTaskService {
|
|
private static final Logger logger = AndroidLogger.forTag("RegistrationTaskService");
|
|
-
|
|
- public InstanceID getInstanceID(Context context) {
|
|
- return InstanceID.getInstance(context);
|
|
- }
|
|
-
|
|
- /**
|
|
- * Called when the task is ready to be executed. Registers with GCM using
|
|
- * {@link InstanceID#getToken} and stores the registration token.
|
|
- *
|
|
- * <p>Returns {@link GcmNetworkManager#RESULT_SUCCESS} when the token is successfully retrieved.
|
|
- * On failure {@link GcmNetworkManager#RESULT_RESCHEDULE} is used which reschedules the service
|
|
- * to be executed again using exponential back-off.
|
|
- */
|
|
- @Override
|
|
- public int onRunTask(TaskParams params) {
|
|
- if (!AndroidChannelConstants.GCM_REGISTRATION_TASK_SERVICE_TAG.equals(params.getTag())) {
|
|
- logger.warning("Unknown task received with tag: %s", params.getTag());
|
|
- return GcmNetworkManager.RESULT_FAILURE;
|
|
- }
|
|
-
|
|
- String senderId = GcmSharedConstants.GCM_UPDATED_SENDER_ID;
|
|
- try {
|
|
- String token = getInstanceID(this).getToken(
|
|
- senderId, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
|
|
- storeToken(token);
|
|
- return GcmNetworkManager.RESULT_SUCCESS;
|
|
- } catch (IOException exception) {
|
|
- logger.warning("Failed to get token for sender: %s. Exception : %s", senderId, exception);
|
|
- return GcmNetworkManager.RESULT_RESCHEDULE;
|
|
- } catch (SecurityException exception) {
|
|
- // InstanceID#getToken occasionally throws a security exception when trying send the
|
|
- // registration intent to GMSCore. Catching the exception here to prevent crashes.
|
|
- logger.warning("Security exception when fetching token: %s", exception);
|
|
- return GcmNetworkManager.RESULT_RESCHEDULE;
|
|
- }
|
|
- }
|
|
-
|
|
- /** Stores the registration token and the current application version in Shared Preferences. */
|
|
- private void storeToken(String token) {
|
|
- AndroidChannelPreferences.setRegistrationToken(token);
|
|
- AndroidChannelPreferences.setAppVersion(
|
|
- CommonUtils.getPackageVersion(this, getPackageName()));
|
|
- // Send the updated token to the server.
|
|
- updateServer();
|
|
- }
|
|
-
|
|
- /** Sends a message to the server to update the GCM registration token. */
|
|
- private void updateServer() {
|
|
- // Inform the sender service that the registration token has changed. If the sender service
|
|
- // had buffered a message because no registration token was previously available, this intent
|
|
- // will cause it to send that message.
|
|
- Intent sendBuffered = new Intent();
|
|
- final String ignoredData = "";
|
|
- sendBuffered.putExtra(AndroidChannelConstants.MESSAGE_SENDER_SVC_GCM_REGID_CHANGE, ignoredData);
|
|
-
|
|
- // Select the sender service to use for upstream message.
|
|
- if (AndroidChannelPreferences.getGcmChannelType() == GcmChannelType.GCM_UPSTREAM) {
|
|
- String upstreamServiceClass = new AndroidTiclManifest(this).getGcmUpstreamServiceClass();
|
|
- if (upstreamServiceClass == null) {
|
|
- logger.warning("GcmUpstreamSenderService class not found.");
|
|
- return;
|
|
- }
|
|
- sendBuffered.setClassName(this, upstreamServiceClass);
|
|
- } else {
|
|
- sendBuffered.setClass(this, AndroidMessageSenderService.class);
|
|
- }
|
|
- try {
|
|
- startService(sendBuffered);
|
|
- } catch (IllegalStateException exception) {
|
|
- logger.warning("Unable to send buffered message(s): %s", exception);
|
|
- }
|
|
-
|
|
- // Inform the Ticl service that the registration id has changed. This will cause it to send
|
|
- // a message to the data center and update the GCM registration id stored at the data center.
|
|
- Intent updateServer = ProtocolIntents.InternalDowncalls.newNetworkAddrChangeIntent();
|
|
- updateServer.setClassName(this, new AndroidTiclManifest(this).getTiclServiceClass());
|
|
- try {
|
|
- startService(updateServer);
|
|
- } catch (IllegalStateException exception) {
|
|
- logger.warning("Unable to inform server about new registration id: %s", exception);
|
|
- }
|
|
- }
|
|
}
|
|
--
|
|
2.11.0
|
|
|