From 4a258481362a15a4f9b93d796453f5e04e862207 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Thu, 22 Oct 2015 10:02:34 +0200 Subject: [PATCH] Add installation date to maps request to the server --- .../src/net/osmand/plus/AppInitializer.java | 10 ++++ .../net/osmand/plus/ContextMenuAdapter.java | 2 - .../src/net/osmand/plus/OsmandSettings.java | 52 ++++++++++--------- .../download/DownloadOsmandIndexesHelper.java | 16 +++++- 4 files changed, 52 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 521c13ccf8..2629aa01d2 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -57,6 +57,8 @@ public class AppInitializer implements IProgress { public static final boolean TIPS_AND_TRICKS = false; private static final String FIRST_TIME_APP_RUN = "FIRST_TIME_APP_RUN"; //$NON-NLS-1$ + protected static final String NUMBER_OF_STARTS = "NUMBER_OF_STARTS"; //$NON-NLS-1$ + protected static final String FIRST_INSTALLED = "FIRST_INSTALLED"; //$NON-NLS-1$ private static final String VECTOR_INDEXES_CHECK = "VECTOR_INDEXES_CHECK"; //$NON-NLS-1$ private static final String VERSION_INSTALLED = "VERSION_INSTALLED"; //$NON-NLS-1$ private static final String EXCEPTION_FILE_SIZE = "EXCEPTION_FS"; //$NON-NLS-1$ @@ -112,6 +114,14 @@ public class AppInitializer implements IProgress { return; } SharedPreferences pref = activity.getPreferences(Context.MODE_WORLD_WRITEABLE); + if(!pref.contains(NUMBER_OF_STARTS)) { + pref.edit().putInt(NUMBER_OF_STARTS, 1).commit(); + } else { + pref.edit().putInt(NUMBER_OF_STARTS, pref.getInt(NUMBER_OF_STARTS, 0) + 1).commit(); + } + if (!pref.contains(FIRST_INSTALLED)) { + pref.edit().putLong(FIRST_INSTALLED, System.currentTimeMillis()).commit(); + } if (!pref.contains(FIRST_TIME_APP_RUN)) { firstTime = true; pref.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit(); diff --git a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java index 60822958f1..3141cf028a 100644 --- a/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java +++ b/OsmAnd/src/net/osmand/plus/ContextMenuAdapter.java @@ -30,7 +30,6 @@ import gnu.trove.list.array.TIntArrayList; public class ContextMenuAdapter { private static final Log LOG = PlatformUtil.getLog(ContextMenuAdapter.class); -// Log log = public interface OnContextMenuClick { //boolean return type needed to desribe if drawer needed to be close or not @@ -296,7 +295,6 @@ public class ContextMenuAdapter { public ArrayAdapter createListAdapter(final Activity activity, final boolean holoLight) { - // XXX layoutId does not effect layout inflated. final int layoutId = defaultLayoutId; final OsmandApplication app = ((OsmandApplication) activity.getApplication()); ArrayAdapter listAdapter = new ContextMenuArrayAdapter(activity, layoutId, R.id.title, diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index caa71822c6..e70993a88a 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1,15 +1,21 @@ package net.osmand.plus; -import android.annotation.TargetApi; -import android.content.Context; -import android.content.res.Configuration; -import android.hardware.Sensor; -import android.hardware.SensorManager; -import android.net.ConnectivityManager; -import android.net.NetworkInfo; -import android.os.Build; -import android.os.Environment; +import java.io.File; +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; import net.osmand.IndexConstants; import net.osmand.StateChangedListener; @@ -28,22 +34,15 @@ import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.render.RenderingRulesStorage; - -import java.io.File; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.Iterator; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.Set; -import java.util.StringTokenizer; +import android.annotation.TargetApi; +import android.content.Context; +import android.content.res.Configuration; +import android.hardware.Sensor; +import android.hardware.SensorManager; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; +import android.os.Build; +import android.os.Environment; public class OsmandSettings { @@ -1876,6 +1875,9 @@ public class OsmandSettings { new BooleanPreference("show_ruler", true).makeProfile().cache(); + public final OsmandPreference NUMBER_OF_STARTS = new IntPreference(AppInitializer.NUMBER_OF_STARTS, 0).makeGlobal(); + + public final OsmandPreference FIRST_INSTALLED_DATE = new LongPreference(AppInitializer.FIRST_INSTALLED, 0).makeGlobal(); // public final OsmandPreference NUMBER_OF_FREE_DOWNLOADS_V2 = new IntPreference("free_downloads_v2", 0).makeGlobal(); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 5f061d2283..b3ab1417cf 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -12,22 +12,26 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.zip.GZIPInputStream; + import net.osmand.AndroidUtils; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.osm.io.NetworkUtils; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; + import org.apache.commons.logging.Log; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; import org.xmlpull.v1.XmlPullParserFactory; + import android.annotation.SuppressLint; import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; +import android.provider.Settings.Secure; public class DownloadOsmandIndexesHelper { private final static Log log = PlatformUtil.getLog(DownloadOsmandIndexesHelper.class); @@ -178,7 +182,17 @@ public class DownloadOsmandIndexesHelper { log.debug("Start loading list of index files"); //$NON-NLS-1$ try { String strUrl = ctx.getAppCustomization().getIndexesUrl(); - + OsmandSettings settings = ctx.getSettings(); + Long nd = settings.FIRST_INSTALLED_DATE.get(); + if(nd > 0) { + strUrl += "&nd=" + ((System.currentTimeMillis() - nd) / (1000l * 24l * 60l * 60l)); + } + strUrl += "&ns=" + settings.NUMBER_OF_STARTS.get(); + try { + strUrl += "&aid=" + Secure.getString(ctx.getContentResolver(), Secure.ANDROID_ID); + } catch (Exception e) { + e.printStackTrace(); + } log.info(strUrl); XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser(); URLConnection connection = NetworkUtils.getHttpURLConnection(strUrl);