Browse Source

Remove dependency on Google Play GCM library

tags/75.0.3770.142-2
wchen342 1 year ago
parent
commit
25826b626e
Signed by untrusted user: wchen342 GPG Key ID: 720B70365E800508
8 changed files with 829 additions and 59 deletions
  1. +0
    -1
      .gclient
  2. +0
    -0
      LICENSE.md
  3. +4
    -3
      README.md
  4. +1
    -1
      domain_sub_2.list
  5. +1
    -0
      patches/ungoogled-chromium-android/patches.list
  6. +19
    -0
      patches/ungoogled-chromium-android/remove-desugar-runtime.patch
  7. +58
    -54
      patches/ungoogled-chromium-android/remove-gcm-client.patch
  8. +746
    -0
      patches/ungoogled-chromium-android/remove_gms_gcm.patch

+ 0
- 1
.gclient View File

@ -84,4 +84,3 @@ solutions = [
]
target_os = ["android"]
target_os_only = "true"

LICENSE → LICENSE.md View File


+ 4
- 3
README.md View File

@ -65,9 +65,10 @@ You can use f-Droid client and add [this repository](https://www.droidware.info/
## TODO List
- [x] Remove dependencies on SDK tools and extras
- [x] Domain substitution in java files
- [ ] Prune binaries
- [ ] Remove Play Services
- [ ] Java patches (mostly UI-related)
- [x] Prune binaries (*Note: haven't found a way to build desugar-runtime without bazel. Please let me know if you know how.*)
- [ ] Remove Play Services [WIP]
* GCM removed
- [ ] Java patches (low priority)
## Credits


+ 1
- 1
domain_sub_2.list View File

@ -13961,4 +13961,4 @@
./v8/test/unittests/heap/slot-set-unittest.cc
./v8/test/unittests/zone/zone-chunk-list-unittest.cc
./v8/tools/mb/mb.py
./v8/tools/release/merge_to_branch.py
./v8/tools/release/merge_to_branch.py

+ 1
- 0
patches/ungoogled-chromium-android/patches.list View File

@ -1 +1,2 @@
remove-gcm-client.patch
remove_gms_gcm.patch

+ 19
- 0
patches/ungoogled-chromium-android/remove-desugar-runtime.patch View File

@ -0,0 +1,19 @@
Remove dependencies on desugar-runtime.jar. Don't work yet.
author: Wengling Chen <[email protected]>
---
third_party/bazel/desugar/BUILD.gn | 5 -----
1 file changed, 5 deletions(-)
diff --git a/third_party/bazel/desugar/BUILD.gn b/third_party/bazel/desugar/BUILD.gn
--- a/third_party/bazel/desugar/BUILD.gn
+++ b/third_party/bazel/desugar/BUILD.gn
@@ -5,8 +5,3 @@
import("//build/config/android/rules.gni")
# Provides runtime support for desugar transformations.
-java_prebuilt("desugar_runtime_java") {
- supports_android = true
- jar_path = "Desugar-runtime.jar"
- no_build_hooks = true
-}

+ 58
- 54
patches/ungoogled-chromium-android/remove-gcm-client.patch View File

@ -1,19 +1,23 @@
Remove dependency on com.google.android.gcm (//third_party/android_sdk/public/extras/google/gcm/gcm-client/dist/gcm.jar).
author: Wengling Chen <[email protected]>
---
src/chrome/android/BUILD.gn | 1
src/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java | 10 -
src/components/gcm_driver/android/BUILD.gn | 1
src/components/sync/android/BUILD.gn | 1
src/third_party/android_sdk/BUILD.gn | 3
src/third_party/cacheinvalidation/BUILD.gn | 1
src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml | 35 ---
src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java | 93 ----------
src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java | 17 -
src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java | 3
chrome/android/BUILD.gn | 1 -
.../gcm/InvalidationGcmUpstreamSender.java | 10 +--
components/gcm_driver/android/BUILD.gn | 1 -
components/sync/android/BUILD.gn | 1 -
third_party/android_sdk/BUILD.gn | 3 -
third_party/cacheinvalidation/BUILD.gn | 1 -
.../external/client/android2/AndroidManifest.xml | 35 --------
.../client/contrib/MultiplexingGcmListener.java | 93 +---------------------
.../channel/AndroidMessageReceiverService.java | 17 ----
.../channel/AndroidMessageSenderService.java | 3 +-
10 files changed, 5 insertions(+), 160 deletions(-)
--- a/src/chrome/android/BUILD.gn
+++ b/src/chrome/android/BUILD.gn
@@ -343,7 +343,6 @@
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -343,7 +343,6 @@ android_library("chrome_java") {
"//third_party/android_deps:com_google_protobuf_protobuf_lite_java",
"//third_party/android_deps:javax_inject_javax_inject_java",
"//third_party/android_media:android_media_java",
@ -21,10 +25,10 @@
"//third_party/android_swipe_refresh:android_swipe_refresh_java",
"//third_party/blink/public:blink_headers_java",
"//third_party/blink/public/mojom:android_mojo_bindings_java",
--- a/src/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java
+++ b/src/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java
@@ -13,7 +13,6 @@
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java
--- a/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/services/gcm/InvalidationGcmUpstreamSender.java
@@ -13,7 +13,6 @@ import android.support.annotation.MainThread;
import android.support.annotation.Nullable;
import android.util.Log;
@ -32,7 +36,7 @@
import com.google.ipc.invalidation.ticl.android2.channel.GcmUpstreamSenderService;
import org.chromium.base.ContextUtils;
@@ -94,13 +93,8 @@
@@ -94,13 +93,8 @@ public class InvalidationGcmUpstreamSender extends GcmUpstreamSenderService {
return;
}
String msgId = UUID.randomUUID().toString();
@ -48,10 +52,10 @@
}
private boolean isMessageWithinLimit(Bundle data) {
--- a/src/components/gcm_driver/android/BUILD.gn
+++ b/src/components/gcm_driver/android/BUILD.gn
@@ -15,7 +15,6 @@
diff --git a/components/gcm_driver/android/BUILD.gn b/components/gcm_driver/android/BUILD.gn
--- a/components/gcm_driver/android/BUILD.gn
+++ b/components/gcm_driver/android/BUILD.gn
@@ -15,7 +15,6 @@ android_library("gcm_driver_java") {
deps = [
"//base:base_java",
"//content/public/android:content_java",
@ -59,10 +63,10 @@
"//third_party/jsr-305:jsr_305_javalib",
]
--- a/src/components/sync/android/BUILD.gn
+++ b/src/components/sync/android/BUILD.gn
@@ -11,7 +11,6 @@
diff --git a/components/sync/android/BUILD.gn b/components/sync/android/BUILD.gn
--- a/components/sync/android/BUILD.gn
+++ b/components/sync/android/BUILD.gn
@@ -11,7 +11,6 @@ android_library("sync_java") {
"//components/signin/core/browser/android:java",
"//net/android:net_java",
"//third_party/android_deps:com_android_support_support_annotations_java",
@ -70,10 +74,10 @@
"//third_party/cacheinvalidation:cacheinvalidation_javalib",
"//third_party/cacheinvalidation:cacheinvalidation_proto_java",
"//third_party/jsr-305:jsr_305_javalib",
--- a/src/third_party/android_sdk/BUILD.gn
+++ b/src/third_party/android_sdk/BUILD.gn
@@ -87,9 +87,6 @@
diff --git a/third_party/android_sdk/BUILD.gn b/third_party/android_sdk/BUILD.gn
--- a/third_party/android_sdk/BUILD.gn
+++ b/third_party/android_sdk/BUILD.gn
@@ -87,9 +87,6 @@ if (enable_java_templates) {
testonly = true
java_files = [ "//third_party/android_sdk/public/extras/chromium/support/src/org/chromium/android/support/PackageManagerWrapper.java" ]
}
@ -83,10 +87,10 @@
android_java_prebuilt("emma_device_java") {
jar_path = "//third_party/android_sdk/public/tools/lib/emma_device.jar"
include_java_resources = true
--- a/src/third_party/cacheinvalidation/BUILD.gn
+++ b/src/third_party/cacheinvalidation/BUILD.gn
@@ -141,7 +141,6 @@
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
@@ -141,7 +141,6 @@ if (is_android) {
"$google_play_services_package:google_play_services_iid_java",
"$google_play_services_package:google_play_services_tasks_java",
"//third_party/android_protobuf:protobuf_nano_javalib",
@ -94,9 +98,9 @@
]
java_files = [
--- a/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml
+++ b/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/android2/AndroidManifest.xml
@@ -4,10 +4,6 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.ipc.invalidation.client.android2">
@ -149,9 +153,9 @@
- </receiver>
</application>
</manifest>
--- a/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java
+++ b/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/external/client/contrib/MultiplexingGcmListener.java
@@ -16,9 +16,6 @@
package com.google.ipc.invalidation.external.client.contrib;
@ -162,7 +166,7 @@
import com.google.ipc.invalidation.external.client.SystemResources.Logger;
import com.google.ipc.invalidation.external.client.android.service.AndroidLogger;
import com.google.ipc.invalidation.ticl.android2.WakeLockManager;
@@ -69,7 +66,7 @@
@@ -69,7 +66,7 @@ import android.content.pm.ServiceInfo;
* there is nothing to do except log an error (which this class does).
*
*/
@ -171,10 +175,11 @@
/* This class is public so that it can be instantiated by the Android runtime. */
/** Constants used in broadcast Intents. */
@@ -106,18 +103,6 @@
@@ -105,18 +102,6 @@ public class MultiplexingGcmListener extends GCMBaseIntentService {
public static final String EXTRA_DATA_NUM_DELETED_MSGS = PREFIX + "NUM_DELETED_MSGS";
}
/**
- /**
- * {@link GCMBroadcastReceiver} that forwards GCM intents to the {@code MultiplexingGcmListener}
- * class.
- */
@ -186,11 +191,10 @@
- }
- }
-
- /**
/**
* Convenience base class for client implementations. It provides base classes for a broadcast
* receiver and an intent service that work together to handle events from the
* {@code MultiplexingGcmListener} while holding a wake lock.
@@ -260,85 +245,11 @@
@@ -260,85 +245,11 @@ public class MultiplexingGcmListener extends GCMBaseIntentService {
/** Logger. */
private static final Logger logger = AndroidLogger.forTag("MplexGcmListener");
@ -277,9 +281,9 @@
static String[] readSenderIdsFromManifestOrDie(Context context) {
try {
ServiceInfo serviceInfo = context.getPackageManager().getServiceInfo(
--- a/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java
+++ b/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageReceiverService.java
@@ -15,7 +15,6 @@
*/
package com.google.ipc.invalidation.ticl.android2.channel;
@ -288,7 +292,7 @@
import com.google.ipc.invalidation.external.client.SystemResources.Logger;
import com.google.ipc.invalidation.external.client.android.service.AndroidLogger;
import com.google.ipc.invalidation.external.client.contrib.MultiplexingGcmListener;
@@ -126,20 +125,4 @@
@@ -126,20 +125,4 @@ public class AndroidMessageReceiverService extends MultiplexingGcmListener.Abstr
// now, there is nothing to do.
}
@ -309,9 +313,9 @@
- }
- }
}
--- a/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java
+++ b/src/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java
diff --git a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java
--- a/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java
+++ b/third_party/cacheinvalidation/src/java/com/google/ipc/invalidation/ticl/android2/channel/AndroidMessageSenderService.java
@@ -15,7 +15,6 @@
*/
package com.google.ipc.invalidation.ticl.android2.channel;
@ -320,7 +324,7 @@
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;
@@ -396,7 +395,7 @@
@@ -396,7 +395,7 @@ public class AndroidMessageSenderService extends IntentService {
// No client key when using old style registration id.
clientKey = "";
try {


+ 746
- 0
patches/ungoogled-chromium-android/remove_gms_gcm.patch View File

@ -0,0 +1,746 @@
Remove dependency on com.google.android.gms.gcm (play-services-gcm-15.0.1.aar).
author: Wengling Chen <[email protected]>
---
chrome/android/BUILD.gn | 2 -
.../invalidation/InvalidationController.java | 8 +-
.../services/gcm/ChromeGcmListenerService.java | 57 +------
components/background_task_scheduler/BUILD.gn | 3 -
.../BackgroundTaskGcmTaskService.java | 53 +------
.../BackgroundTaskSchedulerFactory.java | 2 +-
.../BackgroundTaskSchedulerGcmNetworkManager.java | 164 +--------------------
third_party/android_deps/BUILD.gn | 20 ---
third_party/cacheinvalidation/BUILD.gn | 1 -
.../client/android2/AndroidManifestUpdatedGcm.xml | 20 ---
.../android2/channel/AndroidGcmController.java | 42 +-----
.../channel/AndroidInstanceIDListenerService.java | 13 +-
.../channel/GcmRegistrationTaskService.java | 89 +----------
13 files changed, 11 insertions(+), 463 deletions(-)
diff --git a/chrome/android/BUILD.gn b/chrome/android/BUILD.gn
--- a/chrome/android/BUILD.gn
+++ b/chrome/android/BUILD.gn
@@ -255,7 +255,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",
@@ -720,7 +719,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",
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
@@ -169,6 +169,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.
@@ -194,12 +195,7 @@ public class InvalidationController implements ApplicationStatus.ApplicationStat
*/
private void ensureGcmIsInitialized() {
if (mGcmInitialized) return;
- mGcmInitialized = true;
- PostTask.postTask(TaskTraits.BEST_EFFORT_MAY_BLOCK, () -> {
- boolean useGcmUpstream = true;
- AndroidGcmController.get(ContextUtils.getApplicationContext())
- .initializeGcm(useGcmUpstream);
- });
+ mGcmInitialized = false;
}
@VisibleForTesting
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
@@ -10,7 +10,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.ApplicationStatus;
@@ -33,62 +32,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());
- }
-
/**
* If Chrome is backgrounded, messages coming from lazy subscriptions are
* persisted on disk and replayed next time Chrome is forgrounded. If Chrome is forgrounded or
@@ -149,7 +95,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
@@ -53,7 +53,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",
"//third_party/android_deps:com_android_support_support_annotations_java",
@@ -73,7 +72,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",
@@ -98,7 +96,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;
@@ -19,7 +15,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";
/** Class that waits for the processing to be done. */
@@ -81,53 +77,6 @@ public class BackgroundTaskGcmTaskService extends GcmTaskService {
}
}
- @Override
- public int onRunTask(TaskParams params) {
- final BackgroundTask backgroundTask =
- BackgroundTaskSchedulerGcmNetworkManager.getBackgroundTaskFromTaskParams(params);
- if (backgroundTask == null) {
- Log.w(TAG, "Failed to start task. Could not instantiate class.");
- return GcmNetworkManager.RESULT_FAILURE;
- }
-
- final TaskParameters taskParams =
- BackgroundTaskSchedulerGcmNetworkManager.getTaskParametersFromTaskParams(params);
- 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
@@ -19,7 +19,7 @@ public final class BackgroundTaskSchedulerFactory {
if (sdkInt >= Build.VERSION_CODES.M) {
return new BackgroundTaskSchedulerJobService();
} else {
- return new BackgroundTaskSchedulerGcmNetworkManager();
+ return null; /* 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
@@ -8,14 +8,6 @@ import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
-import com.google.android.gms.common.ConnectionResult;
-import com.google.android.gms.common.GoogleApiAvailability;
-import com.google.android.gms.gcm.GcmNetworkManager;
-import com.google.android.gms.gcm.OneoffTask;
-import com.google.android.gms.gcm.PeriodicTask;
-import com.google.android.gms.gcm.Task;
-import com.google.android.gms.gcm.TaskParams;
-
import org.chromium.base.Log;
import org.chromium.base.ThreadUtils;
import org.chromium.base.VisibleForTesting;
@@ -26,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";
@VisibleForTesting
@@ -34,160 +26,6 @@ class BackgroundTaskSchedulerGcmNetworkManager implements BackgroundTaskSchedule
@VisibleForTesting
static final String BACKGROUND_TASK_EXTRAS_KEY = "_background_task_extras";
- static BackgroundTask getBackgroundTaskFromTaskParams(@NonNull TaskParams taskParams) {
- String backgroundTaskClassName = getBackgroundTaskClassFromTaskParams(taskParams);
- return BackgroundTaskReflection.getBackgroundTaskFromClassName(backgroundTaskClassName);
- }
-
- private static String getBackgroundTaskClassFromTaskParams(@NonNull TaskParams taskParams) {
- Bundle extras = taskParams.getExtras();
- if (extras == null) return null;
- return extras.getString(BACKGROUND_TASK_CLASS_KEY);
- }
-
- /**
- * Retrieves the {@link TaskParameters} from the {@link TaskParams}, which are passed as
- * one of the keys. Only values valid for {@link android.os.BaseBundle} are supported, and other
- * values are stripped at the time when the task is scheduled.
- *
- * @param taskParams the {@link TaskParams} to extract the {@link TaskParameters} from.
- * @return the {@link TaskParameters} for the current job.
- */
- static TaskParameters getTaskParametersFromTaskParams(@NonNull TaskParams taskParams) {
- int taskId;
- try {
- taskId = Integer.parseInt(taskParams.getTag());
- } catch (NumberFormatException e) {
- Log.e(TAG, "Cound not parse task ID from task tag: " + taskParams.getTag());
- return null;
- }
-
- TaskParameters.Builder builder = TaskParameters.create(taskId);
-
- Bundle extras = taskParams.getExtras();
- Bundle taskExtras = extras.getBundle(BACKGROUND_TASK_EXTRAS_KEY);
- builder.addExtras(taskExtras);
-
- return builder.build();
- }
-
- @VisibleForTesting
- static Task createTaskFromTaskInfo(@NonNull TaskInfo taskInfo) {
- Bundle taskExtras = new Bundle();
- taskExtras.putString(
- BACKGROUND_TASK_CLASS_KEY, taskInfo.getBackgroundTaskClass().getName());
- taskExtras.putBundle(BACKGROUND_TASK_EXTRAS_KEY, taskInfo.getExtras());
-
- Task.Builder builder;
- if (taskInfo.isPeriodic()) {
- builder = getPeriodicTaskBuilder(taskInfo.getPeriodicInfo());
- } else {
- builder = getOneOffTaskBuilder(taskInfo.getOneOffInfo());
- }
-
- builder.setExtras(taskExtras)
- .setPersisted(taskInfo.isPersisted())
- .setRequiredNetwork(getGcmNetworkManagerNetworkTypeFromTypeFromTaskNetworkType(
- taskInfo.getRequiredNetworkType()))
- .setRequiresCharging(taskInfo.requiresCharging())
- .setService(BackgroundTaskGcmTaskService.class)
- .setTag(taskIdToTaskTag(taskInfo.getTaskId()))
- .setUpdateCurrent(taskInfo.shouldUpdateCurrent());
-
- return builder.build();
- }
-
- private static Task.Builder getPeriodicTaskBuilder(TaskInfo.PeriodicInfo periodicInfo) {
- PeriodicTask.Builder builder = new PeriodicTask.Builder();
- builder.setPeriod(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getIntervalMs()));
- if (periodicInfo.hasFlex()) {
- builder.setFlex(TimeUnit.MILLISECONDS.toSeconds(periodicInfo.getFlexMs()));
- }
- return builder;
- }
-
- private static Task.Builder getOneOffTaskBuilder(TaskInfo.OneOffInfo oneOffInfo) {
- OneoffTask.Builder builder = new OneoffTask.Builder();
- long windowStartSeconds = oneOffInfo.hasWindowStartTimeConstraint()
- ? TimeUnit.MILLISECONDS.toSeconds(oneOffInfo.getWindowStartTimeMs())
- : 0;
- builder.setExecutionWindow(windowStartSeconds,
- TimeUnit.MILLISECONDS.toSeconds(oneOffInfo.getWindowEndTimeMs()));
- return builder;
- }
-
- private static int getGcmNetworkManagerNetworkTypeFromTypeFromTaskNetworkType(
- @TaskInfo.NetworkType int networkType) {
- switch (networkType) {
- // This is correct: GcmNM ANY means no network is guaranteed.
- case TaskInfo.NetworkType.NONE:
- return Task.NETWORK_STATE_ANY;
- case TaskInfo.NetworkType.ANY:
- return Task.NETWORK_STATE_CONNECTED;
- case TaskInfo.NetworkType.UNMETERED:
- return Task.NETWORK_STATE_UNMETERED;
- default:
- assert false;
- }
- return Task.NETWORK_STATE_ANY;
- }
-
- @Override
- public boolean schedule(Context context, @NonNull TaskInfo taskInfo) {
- ThreadUtils.assertOnUiThread();
- if (!BackgroundTaskReflection.hasParameterlessPublicConstructor(
- taskInfo.getBackgroundTaskClass())) {
- Log.e(TAG,
- "BackgroundTask " + taskInfo.getBackgroundTaskClass()
- + " has no parameterless public constructor.");
- return false;
- }
-
- GcmNetworkManager gcmNetworkManager = getGcmNetworkManager(context);
- if (gcmNetworkManager == null) {
- Log.e(TAG, "GcmNetworkManager is not available.");
- return false;
- }
-
- try {
- Task task = createTaskFromTaskInfo(taskInfo);
- gcmNetworkManager.schedule(task);
- } catch (IllegalArgumentException e) {
- String gcmErrorMessage = e.getMessage() == null ? "null." : e.getMessage();
- Log.e(TAG,
- "GcmNetworkManager failed to schedule task, gcm message: " + gcmErrorMessage);
- return false;
- }
-
- return true;
- }
-
- @Override
- public void cancel(Context context, int taskId) {
- ThreadUtils.assertOnUiThread();
-
- GcmNetworkManager gcmNetworkManager = getGcmNetworkManager(context);
- if (gcmNetworkManager == null) {
- Log.e(TAG, "GcmNetworkManager is not available.");
- return;
- }
-
- try {
- gcmNetworkManager.cancelTask(
- taskIdToTaskTag(taskId), BackgroundTaskGcmTaskService.class);
- } catch (IllegalArgumentException e) {
- Log.e(TAG, "GcmNetworkManager failed to cancel task.");
- }
- }
-
- private GcmNetworkManager getGcmNetworkManager(Context context) {
- if (GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
- == ConnectionResult.SUCCESS) {
- return GcmNetworkManager.getInstance(context);
- }
- return null;
- }
-
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
@@ -75,11 +75,6 @@ java_group("google_play_services_instantapps_java") {
":com_google_android_gms_play_services_instantapps_java",
]
}
-java_group("google_play_services_gcm_java") {
- deps = [
- ":com_google_android_gms_play_services_gcm_java",
- ]
-}
java_group("google_play_services_location_java") {
deps = [
":com_google_android_gms_play_services_location_java",
@@ -496,21 +491,6 @@ android_aar_prebuilt("com_google_android_gms_play_services_fido_java") {
strip_drawables = true
}
-# This is generated, do not edit. Update BuildConfigGenerator.groovy instead.
-android_aar_prebuilt("com_google_android_gms_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 = [
- ":com_google_android_gms_play_services_base_java",
- ":com_google_android_gms_play_services_basement_java",
- ":com_google_android_gms_play_services_iid_java",
- ":com_google_android_gms_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("com_google_android_gms_play_services_iid_java") {
aar_path = "libs/com_google_android_gms_play_services_iid/play-services-iid-15.0.1.aar"
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) {
emma_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",
"//third_party/android_protobuf:protobuf_nano_javalib",
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,32 +62,12 @@ 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(this, token);
- AndroidChannelPreferences.setAppVersion(
- this, 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(this) == 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);
- }
- }
}

Loading…
Cancel
Save