[android] Turn on/off Alohalytics events logging from app’s settings.

This commit is contained in:
Alex Zolotarev 2015-09-01 21:42:53 -07:00
parent 30eb4033fa
commit 79469bc946
2 changed files with 20 additions and 6 deletions

View file

@ -17,6 +17,7 @@ import com.mapswithme.util.Constants;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Yota;
import com.mapswithme.util.statistics.AlohaHelper;
import com.mapswithme.util.statistics.Statistics;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseInstallation;
@ -284,6 +285,16 @@ public class MwmApplication extends android.app.Application implements ActiveCou
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);
}
}
}

View file

@ -282,20 +282,23 @@ public enum Statistics
public boolean isStatisticsEnabled()
{
boolean isStatisticsEnabledByDefault = true;
if (BuildConfig.DEBUG)
isStatisticsEnabledByDefault = false;
return MwmApplication.get().nativeGetBoolean(KEY_STAT_ENABLED, isStatisticsEnabledByDefault);
return MwmApplication.get().nativeGetBoolean(KEY_STAT_ENABLED, !BuildConfig.DEBUG);
}
public void setStatEnabled(boolean isEnabled)
{
MwmApplication.get().nativeSetBoolean(KEY_STAT_ENABLED, 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(mEventBuilder
.setName(EventName.STATISTICS_STATUS_CHANGED + " " + MwmApplication.get().getFirstInstallFlavor())
.setName(EventName.STATISTICS_STATUS_CHANGED + " " + theApp.getFirstInstallFlavor())
.addParam(EventParam.ENABLED, String.valueOf(isEnabled))
.buildEvent());
if (isEnabled)
org.alohalytics.Statistics.enable(theApp);
else
org.alohalytics.Statistics.disable(theApp);
}
}