Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Zolotarev <alex@maps.me>2015-09-06 05:31:13 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:03:53 +0300
commit5e3412ca24202c52afe98228b35916bce80b78e4 (patch)
treefa2ad2fd3bea9fde7849b86ebfa9ed7441d1017b /android
parent06a85edccdf3245ab2290d54a024277fe1c6cc3c (diff)
[android] Correctly turn off all 3party statistics engines when user disables them in settings.
Diffstat (limited to 'android')
-rw-r--r--android/src/com/mapswithme/maps/MwmApplication.java54
-rw-r--r--android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java2
-rw-r--r--android/src/com/mapswithme/maps/settings/SettingsActivity.java2
-rw-r--r--android/src/com/mapswithme/util/MultipleTrackerReferrerReceiver.java2
-rw-r--r--android/src/com/mapswithme/util/statistics/Statistics.java94
5 files changed, 85 insertions, 69 deletions
diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java
index 298487f365..60d62a342e 100644
--- a/android/src/com/mapswithme/maps/MwmApplication.java
+++ b/android/src/com/mapswithme/maps/MwmApplication.java
@@ -22,12 +22,8 @@ import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
import com.parse.SaveCallback;
-import ru.mail.android.mytracker.MRMyTracker;
-import ru.mail.android.mytracker.MRMyTrackerParams;
import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
public class MwmApplication extends android.app.Application implements ActiveCountryTree.ActiveCountryListener
{
@@ -38,10 +34,6 @@ public class MwmApplication extends android.app.Application implements ActiveCou
private static final String LAST_SESSION_TIMESTAMP_SETTING = "LastSessionTimestamp"; // timestamp of last session
private static final String FIRST_INSTALL_VERSION = "FirstInstallVersion";
private static final String FIRST_INSTALL_FLAVOR = "FirstInstallFlavor";
- // for myTracker
- private static final String MY_MAP_DOWNLOAD = "DownloadMap";
- private static final String MY_MAP_UPDATE = "UpdateMap";
- private static final String MY_TOTAL_COUNT = "Count";
// Parse
private static final String PREF_PARSE_DEVICE_TOKEN = "ParseDeviceToken";
private static final String PREF_PARSE_INSTALLATION_ID = "ParseInstallationId";
@@ -50,7 +42,7 @@ public class MwmApplication extends android.app.Application implements ActiveCou
private final Gson mGson = new Gson();
private static SharedPreferences mPrefs;
- private boolean mAreStatsInitialised;
+ private boolean mAreCountersInitialised;
public MwmApplication()
{
@@ -91,16 +83,9 @@ public class MwmApplication extends android.app.Application implements ActiveCou
public void onCountryGroupChanged(int oldGroup, int oldPosition, int newGroup, int newPosition)
{
if (oldGroup == ActiveCountryTree.GROUP_NEW && newGroup == ActiveCountryTree.GROUP_UP_TO_DATE)
- myTrackerTrackMapChange(MY_MAP_DOWNLOAD);
+ Statistics.INSTANCE.myTrackerTrackMapDownload();
else if (oldGroup == ActiveCountryTree.GROUP_OUT_OF_DATE && newGroup == ActiveCountryTree.GROUP_UP_TO_DATE)
- myTrackerTrackMapChange(MY_MAP_UPDATE);
- }
-
- private void myTrackerTrackMapChange(String eventType)
- {
- final Map<String, String> params = new HashMap<>();
- params.put(MY_TOTAL_COUNT, String.valueOf(ActiveCountryTree.getTotalDownloadedCount()));
- MRMyTracker.trackEvent(eventType, params);
+ Statistics.INSTANCE.myTrackerTrackMapUpdate();
}
@Override
@@ -152,19 +137,6 @@ public class MwmApplication extends android.app.Application implements ActiveCou
mPrefs = getSharedPreferences(getString(R.string.pref_file_name), MODE_PRIVATE);
}
- private void initMyTracker()
- {
- MRMyTracker.setDebugMode(BuildConfig.DEBUG);
-
- MRMyTracker.createTracker(getString(R.string.my_tracker_app_id), this);
-
- final MRMyTrackerParams myParams = MRMyTracker.getTrackerParams();
- myParams.setTrackingPreinstallsEnabled(true);
- myParams.setTrackingLaunchEnabled(true);
-
- MRMyTracker.initTracker();
- }
-
public String getApkPath()
{
try
@@ -273,28 +245,14 @@ public class MwmApplication extends android.app.Application implements ActiveCou
});
}
- public void initStats()
+ public void initCounters()
{
- if (!mAreStatsInitialised)
+ if (!mAreCountersInitialised)
{
- mAreStatsInitialised = true;
+ mAreCountersInitialised = true;
updateLaunchNumbers();
updateSessionsNumber();
- initMyTracker();
PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
-
- org.alohalytics.Statistics.setDebugMode(BuildConfig.DEBUG);
- org.alohalytics.Statistics.setup(BuildConfig.STATISTICS_URL, this);
- // One time check for old users who have already disabled statistics in settings.
- // TODO(AlexZ): Remove it in a few releases after September 2, 2015.
- final SharedPreferences prefs = getSharedPreferences("ALOHALYTICS", MODE_PRIVATE);
- final String kAlohalyticsOneTimeStatisticsDisabledCheckKey = "AlohalyticsOneTimeStatisticsDisabledCheck";
- if (!prefs.getBoolean(kAlohalyticsOneTimeStatisticsDisabledCheckKey, false))
- {
- prefs.edit().putBoolean(kAlohalyticsOneTimeStatisticsDisabledCheckKey, true).apply();
- if (!Statistics.INSTANCE.isStatisticsEnabled())
- org.alohalytics.Statistics.disable(this);
- }
}
}
diff --git a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
index 164f31dc4f..e68db48e9d 100644
--- a/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
+++ b/android/src/com/mapswithme/maps/base/BaseMwmFragmentActivity.java
@@ -30,7 +30,7 @@ public class BaseMwmFragmentActivity extends AppCompatActivity
getWindow().clearFlags(android.view.WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
}
- MwmApplication.get().initStats();
+ MwmApplication.get().initCounters();
ViewServer.get(this).addWindow(this);
attachDefaultFragment();
diff --git a/android/src/com/mapswithme/maps/settings/SettingsActivity.java b/android/src/com/mapswithme/maps/settings/SettingsActivity.java
index f1f273de6c..85d4368f4b 100644
--- a/android/src/com/mapswithme/maps/settings/SettingsActivity.java
+++ b/android/src/com/mapswithme/maps/settings/SettingsActivity.java
@@ -56,7 +56,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference
// TODO remove after refactoring to fragments
// this initialisation is necessary hence Activity isn't extended from BaseMwmActivity
// try to prevent possible crash if this is the only activity in application
- MwmApplication.get().initStats();
+ MwmApplication.get().initCounters();
addPreferencesFromResource(R.xml.preferences);
initPreferences();
yotaSetup();
diff --git a/android/src/com/mapswithme/util/MultipleTrackerReferrerReceiver.java b/android/src/com/mapswithme/util/MultipleTrackerReferrerReceiver.java
index 11ce05cf5f..36153c505e 100644
--- a/android/src/com/mapswithme/util/MultipleTrackerReferrerReceiver.java
+++ b/android/src/com/mapswithme/util/MultipleTrackerReferrerReceiver.java
@@ -17,7 +17,7 @@ public class MultipleTrackerReferrerReceiver extends BroadcastReceiver
@Override
public void onReceive(Context context, Intent intent)
{
- MwmApplication.get().initStats();
+ MwmApplication.get().initCounters();
// parse & send referrer to Aloha
try
{
diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java
index 440dc60f72..203c3ac03a 100644
--- a/android/src/com/mapswithme/util/statistics/Statistics.java
+++ b/android/src/com/mapswithme/util/statistics/Statistics.java
@@ -1,6 +1,7 @@
package com.mapswithme.util.statistics;
import android.app.Activity;
+import android.content.Context;
import android.util.Log;
import com.facebook.appevents.AppEventsLogger;
@@ -15,8 +16,10 @@ import com.mapswithme.util.log.SimpleLogger;
import com.mapswithme.util.log.StubLogger;
import java.util.HashMap;
+import java.util.Map;
import ru.mail.android.mytracker.MRMyTracker;
+import ru.mail.android.mytracker.MRMyTrackerParams;
public enum Statistics
{
@@ -84,15 +87,39 @@ public enum Statistics
public static final String RATING = "Rating";
}
+ private static class MyTrackerParams
+ {
+ private static final String MY_MAP_DOWNLOAD = "DownloadMap";
+ private static final String MY_MAP_UPDATE = "UpdateMap";
+ private static final String MY_TOTAL_COUNT = "Count";
+ }
+
+ // Initialized once in constructor and does not change until the process restarts.
+ // In this way we can correctly finish all statistics sessions and completely
+ // avoid their initialization if user has disabled statistics collection.
+ private final boolean mEnabled;
+
Statistics()
{
- configure();
- mLogger.d("Created Statistics instance.");
+ mEnabled = isStatisticsEnabled();
+ final Context context = MwmApplication.get();
+ // At the moment we need special handling for Alohalytics to enable/disable logging of events in core C++ code.
+ if (mEnabled)
+ {
+ org.alohalytics.Statistics.enable(context);
+ mLogger.d("Created Statistics instance.");
+ }
+ else
+ {
+ org.alohalytics.Statistics.disable(context);
+ mLogger.d("Statistics was disabled by user.");
+ }
+ configure(context);
}
private void post(String name)
{
- if (isStatisticsEnabled())
+ if (mEnabled)
FlurryAgent.logEvent(name);
}
@@ -100,7 +127,8 @@ public enum Statistics
{
if (params.length % 2 != 0)
mLogger.e("Even number of parameters is required: key1, value1, key2, value2, ...");
- if (isStatisticsEnabled())
+
+ if (mEnabled)
{
final HashMap<String, String> map = new HashMap<>(params.length);
for (int i = 0; i < params.length - 1; i += 2)
@@ -199,9 +227,29 @@ public enum Statistics
post(eventName);
}
+ public void myTrackerTrackMapDownload()
+ {
+ myTrackerTrackMapChange(MyTrackerParams.MY_MAP_DOWNLOAD);
+ }
+
+ public void myTrackerTrackMapUpdate()
+ {
+ myTrackerTrackMapChange(MyTrackerParams.MY_MAP_UPDATE);
+ }
+
+ private void myTrackerTrackMapChange(String eventType)
+ {
+ if (mEnabled)
+ {
+ final Map<String, String> params = new HashMap<>();
+ params.put(MyTrackerParams.MY_TOTAL_COUNT, String.valueOf(ActiveCountryTree.getTotalDownloadedCount()));
+ MRMyTracker.trackEvent(eventType, params);
+ }
+ }
+
public void startActivity(Activity activity)
{
- if (isStatisticsEnabled())
+ if (mEnabled)
{
FlurryAgent.onStartSession(activity);
AppEventsLogger.activateApp(activity);
@@ -210,18 +258,31 @@ public enum Statistics
}
}
- private void configure()
+ // This method is not called at all if statistics was disabled.
+ private void configure(Context context)
{
- FlurryAgent.setLogLevel(BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR);
- FlurryAgent.setVersionName(BuildConfig.VERSION_NAME);
- FlurryAgent.setCaptureUncaughtExceptions(false);
- android.content.Context context = MwmApplication.get();
- FlurryAgent.init(context, context.getString(R.string.flurry_app_key));
+ if (mEnabled)
+ {
+ FlurryAgent.setLogLevel(BuildConfig.DEBUG ? Log.DEBUG : Log.ERROR);
+ FlurryAgent.setVersionName(BuildConfig.VERSION_NAME);
+ FlurryAgent.setCaptureUncaughtExceptions(false);
+ FlurryAgent.init(context, context.getString(R.string.flurry_app_key));
+
+ MRMyTracker.setDebugMode(BuildConfig.DEBUG);
+ MRMyTracker.createTracker(context.getString(R.string.my_tracker_app_id), context);
+ final MRMyTrackerParams myParams = MRMyTracker.getTrackerParams();
+ myParams.setTrackingPreinstallsEnabled(true);
+ myParams.setTrackingLaunchEnabled(true);
+ MRMyTracker.initTracker();
+
+ org.alohalytics.Statistics.setDebugMode(BuildConfig.DEBUG);
+ org.alohalytics.Statistics.setup(BuildConfig.STATISTICS_URL, context);
+ }
}
public void stopActivity(Activity activity)
{
- if (isStatisticsEnabled())
+ if (mEnabled)
{
FlurryAgent.onEndSession(activity);
AppEventsLogger.deactivateApp(activity);
@@ -230,6 +291,8 @@ public enum Statistics
}
}
+ // This method is used to display user setting's preference and initialize
+ // actual state of statistics (see mEnabled in constructor).
public boolean isStatisticsEnabled()
{
return MwmApplication.get().nativeGetBoolean(KEY_STAT_ENABLED, !BuildConfig.DEBUG);
@@ -238,14 +301,9 @@ public enum Statistics
public void setStatEnabled(boolean isEnabled)
{
final MwmApplication theApp = MwmApplication.get();
- theApp.nativeSetBoolean(KEY_STAT_ENABLED, isEnabled);
// We track if user turned on/off statistics to understand data better.
post(EventName.STATISTICS_STATUS_CHANGED + " " + theApp.getFirstInstallFlavor(),
new String[]{EventParam.ENABLED, String.valueOf(isEnabled)});
-
- if (isEnabled)
- org.alohalytics.Statistics.enable(theApp);
- else
- org.alohalytics.Statistics.disable(theApp);
+ theApp.nativeSetBoolean(KEY_STAT_ENABLED, isEnabled);
}
}