diff --git a/CHANGELOG.md b/CHANGELOG.md index db4151aa4..382de034b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,16 @@ - "getCrashReportingANRCheckingPeriod" - "setCrashReportingANRCheckingPeriod" - "disableANRCrashReporting" + +* ! Minor breaking change ! The following methods have been removed from the "Config" class: + - "setAutoViewsTracking" + - "setAutoSessionsTracking" + - "setSessionAutoCloseAfter" + - "isAutoViewsTrackingEnabled" + - "isAutoSessionsTrackingEnabled" + - "getSessionAutoCloseAfter" + - "setSessionCooldownPeriod" + * ! Minor breaking change ! The "TestMode" functionality is being removed from the SDK. * ! Minor breaking change ! The module override functionality is being removed from the SDK. * ! Minor breaking change ! It is not possible to set the logging tag anymore. diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Config.java b/sdk-java/src/main/java/ly/count/sdk/java/Config.java index 8337018be..38fd98368 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Config.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Config.java @@ -246,11 +246,6 @@ public boolean restore(byte[] data) { */ protected int deviceIdStrategy = 0; - /** - * Allow fallback from specified device id strategy to any other available strategy - */ - protected boolean deviceIdFallbackAllowed = true; - /** * Developer specified device id */ @@ -373,18 +368,6 @@ public boolean restore(byte[] data) { */ protected int eventsBufferSize = 10; - /** - * Minimal amount of time between sessions in seconds. - * For now used only when recovering from a crash as a session extension period. - */ - protected int sessionCooldownPeriod = 30; - - /** - * How much time of user inactivity Countly should wait until automatically ending session. - * Works only with {@link #autoSessionsTracking} set to {@code true}. - */ - protected int sessionAutoCloseAfter = "Android".equals(System.getProperty("os.name")) ? 10 : 0; - /** * {@link CrashProcessor}-implementing class which is instantiated when application * crashes or crash is reported programmatically using {@link Session#addCrashReport(Throwable, boolean, String, Map, String...)}. @@ -397,27 +380,12 @@ public boolean restore(byte[] data) { */ protected Map> moduleOverrides = null; - /** - * String-String map with custom parameters sent in each request, persistent. - */ - protected Map persistentParams = null; - /** * Requires GDPR-compliance calls. * If {@code true}, SDK waits for corresponding consent calls before recording any data. */ protected boolean requiresConsent = false; - /** - * Automatically start session on app launch and stop it before it terminates - */ - protected boolean autoSessionsTracking = true; - - /** - * Automatically start a view on each activity start and stop it once activity is stopped - */ - protected boolean autoViewsTracking = true; - /** * If star rating dialog should be cancellable */ @@ -897,22 +865,6 @@ public Config disableUpdateRequests() { return this; } - /** - * Set minimal amount of time between sessions in seconds. - * For now used only when recovering from a crash as a session extension period. - * - * @param sessionCooldownPeriod min time interval between two sessions - * @return {@code this} instance for method chaining - */ - public Config setSessionCooldownPeriod(int sessionCooldownPeriod) { - if (sessionCooldownPeriod < 0) { - System.out.print("[ConfigCore] sessionCooldownPeriod cannot be negative"); - } else { - this.sessionCooldownPeriod = sessionCooldownPeriod; - } - return this; - } - /** * Change name of SDK used in HTTP requests * @@ -1094,7 +1046,7 @@ public Config addCertificatePin(String pemEncodedCertificate) { /** * Change period when a check for ANR is made. ANR reporting is enabled by default once you enable {@code Feature.CrashReporting}. * Default period is 5 seconds. This is *NOT* a timeout for any possible time frame within app running time, it's a checking period. - * Meaning *some* ANRs are to be recorded if main thread is blocked for slightly more than {@link #crashReportingANRCheckingPeriod}. + * Meaning *some* ANRs are to be recorded if main thread is blocked for slightly more than #crashReportingANRCheckingPeriod. * Statistically it should be good enough as you don't really need all ANRs on the server. * *More* ANRs will be recorded in case main thread is blocked for {@code 1.5 * crashReportingANRCheckingPeriod}. Almost all ANRs * are going to be recorded once main thread is blocked for {@code 2 * crashReportingANRCheckingPeriod} or more seconds. @@ -1145,15 +1097,6 @@ public Config setCrashProcessorClass(Class crashProces */ protected Config overrideModule(Integer feature, Class cls) { return this; - //if (feature == null || cls == null) { - // System.out.print("[ConfigCore] Feature & class cannot be null"); - //} else { - // if (moduleOverrides == null) { - // moduleOverrides = new HashMap<>(); - // } - // moduleOverrides.put(feature, cls); - //} - //return this; } /** @@ -1188,9 +1131,10 @@ public boolean isFeatureEnabled(Config.Feature feature) { * Getter for {@link #moduleOverrides} * * @return {@link #moduleOverrides} value for {@code Feature} specified + * @deprecated this will do nothing */ public Class getModuleOverride(Config.Feature feature) { - return moduleOverrides == null ? null : moduleOverrides.get(feature.index); + return null; } /** @@ -1205,69 +1149,6 @@ public Config setRequiresConsent(boolean requiresConsent) { return this; } - /** - * Enable auto views tracking - * - * @param autoViewsTracking whether to enable it or disable - * @return {@code this} instance for method chaining - * @see #autoViewsTracking - */ - public Config setAutoViewsTracking(boolean autoViewsTracking) { - this.autoViewsTracking = autoViewsTracking; - return this; - } - - /** - * Enable auto sessions tracking - * - * @param autoSessionsTracking whether to enable it or disable - * @return {@code this} instance for method chaining - * @see #autoSessionsTracking - */ - public Config setAutoSessionsTracking(boolean autoSessionsTracking) { - this.autoSessionsTracking = autoSessionsTracking; - return this; - } - - /** - * Wait this much time before ending session in auto session tracking mode - * - * @param sessionAutoCloseAfter time in seconds - * @return {@code this} instance for method chaining - * @see #autoSessionsTracking - */ - public Config setSessionAutoCloseAfter(int sessionAutoCloseAfter) { - this.sessionAutoCloseAfter = sessionAutoCloseAfter; - return this; - } - - /** - * Getter for {@link #autoSessionsTracking} - * - * @return {@link #autoSessionsTracking} value - */ - public boolean isAutoViewsTrackingEnabled() { - return autoViewsTracking; - } - - /** - * Getter for {@link #autoSessionsTracking} - * - * @return {@link #autoSessionsTracking} value - */ - public boolean isAutoSessionsTrackingEnabled() { - return autoSessionsTracking; - } - - /** - * Getter for {@link #sessionAutoCloseAfter} - * - * @return {@link #sessionAutoCloseAfter} value - */ - public int getSessionAutoCloseAfter() { - return sessionAutoCloseAfter; - } - /** * Getter for {@link #serverURL} * @@ -1302,7 +1183,7 @@ public int getDeviceIdStrategy() { * @deprecated this will always return "true" */ public boolean isDeviceIdFallbackAllowed() { - return deviceIdFallbackAllowed; + return true; } /** @@ -1415,9 +1296,9 @@ public LogCallback getLogListener() { } /** - * Getter for {@link #testMode} + * Getter for #testMode * - * @return {@link #testMode} value + * @return #testMode value * @deprecated Calling this function will always return 'false' */ public boolean isTestModeEnabled() { @@ -1433,15 +1314,6 @@ public int getSendUpdateEachSeconds() { return sendUpdateEachSeconds; } - /** - * Getter for {@link #sessionCooldownPeriod} - * - * @return {@link #sessionCooldownPeriod} value - */ - public int getSessionCooldownPeriod() { - return sessionCooldownPeriod; - } - /** * Getter for {@link #eventsBufferSize} * @@ -1506,10 +1378,10 @@ public Set getCertificatePins() { } /** - * Getter for {@link #crashReportingANRCheckingPeriod} + * Getter for #crashReportingANRCheckingPeriod * - * @return {@link #crashReportingANRCheckingPeriod} value - * @Deprecated will always return "5" + * @return #crashReportingANRCheckingPeriod value + * @deprecated will always return "5" */ public int getCrashReportingANRCheckingPeriod() { return 5; @@ -1532,7 +1404,6 @@ public String getCrashProcessorClass() { */ public Class getModuleOverride(int feature) { return null; - //return moduleOverrides == null ? null : moduleOverrides.get(feature); } /** diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java index bfc35ddd5..9caff02d9 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Countly.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Countly.java @@ -25,11 +25,11 @@ public class Countly implements Usage { public static Device device = Device.dev; protected static Countly cly; - protected SDK sdk; + protected SDKCore sdk; protected CtxCore ctx; protected Log L; - protected Countly(SDK sdk, CtxCore ctx, Log logger) { + protected Countly(SDKCore sdk, CtxCore ctx, Log logger) { cly = this; L = logger; this.sdk = sdk; @@ -79,7 +79,7 @@ public static void init(final File directory, final Config config) { InternalConfig internalConfig = new InternalConfig(config); Log L = new Log(internalConfig.loggingLevel, internalConfig.logListener); - SDK sdk = new SDK(); + SDKCore sdk = new SDKCore(); sdk.init(new CtxCore(sdk, internalConfig, L, directory), L); // config has been changed, thus recreating ctx diff --git a/sdk-java/src/main/java/ly/count/sdk/java/Usage.java b/sdk-java/src/main/java/ly/count/sdk/java/Usage.java index 419cc0d33..c604e99dc 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/Usage.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/Usage.java @@ -111,14 +111,14 @@ public interface Usage { /** * @param id new user / device id string, cannot be empty * @deprecated Login function to set device (user) id on Countly server to the string specified here. - * Closes current session, then starts new one automatically if {@link Config#autoSessionsTracking} is on, acquires device id. + * Closes current session, then starts new one automatically if Config#autoSessionsTracking is on, acquires device id. */ Usage login(String id); /** * @deprecated Logout function to make current user anonymous (that is with random id according to * {@link Config#deviceIdStrategy} and such). Obviously makes sense only after a call to {@link #login(String)}, - * so it throws error or does nothing (depending on {@link Config#testMode}) if current id wasn't set using {@link #login(String)}. + * so it throws error or does nothing (depending on Config#testMode) if current id wasn't set using {@link #login(String)}. * * Closes current session. */ diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java index 7f5880da1..8056020df 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java @@ -140,7 +140,7 @@ public byte[] store() { } stream.writeInt(sendUpdateEachSeconds); stream.writeInt(eventsBufferSize); - stream.writeInt(sessionCooldownPeriod); + stream.writeInt(0);//for keeping backwards compatibility, remove in the future. sessionCooldownPeriod stream.writeBoolean(false);//for keeping backwards compatibility, remove in the future stream.writeInt(5);//for keeping backwards compatibility, remove in the future (crashReportingANRCheckingPeriod) stream.writeObject(crashProcessorClass); @@ -229,7 +229,7 @@ public boolean restore(byte[] data) { } sendUpdateEachSeconds = stream.readInt(); eventsBufferSize = stream.readInt(); - sessionCooldownPeriod = stream.readInt(); + int throwawaySessionCooldownPeriod = stream.readInt();//we are only reading this for backwards compatibility. Throw away in the future boolean throwawayCountlyTestMode = stream.readBoolean();//we are only reading this for backwards compatibility. Throw away in the future int throwawayCrashReportingANRCheckingPeriod = stream.readInt();//we are only reading this for backwards compatibility. Throw away in the future. crashReportingANRCheckingPeriod crashProcessorClass = (String) stream.readObject(); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDK.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDK.java deleted file mode 100644 index 0413aa356..000000000 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDK.java +++ /dev/null @@ -1,18 +0,0 @@ -package ly.count.sdk.java.internal; - -public class SDK extends SDKCore { - - private static final String FILE_NAME_PREFIX = "[CLY]"; - private static final String FILE_NAME_SEPARATOR = "_"; - - @Override - public void stop(ly.count.sdk.java.internal.CtxCore ctx, boolean clear) { - super.stop(ctx, clear); - sdkStorage.stop(ctx, clear); - } - - @Override - public void onRequest(ly.count.sdk.java.internal.CtxCore ctx, Request request) { - onSignal(ctx, SDKCore.Signal.Ping.getIndex(), null); - } -} diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java index de9114a4a..65b408e98 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java @@ -7,7 +7,7 @@ import java.util.*; import java.util.concurrent.Future; -public abstract class SDKCore implements SDKInterface { +public class SDKCore implements SDKInterface { protected static SDKCore instance; @@ -36,7 +36,7 @@ public int getIndex() { } } - protected SDKCore() { + public SDKCore() { this.modules = new TreeMap<>(); instance = this; sdkStorage = new SDKStorage(); @@ -130,6 +130,8 @@ public void run(int feature, Module module) { user = null; config = null; instance = null; + + sdkStorage.stop(ctx, clear);//from original super class } private boolean addingConsent(int adding, CoreFeature feature) { @@ -736,4 +738,11 @@ private boolean processCrash(CtxCore ctx, Long id) { return false; } } + + + //transferred from original subclass + @Override + public void onRequest(ly.count.sdk.java.internal.CtxCore ctx, Request request) { + onSignal(ctx, SDKCore.Signal.Ping.getIndex(), null); + } } diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKLifecycle.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKLifecycle.java deleted file mode 100644 index d907eff0b..000000000 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SDKLifecycle.java +++ /dev/null @@ -1,76 +0,0 @@ -package ly.count.sdk.java.internal; - -import ly.count.sdk.java.internal.Byteable; -import ly.count.sdk.java.internal.CtxCore; -import ly.count.sdk.java.internal.InternalConfig; -import ly.count.sdk.java.internal.Log; -import ly.count.sdk.java.internal.Module; -import ly.count.sdk.java.internal.ModuleCrash; -import ly.count.sdk.java.internal.ModuleRequests; -import ly.count.sdk.java.internal.Request; -import ly.count.sdk.java.internal.SDKCore; -import ly.count.sdk.java.internal.Storage; -import org.json.JSONObject; - -import java.util.Map; - -/** - * Application lifecycle-related methods of {@link SDK} - */ - -public abstract class SDKLifecycle extends SDKCore { - - /** - * Core instance config - */ - - protected InternalConfig config; - - protected SDKLifecycle() { - super(); - } - - @Override - public void stop(ly.count.sdk.java.internal.CtxCore ctx, boolean clear) { - super.stop(ctx, clear); - config = null; - } - - @Override - public void onSignal(CtxCore ctx, int id, Byteable param1, Byteable param2) { - if (id == Signal.DID.getIndex()) { - networking.check(ctx); - } - } - - @Override - public void onSignal(CtxCore ctx, int id, String param) { - if (id == Signal.Ping.getIndex()) { - networking.check(ctx); - } else if (id == Signal.Crash.getIndex()) { - processCrash(ctx, Long.parseLong(param)); - } - } - - private boolean processCrash(CtxCore ctx, Long id) { - CrashImpl crash = new CrashImpl(id, L); - crash = Storage.read(ctx, crash); - - if (crash == null) { - L.e("Cannot read crash from storage, skipping"); - return false; - } - - Request request = ModuleRequests.nonSessionRequest(ctx); - ModuleCrash.putCrashIntoParams(crash, request.params); - if (Storage.push(ctx, request)) { - L.i("[SDKLifecycle] Added request " + request.storageId() + " instead of crash " + crash.storageId()); - networking.check(ctx); - Boolean success = Storage.remove(ctx, crash); - return success == null ? false : success; - } else { - L.e("[SDKLifecycle] Couldn't write request " + request.storageId() + " instead of crash " + crash.storageId()); - return false; - } - } -} diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java index 61dfeabc0..c17290af5 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/SessionImpl.java @@ -222,16 +222,16 @@ public void call(Boolean removed) throws Exception { } Boolean recover(Config config) { - if ((System.currentTimeMillis() - id) < Device.dev.secToMs(config.getSessionCooldownPeriod() * 2)) { + if ((System.currentTimeMillis() - id) < 0) { return null; } else { Future future = null; if (began == null) { return Storage.remove(ctx, this); } else if (ended == null && updated == null) { - future = end(began + Device.dev.secToNs(config.getSessionCooldownPeriod()), null, null); + future = end(began, null, null); } else if (ended == null) { - future = end(updated + Device.dev.secToNs(config.getSessionCooldownPeriod()), null, null); + future = end(updated, null, null); } else { // began != null && ended != null return Storage.remove(ctx, this); diff --git a/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java b/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java index c818f91fd..097c8389e 100644 --- a/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java +++ b/sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java @@ -19,7 +19,7 @@ */ public class Utils { - protected static final Utils utils = new Utils(); + protected static final Utils utils = new Utils();//todo remove this when possible public static final String UTF8 = "UTF-8"; public static final String CRLF = "\r\n"; @@ -317,85 +317,6 @@ public T _reflectiveGetField(Object object, Class cls, String name) { return null; } - // public static final class Reflection { - // private T instance; - // private Class cls; - // - // Reflection(T instance) { - // this.instance = instance; - // this.cls = instance.getClass(); - // } - // - // Reflection(String className) throws ClassNotFoundException { - // this.cls = Class.forName(className); - // } - // - // public Object call(String methodName, Object... args) { - // try { - // Class types[] = null; - // - // if (args != null && args.length > 0) { - // types = new Class[args.length]; - // - // for (int i = 0; i < types.length; i++) { - // types[i] = args[i].getClass(); - // } - // } - // Method method = cls.getDeclaredMethod(methodName, types); - // return method.invoke(instance, args); - // } catch (NoSuchMethodException t) { - // System.out.print("Utils Cannot call " + methodName + " of " + cls.getName() + t.toString()); - // return false; - // } catch (IllegalAccessException t) { - // System.out.print("Utils Cannot call " + methodName + " of " + cls.getName() + t.toString()); - // return false; - // } catch (InvocationTargetException t) { - // System.out.print("Utils Cannot call " + methodName + " of " + cls.getName() + t.toString()); - // return false; - // } - // } - // - // public Object get(String fieldName) { - // try { - // Field field = instance == null ? cls.getDeclaredField(fieldName): instance.getClass().getDeclaredField(fieldName); - // boolean accessible = field.isAccessible(); - // if (!accessible) { - // field.setAccessible(true); - // } - // Object value = field.get(instance); - // if (!accessible) { - // field.setAccessible(false); - // } - // return value; - // } catch (IllegalAccessException e) { - // System.out.print("Utils Cannot access field " + fieldName + " of " + cls.getName() + e.toString()); - // } catch (NoSuchFieldException e) { - // System.out.print("Utils No field " + fieldName + " in " + cls.getName() + e.toString()); - // } - // return null; - // } - // - // public Boolean set(String fieldName, Object value) { - // try { - // Field field = instance == null ? cls.getDeclaredField(fieldName): instance.getClass().getDeclaredField(fieldName); - // boolean accessible = field.isAccessible(); - // if (!accessible) { - // field.setAccessible(true); - // } - // field.set(instance, value); - // if (!accessible) { - // field.setAccessible(false); - // } - // return true; - // } catch (IllegalAccessException e) { - // System.out.print("Utils Cannot access field " + fieldName + " of " + cls.getName() + e.toString()); - // } catch (NoSuchFieldException e) { - // System.out.print("Utils No field " + fieldName + " in " + cls.getName() + e.toString()); - // } - // return false; - // } - // } - /** * Calculate digest (SHA-1, SHA-256, etc.) hash of the string provided *