Skip to content

Commit

Permalink
Refactoring cleanup (#35)
Browse files Browse the repository at this point in the history
* cleanup

* Removing unused SDKLifecycle

* Combining "SDK" with "SDKCore"
  • Loading branch information
ArtursKadikis authored Mar 7, 2023
1 parent 8ff5cbd commit 59b1589
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 324 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
147 changes: 9 additions & 138 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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...)}.
Expand All @@ -397,27 +380,12 @@ public boolean restore(byte[] data) {
*/
protected Map<Integer, Class<? extends Module>> moduleOverrides = null;

/**
* String-String map with custom parameters sent in each request, persistent.
*/
protected Map<String, String> 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
*/
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1145,15 +1097,6 @@ public Config setCrashProcessorClass(Class<? extends CrashProcessor> crashProces
*/
protected Config overrideModule(Integer feature, Class<? extends Module> 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;
}

/**
Expand Down Expand Up @@ -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<? extends Module> getModuleOverride(Config.Feature feature) {
return moduleOverrides == null ? null : moduleOverrides.get(feature.index);
return null;
}

/**
Expand All @@ -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}
*
Expand Down Expand Up @@ -1302,7 +1183,7 @@ public int getDeviceIdStrategy() {
* @deprecated this will always return "true"
*/
public boolean isDeviceIdFallbackAllowed() {
return deviceIdFallbackAllowed;
return true;
}

/**
Expand Down Expand Up @@ -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() {
Expand All @@ -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}
*
Expand Down Expand Up @@ -1506,10 +1378,10 @@ public Set<String> 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;
Expand All @@ -1532,7 +1404,6 @@ public String getCrashProcessorClass() {
*/
public Class<? extends Module> getModuleOverride(int feature) {
return null;
//return moduleOverrides == null ? null : moduleOverrides.get(feature);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions sdk-java/src/main/java/ly/count/sdk/java/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions sdk-java/src/main/java/ly/count/sdk/java/Usage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 0 additions & 18 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/SDK.java

This file was deleted.

13 changes: 11 additions & 2 deletions sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -36,7 +36,7 @@ public int getIndex() {
}
}

protected SDKCore() {
public SDKCore() {
this.modules = new TreeMap<>();
instance = this;
sdkStorage = new SDKStorage();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 59b1589

Please sign in to comment.