Bug 1386151 - Accept multiple sender ID for MMA. Waiting for Sender ID udpate and API Key request. r?maliu
MozReview-Commit-ID: Ewot0f6iBgk
--- a/mobile/android/base/MmaConstants.java.in
+++ b/mobile/android/base/MmaConstants.java.in
@@ -23,16 +23,18 @@ public class MmaConstants {
public static final String MOZ_LEANPLUM_SDK_CLIENTID =
//#ifdef MOZ_LEANPLUM_SDK_CLIENTID
"@MOZ_LEANPLUM_SDK_CLIENTID@";
//#else
null;
//#endif
+public static final String MOZ_MMA_SENDER_ID = "242693410970";
+
public static MmaInterface getMma() {
//#ifdef MOZ_ANDROID_MMA
return new MmaLeanplumImp();
//#else
return new MmaStubImp();
//#endif
}
}
--- a/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gcm/GcmMessageListenerService.java
@@ -25,17 +25,17 @@ public class GcmMessageListenerService e
*
* @param from SenderID of the sender.
* @param bundle Data bundle containing message data as key/value pairs.
*/
@Override
public void onMessageReceived(final String from, final Bundle bundle) {
Log.d("GeckoPushGCM", "Message received. Processing on background thread.");
- if (MmaDelegate.handleGcmMessage(this, bundle)) {
+ if (MmaDelegate.handleGcmMessage(this, from, bundle)) {
return;
}
ThreadUtils.postToBackgroundThread(new Runnable() {
@Override
public void run() {
PushService.getInstance(GcmMessageListenerService.this).onMessageReceived(
GcmMessageListenerService.this, bundle);
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaDelegate.java
@@ -12,19 +12,21 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.Log;
+import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.Experiments;
import org.mozilla.gecko.MmaConstants;
import org.mozilla.gecko.PrefsHelper;
+import org.mozilla.gecko.R;
import org.mozilla.gecko.Tab;
import org.mozilla.gecko.Tabs;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.switchboard.SwitchBoard;
import org.mozilla.gecko.util.ContextUtils;
import java.lang.ref.WeakReference;
@@ -77,17 +79,18 @@ public class MmaDelegate {
if (pref.equals(KEY_PREF_BOOLEAN_MMA_ENABLED)) {
Log.d(TAG, "prefValue() called with: pref = [" + pref + "], value = [" + value + "]");
if (value) {
// Since user attributes are gathered in Fennec, not in MMA implementation,
// we gather the information here then pass to mmaHelper.init()
// Note that generateUserAttribute always return a non null HashMap.
Map<String, Object> attributes = gatherUserAttributes(activity);
-
+ mmaHelper.setGcmSenderId(getSenderIds());
+ mmaHelper.setCustomIcon(R.drawable.ic_status_logo);
mmaHelper.init(activity, attributes);
if (!isDefaultBrowser(activity)) {
mmaHelper.event(MmaDelegate.LAUNCH_BUT_NOT_DEFAULT_BROWSER);
}
isGeckoPrefOn = true;
} else {
isGeckoPrefOn = false;
@@ -151,13 +154,16 @@ public class MmaDelegate {
// No default is set
return false;
}
final String packageName = info.activityInfo.packageName;
return (TextUtils.equals(packageName, context.getPackageName()));
}
- public static boolean handleGcmMessage(@NonNull Context context, @NonNull Bundle bundle) {
- return mmaHelper.handleGcmMessage(context, bundle);
+ public static boolean handleGcmMessage(@NonNull Context context, String from, @NonNull Bundle bundle) {
+ return mmaHelper.handleGcmMessage(context, from, bundle);
}
+ public static String getSenderIds() {
+ return AppConstants.MOZ_ANDROID_GCM_SENDERID + mmaHelper.getMmaSenderId();
+ }
}
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaInterface.java
@@ -5,27 +5,34 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.mma;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.CheckResult;
+import android.support.annotation.DrawableRes;
import java.util.Map;
public interface MmaInterface {
void init(Activity Activity, Map<String, ?> attributes);
+ void setGcmSenderId(String senderIds);
+
+ void setCustomIcon(@DrawableRes int iconResId);
+
void start(Context context);
void event(String mmaEvent);
void event(String mmaEvent, double value);
void stop();
- @CheckResult boolean handleGcmMessage(Context context, Bundle bundle);
+ @CheckResult boolean handleGcmMessage(Context context, String from, Bundle bundle);
+
+ String getMmaSenderId();
}
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaLeanplumImp.java
@@ -6,27 +6,27 @@
package org.mozilla.gecko.mma;
import android.app.Activity;
import android.app.Notification;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.support.annotation.DrawableRes;
import android.support.v4.app.NotificationCompat;
import com.leanplum.Leanplum;
import com.leanplum.LeanplumActivityHelper;
import com.leanplum.LeanplumPushNotificationCustomizer;
import com.leanplum.LeanplumPushService;
import com.leanplum.internal.Constants;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.MmaConstants;
-import org.mozilla.gecko.R;
import java.util.Map;
import java.util.UUID;
public class MmaLeanplumImp implements MmaInterface {
private static final String KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID = "android.not_a_preference.leanplum.device_id";
@@ -49,25 +49,16 @@ public class MmaLeanplumImp implements M
final SharedPreferences sharedPreferences = activity.getPreferences(0);
String deviceId = sharedPreferences.getString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, null);
if (deviceId == null) {
deviceId = UUID.randomUUID().toString();
sharedPreferences.edit().putString(KEY_ANDROID_PREF_STRING_LEANPLUM_DEVICE_ID, deviceId).apply();
}
Leanplum.setDeviceId(deviceId);
- LeanplumPushService.setGcmSenderId(AppConstants.MOZ_ANDROID_GCM_SENDERID);
- LeanplumPushService.setCustomizer(new LeanplumPushNotificationCustomizer() {
- @Override
- public void customize(NotificationCompat.Builder builder, Bundle notificationPayload) {
- builder.setSmallIcon(R.drawable.ic_status_logo);
- builder.setDefaults(Notification.DEFAULT_SOUND);
- }
-
- });
if (attributes != null) {
Leanplum.start(activity, attributes);
} else {
Leanplum.start(activity);
}
// this is special to Leanplum. Since we defer LeanplumActivityHelper's onResume call till
// switchboard completes loading. We miss the call to LeanplumActivityHelper.onResume.
@@ -82,16 +73,33 @@ public class MmaLeanplumImp implements M
@Override
public void run() {
LeanplumActivityHelper.onResume(activity);
}
});
}
@Override
+ public void setGcmSenderId(String senderIds) {
+ LeanplumPushService.setGcmSenderId(senderIds);
+ }
+
+ @Override
+ public void setCustomIcon(@DrawableRes final int iconResId) {
+ LeanplumPushService.setCustomizer(new LeanplumPushNotificationCustomizer() {
+ @Override
+ public void customize(NotificationCompat.Builder builder, Bundle notificationPayload) {
+ builder.setSmallIcon(iconResId);
+ builder.setDefaults(Notification.DEFAULT_SOUND);
+ }
+
+ });
+ }
+
+ @Override
public void start(Context context) {
}
@Override
public void event(String leanplumEvent) {
Leanplum.track(leanplumEvent);
@@ -104,17 +112,22 @@ public class MmaLeanplumImp implements M
}
@Override
public void stop() {
Leanplum.stop();
}
@Override
- public boolean handleGcmMessage(Context context, Bundle bundle) {
- if (bundle.containsKey(Constants.Keys.PUSH_MESSAGE_TEXT)) {
+ public boolean handleGcmMessage(Context context, String from, Bundle bundle) {
+ if (from != null && from.equals(MmaConstants.MOZ_MMA_SENDER_ID) && bundle.containsKey(Constants.Keys.PUSH_MESSAGE_TEXT)) {
LeanplumPushService.handleNotification(context, bundle);
return true;
}
return false;
}
+ @Override
+ public String getMmaSenderId() {
+ return "," + MmaConstants.MOZ_MMA_SENDER_ID;
+ }
+
}
--- a/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
+++ b/mobile/android/base/java/org/mozilla/gecko/mma/MmaStubImp.java
@@ -4,27 +4,38 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.mma;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
+import android.support.annotation.DrawableRes;
import java.util.Map;
public class MmaStubImp implements MmaInterface {
@Override
public void init(Activity activity, Map<String, ?> attributes) {
}
@Override
+ public void setGcmSenderId(String senderIds) {
+
+ }
+
+ @Override
+ public void setCustomIcon(@DrawableRes int iconResId) {
+
+ }
+
+ @Override
public void start(Context context) {
}
@Override
public void event(String leanplumEvent) {
}
@@ -35,13 +46,18 @@ public class MmaStubImp implements MmaIn
}
@Override
public void stop() {
}
@Override
- public boolean handleGcmMessage(Context context, Bundle bundle) {
+ public boolean handleGcmMessage(Context context, String from, Bundle bundle) {
return false;
}
+ @Override
+ public String getMmaSenderId() {
+ return "";
+ }
+
}
--- a/mobile/android/base/java/org/mozilla/gecko/push/PushManager.java
+++ b/mobile/android/base/java/org/mozilla/gecko/push/PushManager.java
@@ -7,16 +7,17 @@ package org.mozilla.gecko.push;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import org.json.JSONObject;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.gcm.GcmTokenClient;
+import org.mozilla.gecko.mma.MmaDelegate;
import org.mozilla.gecko.push.autopush.AutopushClientException;
import org.mozilla.gecko.util.ThreadUtils;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.Map;
@@ -238,17 +239,17 @@ public class PushManager {
if (registration == null || registration.autopushEndpoint == null) {
Log.i(LOG_TAG, "Cannot advance to registered: registration needs configuration.");
throw new ProfileNeedsConfigurationException();
}
return advanceRegistration(registration, profileName, now);
}
protected @NonNull PushRegistration advanceRegistration(final PushRegistration registration, final @NonNull String profileName, final long now) throws AutopushClientException, PushClient.LocalException, GcmTokenClient.NeedsGooglePlayServicesException, IOException {
- final Fetched gcmToken = gcmClient.getToken(AppConstants.MOZ_ANDROID_GCM_SENDERID, registration.debug);
+ final Fetched gcmToken = gcmClient.getToken(MmaDelegate.getSenderIds(), registration.debug);
final PushClient pushClient = pushClientFactory.getPushClient(registration.autopushEndpoint, registration.debug);
if (registration.uaid.value == null) {
if (registration.debug) {
Log.i(LOG_TAG, "No uaid; requesting from autopush endpoint: " + registration.autopushEndpoint);
} else {
Log.i(LOG_TAG, "No uaid: requesting from autopush endpoint.");
@@ -290,17 +291,17 @@ public class PushManager {
public void invalidateGcmToken() {
gcmClient.invalidateToken();
}
public void startup(long now) {
try {
Log.i(LOG_TAG, "Startup: requesting GCM token.");
- gcmClient.getToken(AppConstants.MOZ_ANDROID_GCM_SENDERID, false); // For side-effects.
+ gcmClient.getToken(MmaDelegate.getSenderIds(), false); // For side-effects.
} catch (GcmTokenClient.NeedsGooglePlayServicesException e) {
// Requires user intervention. At App startup, we don't want to address this. In
// response to user activity, we do want to try to have the user address this.
Log.w(LOG_TAG, "Startup: needs Google Play Services. Ignoring until GCM is requested in response to user activity.");
return;
} catch (IOException e) {
// We're temporarily unable to get a GCM token. There's nothing to be done; we'll
// try to advance the App's state in response to user activity or at next startup.