Stored first install version to settings.

This commit is contained in:
Dmitry Yunitsky 2015-01-22 20:36:19 +03:00 committed by Alex Zolotarev
parent c16508c855
commit 1d0013495e
2 changed files with 20 additions and 7 deletions

View file

@ -39,10 +39,11 @@ public class MWMApplication extends android.app.Application implements ActiveCou
{
private final static String TAG = "MWMApplication";
private static final String FOREGROUND_TIME_SETTING = "AllForegroundTime";
public static final String LAUNCH_NUMBER_SETTING = "LaunchNumber"; // total number of app launches
public static final String SESSION_NUMBER_SETTING = "SessionNumber"; // session = number of days, when app was launched
public static final String LAST_SESSION_TIMESTAMP_SETTING = "LastSessionTimestamp"; // timestamp of last session
private static final String LAUNCH_NUMBER_SETTING = "LaunchNumber"; // total number of app launches
private static final String SESSION_NUMBER_SETTING = "SessionNumber"; // session = number of days, when app was launched
private static final String LAST_SESSION_TIMESTAMP_SETTING = "LastSessionTimestamp"; // timestamp of last session
public static final String IS_PREINSTALLED = "IsPreinstalled";
private static final String FIRST_INSTALL_VERSION = "FirstInstallVersion";
private static MWMApplication mSelf;
@ -285,7 +286,10 @@ public class MWMApplication extends android.app.Application implements ActiveCou
{
final int currentLaunches = nativeGetInt(LAUNCH_NUMBER_SETTING, 0);
if (currentLaunches == 0)
{
trackAppActivation();
nativeSetInt(FIRST_INSTALL_VERSION, BuildConfig.VERSION_CODE);
}
nativeSetInt(LAUNCH_NUMBER_SETTING, currentLaunches + 1);
}
@ -305,7 +309,6 @@ public class MWMApplication extends android.app.Application implements ActiveCou
}
/**
*
* @return total number of application launches
*/
public int getLaunchesNumber()
@ -315,6 +318,7 @@ public class MWMApplication extends android.app.Application implements ActiveCou
/**
* Session = single day, when app was started any number of times.
*
* @return number of sessions.
*/
public int getSessionsNumber()
@ -322,6 +326,11 @@ public class MWMApplication extends android.app.Application implements ActiveCou
return nativeGetInt(SESSION_NUMBER_SETTING, 0);
}
public int getFirstInstallVersion()
{
return nativeGetInt(FIRST_INSTALL_VERSION, 0);
}
private void initMAT(Activity activity)
{
if (!Utils.hasAnyGoogleStoreInstalled())

View file

@ -26,7 +26,6 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -287,12 +286,17 @@ public class Utils
return model;
}
public static boolean isInstalledAfter(Calendar calendar)
/**
*
* @param timestamp in currentTimeMillis() format
* @return
*/
public static boolean isInstalledAfter(long timestamp)
{
try
{
final PackageInfo info = MWMApplication.get().getPackageManager().getPackageInfo(BuildConfig.APPLICATION_ID, 0);
return info.firstInstallTime > calendar.getTimeInMillis();
return info.firstInstallTime > timestamp;
} catch (PackageManager.NameNotFoundException e)
{
e.printStackTrace();