зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1361664 - Part1. Udate MMA API, make init() accept activity. r=maliu
MozReview-Commit-ID: AcfoeCPV8SV --HG-- extra : rebase_source : 6441ed54f9e19b6c384281084699e5247ec5d3f6
This commit is contained in:
Родитель
1adf4c5700
Коммит
41b293dfc2
|
@ -895,7 +895,7 @@ public class BrowserApp extends GeckoApp
|
||||||
if (SwitchBoard.isInExperiment(context, Experiments.LEANPLUM) &&
|
if (SwitchBoard.isInExperiment(context, Experiments.LEANPLUM) &&
|
||||||
GeckoPreferences.getBooleanPref(context, GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
|
GeckoPreferences.getBooleanPref(context, GeckoPreferences.PREFS_HEALTHREPORT_UPLOAD_ENABLED, true)) {
|
||||||
// Do LeanPlum start/init here
|
// Do LeanPlum start/init here
|
||||||
MmaDelegate.init(BrowserApp.this.getApplication());
|
MmaDelegate.init(BrowserApp.this);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
package org.mozilla.gecko.mma;
|
package org.mozilla.gecko.mma;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.mozilla.gecko.MmaConstants;
|
import org.mozilla.gecko.MmaConstants;
|
||||||
import org.mozilla.gecko.PrefsHelper;
|
import org.mozilla.gecko.PrefsHelper;
|
||||||
|
@ -15,35 +15,50 @@ import org.mozilla.gecko.PrefsHelper;
|
||||||
|
|
||||||
public class MmaDelegate {
|
public class MmaDelegate {
|
||||||
|
|
||||||
private static final String ENABLE_PREF = "mma.enabled";
|
private static final String TAG = "MmaDelegate";
|
||||||
|
private static final String KEY_PREF_BOOLEAN_MMA_ENABLED = "mma.enabled";
|
||||||
|
private static final String[] PREFS = { KEY_PREF_BOOLEAN_MMA_ENABLED };
|
||||||
|
|
||||||
|
|
||||||
|
private static boolean isGeckoPrefOn = false;
|
||||||
private static MmaInterface mmaHelper = MmaConstants.getMma();
|
private static MmaInterface mmaHelper = MmaConstants.getMma();
|
||||||
|
|
||||||
private static final String[] prefs = { ENABLE_PREF };
|
|
||||||
|
|
||||||
|
public static void init(Activity activity) {
|
||||||
public static void init(Application application) {
|
setupPrefHandler(activity);
|
||||||
setupPrefHandler(application);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void stop() {
|
public static void stop() {
|
||||||
mmaHelper.stop();
|
mmaHelper.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupPrefHandler(final Application application) {
|
private static void setupPrefHandler(final Activity activity) {
|
||||||
PrefsHelper.PrefHandler handler = new PrefsHelper.PrefHandlerBase() {
|
PrefsHelper.PrefHandler handler = new PrefsHelper.PrefHandlerBase() {
|
||||||
@Override
|
@Override
|
||||||
public void prefValue(String pref, boolean value) {
|
public void prefValue(String pref, boolean value) {
|
||||||
if (pref.equals(ENABLE_PREF)) {
|
if (pref.equals(KEY_PREF_BOOLEAN_MMA_ENABLED)) {
|
||||||
|
Log.d(TAG, "prefValue() called with: pref = [" + pref + "], value = [" + value + "]");
|
||||||
if (value) {
|
if (value) {
|
||||||
mmaHelper.init(application);
|
mmaHelper.init(activity);
|
||||||
|
isGeckoPrefOn = true;
|
||||||
} else {
|
} else {
|
||||||
mmaHelper.stop();
|
isGeckoPrefOn = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
PrefsHelper.addObserver(prefs, handler);
|
PrefsHelper.addObserver(PREFS, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void track(String event) {
|
||||||
|
if (isGeckoPrefOn) {
|
||||||
|
mmaHelper.track(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void track(String event, long value) {
|
||||||
|
if (isGeckoPrefOn) {
|
||||||
|
mmaHelper.track(event, value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,18 +6,19 @@
|
||||||
|
|
||||||
package org.mozilla.gecko.mma;
|
package org.mozilla.gecko.mma;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
public interface MmaInterface {
|
public interface MmaInterface {
|
||||||
void init(Application application);
|
void init(Activity Activity);
|
||||||
|
|
||||||
void start(Context context);
|
void start(Context context);
|
||||||
|
|
||||||
void track(String leanplumEvent);
|
void track(String mmaEvent);
|
||||||
|
|
||||||
void track(String leanplumEvent, double value);
|
void track(String mmaEvent, double value);
|
||||||
|
|
||||||
void stop();
|
void stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
package org.mozilla.gecko.mma;
|
package org.mozilla.gecko.mma;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
@ -13,16 +14,21 @@ import com.leanplum.Leanplum;
|
||||||
import com.leanplum.LeanplumActivityHelper;
|
import com.leanplum.LeanplumActivityHelper;
|
||||||
import com.leanplum.annotations.Parser;
|
import com.leanplum.annotations.Parser;
|
||||||
|
|
||||||
|
import org.mozilla.gecko.ActivityHandlerHelper;
|
||||||
import org.mozilla.gecko.AppConstants;
|
import org.mozilla.gecko.AppConstants;
|
||||||
import org.mozilla.gecko.MmaConstants;
|
import org.mozilla.gecko.MmaConstants;
|
||||||
|
import org.mozilla.gecko.util.ContextUtils;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class MmaLeanplumImp implements MmaInterface {
|
public class MmaLeanplumImp implements MmaInterface {
|
||||||
@Override
|
@Override
|
||||||
public void init(Application application) {
|
public void init(Activity activity) {
|
||||||
Leanplum.setApplicationContext(application);
|
Leanplum.setApplicationContext(activity.getApplicationContext());
|
||||||
Parser.parseVariables(application);
|
|
||||||
LeanplumActivityHelper.enableLifecycleCallbacks(application);
|
LeanplumActivityHelper.enableLifecycleCallbacks(activity.getApplication());
|
||||||
|
|
||||||
if (AppConstants.MOZILLA_OFFICIAL) {
|
if (AppConstants.MOZILLA_OFFICIAL) {
|
||||||
Leanplum.setAppIdForProductionMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
|
Leanplum.setAppIdForProductionMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
|
||||||
|
@ -30,7 +36,18 @@ public class MmaLeanplumImp implements MmaInterface {
|
||||||
Leanplum.setAppIdForDevelopmentMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
|
Leanplum.setAppIdForDevelopmentMode(MmaConstants.MOZ_LEANPLUM_SDK_CLIENTID, MmaConstants.MOZ_LEANPLUM_SDK_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
Leanplum.start(application);
|
|
||||||
|
Map<String, Object> attributes = new HashMap<>();
|
||||||
|
boolean installedFocus = ContextUtils.isPackageInstalled(activity, "org.mozilla.focus");
|
||||||
|
boolean installedKlar = ContextUtils.isPackageInstalled(activity, "org.mozilla.klar");
|
||||||
|
if (installedFocus || installedKlar) {
|
||||||
|
attributes.put("focus", "installed");
|
||||||
|
}
|
||||||
|
Leanplum.start(activity, attributes);
|
||||||
|
Leanplum.track("Launch");
|
||||||
|
// this is special to Leanplum. Since we defer LeanplumActivityHelper's onResume call till
|
||||||
|
// switchboard completes loading, we manually call it here.
|
||||||
|
LeanplumActivityHelper.onResume(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
|
|
||||||
package org.mozilla.gecko.mma;
|
package org.mozilla.gecko.mma;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
public class MmaStubImp implements MmaInterface {
|
public class MmaStubImp implements MmaInterface {
|
||||||
@Override
|
@Override
|
||||||
public void init(Application application) {
|
public void init(Activity activity) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -209,7 +209,7 @@ public class LeanplumActivityHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void onResume(Activity activity) {
|
public static void onResume(Activity activity) {
|
||||||
isActivityPaused = false;
|
isActivityPaused = false;
|
||||||
currentActivity = activity;
|
currentActivity = activity;
|
||||||
if (LeanplumInternal.isPaused() || LeanplumInternal.hasStartedInBackground()) {
|
if (LeanplumInternal.isPaused() || LeanplumInternal.hasStartedInBackground()) {
|
||||||
|
|
Загрузка…
Ссылка в новой задаче