[android] Fixed the sending gps tracks

[android] Core reads the 'StatisticsEnabled' setting from the settings.ini. And problem was that the mentioned setting wasn't stored in settings.ini because of write permission migh not be granted at that moment. Now, the setting is set to setting.ini safely, i.e. when all needed permissions are granted.
This commit is contained in:
Александр Зацепин 2017-08-07 18:10:23 +03:00 committed by Arsentiy Milchakov
parent b9c70406cb
commit 680efe2f90
5 changed files with 25 additions and 13 deletions

View file

@ -13,9 +13,6 @@ import android.support.multidex.MultiDex;
import android.text.TextUtils;
import android.util.Log;
import java.io.File;
import java.util.List;
import com.crashlytics.android.Crashlytics;
import com.crashlytics.android.ndk.CrashlyticsNdk;
import com.mapswithme.maps.background.AppBackgroundTracker;
@ -35,6 +32,7 @@ import com.mapswithme.util.Constants;
import com.mapswithme.util.Counters;
import com.mapswithme.util.CrashlyticsUtils;
import com.mapswithme.util.PermissionsUtils;
import com.mapswithme.util.SharedPropertiesUtils;
import com.mapswithme.util.ThemeSwitcher;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.Utils;
@ -47,6 +45,9 @@ import com.my.tracker.MyTrackerParams;
import com.pushwoosh.PushManager;
import io.fabric.sdk.android.Fabric;
import java.io.File;
import java.util.List;
public class MwmApplication extends Application
{
private Logger mLogger;
@ -194,6 +195,8 @@ public class MwmApplication extends Application
nativeInitPlatform(getApkPath(), getStoragePath(settingsPath), getTempPath(), getObbGooglePath(),
BuildConfig.FLAVOR, BuildConfig.BUILD_TYPE, UiUtils.isTablet());
Config.setStatisticsEnabled(SharedPropertiesUtils.isStatisticsEnabled());
@SuppressWarnings("unused")
Statistics s = Statistics.INSTANCE;

View file

@ -36,6 +36,7 @@ import com.mapswithme.maps.sound.LanguageData;
import com.mapswithme.maps.sound.TtsPlayer;
import com.mapswithme.util.Config;
import com.mapswithme.util.NetworkPolicy;
import com.mapswithme.util.SharedPropertiesUtils;
import com.mapswithme.util.ThemeSwitcher;
import com.mapswithme.util.UiUtils;
import com.mapswithme.util.concurrency.UiThread;
@ -595,7 +596,7 @@ public class SettingsPrefsFragment extends BaseXmlSettingsFragment
if (pref == null)
return;
((TwoStatePreference)pref).setChecked(Config.isStatisticsEnabled());
((TwoStatePreference)pref).setChecked(SharedPropertiesUtils.isStatisticsEnabled());
pref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener()
{
@Override

View file

@ -24,7 +24,7 @@ public final class Config
private static final String KEY_DOWNLOADER_AUTO = "AutoDownloadEnabled";
private static final String KEY_PREF_ZOOM_BUTTONS = "ZoomButtonsEnabled";
private static final String KEY_PREF_STATISTICS = "StatisticsEnabled";
static final String KEY_PREF_STATISTICS = "StatisticsEnabled";
private static final String KEY_PREF_USE_GS = "UseGoogleServices";
private static final String KEY_MISC_DISCLAIMER_ACCEPTED = "IsDisclaimerApproved";
@ -170,14 +170,9 @@ public final class Config
setBool(KEY_PREF_ZOOM_BUTTONS, show);
}
public static boolean isStatisticsEnabled()
{
return MwmApplication.prefs().getBoolean(KEY_PREF_STATISTICS, true);
}
public static void setStatisticsEnabled(boolean enabled)
{
MwmApplication.prefs().edit().putBoolean(KEY_PREF_STATISTICS, enabled).apply();
setBool(KEY_PREF_STATISTICS, enabled);
}
public static boolean useGoogleServices()

View file

@ -5,6 +5,8 @@ import android.preference.PreferenceManager;
import com.mapswithme.maps.MwmApplication;
import com.mapswithme.maps.R;
import static com.mapswithme.util.Config.KEY_PREF_STATISTICS;
public final class SharedPropertiesUtils
{
public static boolean isShowcaseSwitchedOnLocal()
@ -13,6 +15,16 @@ public final class SharedPropertiesUtils
.getBoolean(MwmApplication.get().getString(R.string.pref_showcase_switched_on), false);
}
public static boolean isStatisticsEnabled()
{
return MwmApplication.prefs().getBoolean(KEY_PREF_STATISTICS, true);
}
public static void setStatisticsEnabled(boolean enabled)
{
MwmApplication.prefs().edit().putBoolean(KEY_PREF_STATISTICS, enabled).apply();
}
//Utils class
private SharedPropertiesUtils()
{

View file

@ -34,6 +34,7 @@ import com.mapswithme.util.BatteryState;
import com.mapswithme.util.Config;
import com.mapswithme.util.ConnectionState;
import com.mapswithme.util.Counters;
import com.mapswithme.util.SharedPropertiesUtils;
import com.my.tracker.MyTracker;
import java.lang.annotation.Retention;
@ -353,8 +354,7 @@ public enum Statistics
Statistics()
{
mEnabled = Config.isStatisticsEnabled();
Config.setStatisticsEnabled(mEnabled);
mEnabled = SharedPropertiesUtils.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)
@ -445,6 +445,7 @@ public enum Statistics
public void setStatEnabled(boolean isEnabled)
{
SharedPropertiesUtils.setStatisticsEnabled(isEnabled);
Config.setStatisticsEnabled(isEnabled);
// We track if user turned on/off statistics to understand data better.