Bug 1568674 Leanplum startup problem in Fennec 68.0 r=VladBaicu

Enabled bidirectional realtime variable updates for production mode.

Differential Revision: https://phabricator.services.mozilla.com/D41231

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrei Lazar 2019-08-13 14:00:13 +00:00
parent f3d824c187
commit 3045c46408
8 changed files with 30 additions and 62 deletions

View File

@ -15,6 +15,7 @@ import android.support.annotation.NonNull;
import org.mozilla.gecko.AppConstants;
import org.mozilla.gecko.BrowserApp;
import org.mozilla.gecko.Experiments;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.MmaConstants;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.R;
@ -109,6 +110,7 @@ public class MmaDelegate {
}
mmaHelper.setDeviceId(deviceId);
PrefsHelper.setPref(GeckoPreferences.PREFS_MMA_DEVICE_ID, deviceId);
mmaHelper.setToken(GeckoSharedPrefs.forApp(applicationContext).getString("gcm_token", ""));
// above two config setup required to be invoked before mmaHelper.init.
mmaHelper.init(activity, attributes);

View File

@ -32,6 +32,8 @@ public interface MmaInterface {
void stop();
void setToken(String token);
@CheckResult boolean handleGcmMessage(Context context, String from, Bundle bundle);
void setDeviceId(@NonNull String deviceId);

View File

@ -160,6 +160,11 @@ public class MmaLeanplumImp implements MmaInterface {
Leanplum.setDeviceId(deviceId);
}
@Override
public void setToken(@NonNull String token) {
Leanplum.setToken(token);
}
@Override
public PanelConfig getPanelConfig(@NonNull Context context, PanelConfig.TYPE type, final boolean useLocalValues) {
if (useLocalValues) {

View File

@ -48,6 +48,11 @@ public class MmaStubImp implements MmaInterface {
}
@Override
public void setToken(String token) {
}
@Override
public boolean handleGcmMessage(Context context, String from, Bundle bundle) {
return false;

View File

@ -104,6 +104,7 @@ public class Leanplum {
private static RegisterDeviceFinishedCallback registerDeviceFinishedHandler;
private static LeanplumDeviceIdMode deviceIdMode = LeanplumDeviceIdMode.MD5_MAC_ADDRESS;
private static String customDeviceId;
private static String customToken;
private static String defaultChannelId;
private static boolean userSpecifiedDeviceId;
private static boolean initializedMessageTemplates = false;
@ -173,6 +174,10 @@ public class Leanplum {
Constants.hashFilesToDetermineModifications = enabled;
}
public static void setToken(String token) {
customToken = token;
}
/**
* Optional. Whether to enable file uploading in development mode.
*
@ -634,11 +639,7 @@ public class Leanplum {
*/
private static void checkAndStartNotificationsModules() {
if (Util.hasPlayServices()) {
try {
Class.forName(LEANPLUM_PUSH_SERVICE).getDeclaredMethod("onStart")
.invoke(null);
} catch (Throwable ignored) {
}
LeanplumPushService.onStart();
} else {
Log.i("No valid Google Play Services APK found.");
}
@ -696,6 +697,8 @@ public class Leanplum {
params.put(Constants.Params.DEVICE_SYSTEM_VERSION, Util.getSystemVersion());
if (!TextUtils.isEmpty(registrationId)) {
params.put(Constants.Params.DEVICE_PUSH_TOKEN, registrationId);
} else if (!TextUtils.isEmpty(customToken)) {
params.put(Constants.Params.DEVICE_PUSH_TOKEN, customToken);
}
params.put(Constants.Keys.TIMEZONE, localTimeZone.getID());
params.put(Constants.Keys.TIMEZONE_OFFSET_SECONDS, Integer.toString(timezoneOffsetSeconds));
@ -848,10 +851,8 @@ public class Leanplum {
}
try {
Class.forName(LEANPLUM_NOTIFICATION_CHANNEL)
.getDeclaredMethod("configureChannels", Context.class, JSONArray.class,
JSONArray.class, String.class).invoke(new Object(), context,
notificationGroups, notificationChannels, defaultNotificationChannel);
LeanplumNotificationChannel.configureChannels(context, notificationGroups,
notificationChannels, defaultNotificationChannel);
} catch (Throwable ignored) {
}
}
@ -880,8 +881,6 @@ public class Leanplum {
parseVariantDebugInfo(response);
// Allow bidirectional realtime variable updates.
if (Constants.isDevelopmentModeEnabled) {
final Context currentContext = (
LeanplumActivityHelper.currentActivity != context &&
LeanplumActivityHelper.currentActivity != null) ?
@ -940,7 +939,7 @@ public class Leanplum {
// Check for updates.
final String latestVersion = response.optString(Constants.Keys.LATEST_VERSION, null);
if (isRegistered && latestVersion != null) {
if (isRegistered && latestVersion != null && Constants.isDevelopmentModeEnabled) {
Log.i("An update to Leanplum Android SDK, " + latestVersion +
", is available. Go to leanplum.com to download it.");
}
@ -969,7 +968,6 @@ public class Leanplum {
if (isRegistered) {
LeanplumInternal.onHasStartedAndRegisteredAsDeveloper();
}
}
LeanplumInternal.moveToForeground();
startHeartbeat();
} catch (Throwable t) {

View File

@ -89,14 +89,8 @@ abstract class LeanplumCloudMessagingProvider {
return;
}
LeanplumCloudMessagingProvider.registrationId = registrationId;
// Check if received push notification token is different from stored one and send new one to
// server.
if (!LeanplumCloudMessagingProvider.registrationId.equals(SharedPreferencesUtil.getString(
context, Constants.Defaults.LEANPLUM_PUSH, Constants.Defaults.PROPERTY_REGISTRATION_ID))) {
Log.i("Device registered for push notifications with registration token", registrationId);
storePreferences(context.getApplicationContext());
sendRegistrationIdToBackend(LeanplumCloudMessagingProvider.registrationId);
}
storePreferences(context.getApplicationContext());
sendRegistrationIdToBackend(registrationId);
}
/**

View File

@ -631,7 +631,7 @@ class LeanplumNotificationChannel {
* @param notificationChannels Notification channels.
* @param defaultNotificationChannel Default channel details.
*/
static void configureChannels(Context context, JSONArray notificationGroups,
public static void configureChannels(Context context, JSONArray notificationGroups,
JSONArray notificationChannels, String defaultNotificationChannel) {
// Configure notification channels and groups
configureNotificationGroups(

View File

@ -109,13 +109,7 @@ public class LeanplumPushService {
* multiple sender IDs, use {@link LeanplumPushService#setGcmSenderIds}.
*/
public static void setGcmSenderId(String senderId) {
try {
Class.forName(COM_LEANPLUM_GCM_PROVIDER).getDeclaredMethod("setSenderId",
String.class).invoke(new Object(), senderId);
} catch (Throwable throwable) {
Log.e("Couldn't invoke a LeanplumGcmProvider.setGcmSenderId method, please be " +
"sure you include LeanplumGCM module.", throwable);
}
LeanplumGcmProvider.setSenderId(senderId);
}
/**
@ -744,39 +738,7 @@ public class LeanplumPushService {
* Call this when Leanplum starts. This method will call by reflection from AndroidSDKCore.
*/
static void onStart() {
Class leanplumGcmPushServiceClass = null;
Class leanplumFcmPushServiceClass = null;
try {
leanplumGcmPushServiceClass = Class.forName(LEANPLUM_PUSH_SERVICE_GCM);
} catch (Throwable ignored) {
}
try {
leanplumFcmPushServiceClass = Class.forName(LEANPLUM_PUSH_SERVICE_FCM);
} catch (Throwable ignored) {
}
if (leanplumGcmPushServiceClass != null && leanplumFcmPushServiceClass != null) {
Log.e("Leanplum does not support leanplum-gcm and leanplum-fcm library at the " +
"same time. To support Leanplum GCM and Location services modify your build.gradle by " +
"including only implementation 'com.leanplum:leanplum:+' " +
"To support only GCM services, use implementation 'com.leanplum:leanplum-gcm:+' " +
"For FCM services include implementation 'com.leanplum:leanplum-fcm:+'" +
" If you wish to use Leanplum FCM and Location services you also need to include " +
"implementation 'com.leanplum:leanplum-location:+'.");
} else if (leanplumGcmPushServiceClass != null) {
try {
leanplumGcmPushServiceClass.getDeclaredMethod("onStart").invoke(null);
} catch (Throwable ignored) {
}
} else if (leanplumFcmPushServiceClass != null) {
try {
leanplumFcmPushServiceClass.getDeclaredMethod("onStart").invoke(null);
} catch (Throwable ignored) {
}
}
LeanplumPushServiceGcm.onStart();
}
/**