Skip to content

Commit 59b1589

Browse files
Refactoring cleanup (#35)
* cleanup * Removing unused SDKLifecycle * Combining "SDK" with "SDKCore"
1 parent 8ff5cbd commit 59b1589

File tree

10 files changed

+41
-324
lines changed

10 files changed

+41
-324
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
- "getCrashReportingANRCheckingPeriod"
1717
- "setCrashReportingANRCheckingPeriod"
1818
- "disableANRCrashReporting"
19+
20+
* ! Minor breaking change ! The following methods have been removed from the "Config" class:
21+
- "setAutoViewsTracking"
22+
- "setAutoSessionsTracking"
23+
- "setSessionAutoCloseAfter"
24+
- "isAutoViewsTrackingEnabled"
25+
- "isAutoSessionsTrackingEnabled"
26+
- "getSessionAutoCloseAfter"
27+
- "setSessionCooldownPeriod"
28+
1929
* ! Minor breaking change ! The "TestMode" functionality is being removed from the SDK.
2030
* ! Minor breaking change ! The module override functionality is being removed from the SDK.
2131
* ! Minor breaking change ! It is not possible to set the logging tag anymore.

sdk-java/src/main/java/ly/count/sdk/java/Config.java

Lines changed: 9 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@ public boolean restore(byte[] data) {
246246
*/
247247
protected int deviceIdStrategy = 0;
248248

249-
/**
250-
* Allow fallback from specified device id strategy to any other available strategy
251-
*/
252-
protected boolean deviceIdFallbackAllowed = true;
253-
254249
/**
255250
* Developer specified device id
256251
*/
@@ -373,18 +368,6 @@ public boolean restore(byte[] data) {
373368
*/
374369
protected int eventsBufferSize = 10;
375370

376-
/**
377-
* Minimal amount of time between sessions in seconds.
378-
* For now used only when recovering from a crash as a session extension period.
379-
*/
380-
protected int sessionCooldownPeriod = 30;
381-
382-
/**
383-
* How much time of user inactivity Countly should wait until automatically ending session.
384-
* Works only with {@link #autoSessionsTracking} set to {@code true}.
385-
*/
386-
protected int sessionAutoCloseAfter = "Android".equals(System.getProperty("os.name")) ? 10 : 0;
387-
388371
/**
389372
* {@link CrashProcessor}-implementing class which is instantiated when application
390373
* crashes or crash is reported programmatically using {@link Session#addCrashReport(Throwable, boolean, String, Map, String...)}.
@@ -397,27 +380,12 @@ public boolean restore(byte[] data) {
397380
*/
398381
protected Map<Integer, Class<? extends Module>> moduleOverrides = null;
399382

400-
/**
401-
* String-String map with custom parameters sent in each request, persistent.
402-
*/
403-
protected Map<String, String> persistentParams = null;
404-
405383
/**
406384
* Requires GDPR-compliance calls.
407385
* If {@code true}, SDK waits for corresponding consent calls before recording any data.
408386
*/
409387
protected boolean requiresConsent = false;
410388

411-
/**
412-
* Automatically start session on app launch and stop it before it terminates
413-
*/
414-
protected boolean autoSessionsTracking = true;
415-
416-
/**
417-
* Automatically start a view on each activity start and stop it once activity is stopped
418-
*/
419-
protected boolean autoViewsTracking = true;
420-
421389
/**
422390
* If star rating dialog should be cancellable
423391
*/
@@ -897,22 +865,6 @@ public Config disableUpdateRequests() {
897865
return this;
898866
}
899867

900-
/**
901-
* Set minimal amount of time between sessions in seconds.
902-
* For now used only when recovering from a crash as a session extension period.
903-
*
904-
* @param sessionCooldownPeriod min time interval between two sessions
905-
* @return {@code this} instance for method chaining
906-
*/
907-
public Config setSessionCooldownPeriod(int sessionCooldownPeriod) {
908-
if (sessionCooldownPeriod < 0) {
909-
System.out.print("[ConfigCore] sessionCooldownPeriod cannot be negative");
910-
} else {
911-
this.sessionCooldownPeriod = sessionCooldownPeriod;
912-
}
913-
return this;
914-
}
915-
916868
/**
917869
* Change name of SDK used in HTTP requests
918870
*
@@ -1094,7 +1046,7 @@ public Config addCertificatePin(String pemEncodedCertificate) {
10941046
/**
10951047
* Change period when a check for ANR is made. ANR reporting is enabled by default once you enable {@code Feature.CrashReporting}.
10961048
* Default period is 5 seconds. This is *NOT* a timeout for any possible time frame within app running time, it's a checking period.
1097-
* Meaning *some* ANRs are to be recorded if main thread is blocked for slightly more than {@link #crashReportingANRCheckingPeriod}.
1049+
* Meaning *some* ANRs are to be recorded if main thread is blocked for slightly more than #crashReportingANRCheckingPeriod.
10981050
* Statistically it should be good enough as you don't really need all ANRs on the server.
10991051
* *More* ANRs will be recorded in case main thread is blocked for {@code 1.5 * crashReportingANRCheckingPeriod}. Almost all ANRs
11001052
* 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<? extends CrashProcessor> crashProces
11451097
*/
11461098
protected Config overrideModule(Integer feature, Class<? extends Module> cls) {
11471099
return this;
1148-
//if (feature == null || cls == null) {
1149-
// System.out.print("[ConfigCore] Feature & class cannot be null");
1150-
//} else {
1151-
// if (moduleOverrides == null) {
1152-
// moduleOverrides = new HashMap<>();
1153-
// }
1154-
// moduleOverrides.put(feature, cls);
1155-
//}
1156-
//return this;
11571100
}
11581101

11591102
/**
@@ -1188,9 +1131,10 @@ public boolean isFeatureEnabled(Config.Feature feature) {
11881131
* Getter for {@link #moduleOverrides}
11891132
*
11901133
* @return {@link #moduleOverrides} value for {@code Feature} specified
1134+
* @deprecated this will do nothing
11911135
*/
11921136
public Class<? extends Module> getModuleOverride(Config.Feature feature) {
1193-
return moduleOverrides == null ? null : moduleOverrides.get(feature.index);
1137+
return null;
11941138
}
11951139

11961140
/**
@@ -1205,69 +1149,6 @@ public Config setRequiresConsent(boolean requiresConsent) {
12051149
return this;
12061150
}
12071151

1208-
/**
1209-
* Enable auto views tracking
1210-
*
1211-
* @param autoViewsTracking whether to enable it or disable
1212-
* @return {@code this} instance for method chaining
1213-
* @see #autoViewsTracking
1214-
*/
1215-
public Config setAutoViewsTracking(boolean autoViewsTracking) {
1216-
this.autoViewsTracking = autoViewsTracking;
1217-
return this;
1218-
}
1219-
1220-
/**
1221-
* Enable auto sessions tracking
1222-
*
1223-
* @param autoSessionsTracking whether to enable it or disable
1224-
* @return {@code this} instance for method chaining
1225-
* @see #autoSessionsTracking
1226-
*/
1227-
public Config setAutoSessionsTracking(boolean autoSessionsTracking) {
1228-
this.autoSessionsTracking = autoSessionsTracking;
1229-
return this;
1230-
}
1231-
1232-
/**
1233-
* Wait this much time before ending session in auto session tracking mode
1234-
*
1235-
* @param sessionAutoCloseAfter time in seconds
1236-
* @return {@code this} instance for method chaining
1237-
* @see #autoSessionsTracking
1238-
*/
1239-
public Config setSessionAutoCloseAfter(int sessionAutoCloseAfter) {
1240-
this.sessionAutoCloseAfter = sessionAutoCloseAfter;
1241-
return this;
1242-
}
1243-
1244-
/**
1245-
* Getter for {@link #autoSessionsTracking}
1246-
*
1247-
* @return {@link #autoSessionsTracking} value
1248-
*/
1249-
public boolean isAutoViewsTrackingEnabled() {
1250-
return autoViewsTracking;
1251-
}
1252-
1253-
/**
1254-
* Getter for {@link #autoSessionsTracking}
1255-
*
1256-
* @return {@link #autoSessionsTracking} value
1257-
*/
1258-
public boolean isAutoSessionsTrackingEnabled() {
1259-
return autoSessionsTracking;
1260-
}
1261-
1262-
/**
1263-
* Getter for {@link #sessionAutoCloseAfter}
1264-
*
1265-
* @return {@link #sessionAutoCloseAfter} value
1266-
*/
1267-
public int getSessionAutoCloseAfter() {
1268-
return sessionAutoCloseAfter;
1269-
}
1270-
12711152
/**
12721153
* Getter for {@link #serverURL}
12731154
*
@@ -1302,7 +1183,7 @@ public int getDeviceIdStrategy() {
13021183
* @deprecated this will always return "true"
13031184
*/
13041185
public boolean isDeviceIdFallbackAllowed() {
1305-
return deviceIdFallbackAllowed;
1186+
return true;
13061187
}
13071188

13081189
/**
@@ -1415,9 +1296,9 @@ public LogCallback getLogListener() {
14151296
}
14161297

14171298
/**
1418-
* Getter for {@link #testMode}
1299+
* Getter for #testMode
14191300
*
1420-
* @return {@link #testMode} value
1301+
* @return #testMode value
14211302
* @deprecated Calling this function will always return 'false'
14221303
*/
14231304
public boolean isTestModeEnabled() {
@@ -1433,15 +1314,6 @@ public int getSendUpdateEachSeconds() {
14331314
return sendUpdateEachSeconds;
14341315
}
14351316

1436-
/**
1437-
* Getter for {@link #sessionCooldownPeriod}
1438-
*
1439-
* @return {@link #sessionCooldownPeriod} value
1440-
*/
1441-
public int getSessionCooldownPeriod() {
1442-
return sessionCooldownPeriod;
1443-
}
1444-
14451317
/**
14461318
* Getter for {@link #eventsBufferSize}
14471319
*
@@ -1506,10 +1378,10 @@ public Set<String> getCertificatePins() {
15061378
}
15071379

15081380
/**
1509-
* Getter for {@link #crashReportingANRCheckingPeriod}
1381+
* Getter for #crashReportingANRCheckingPeriod
15101382
*
1511-
* @return {@link #crashReportingANRCheckingPeriod} value
1512-
* @Deprecated will always return "5"
1383+
* @return #crashReportingANRCheckingPeriod value
1384+
* @deprecated will always return "5"
15131385
*/
15141386
public int getCrashReportingANRCheckingPeriod() {
15151387
return 5;
@@ -1532,7 +1404,6 @@ public String getCrashProcessorClass() {
15321404
*/
15331405
public Class<? extends Module> getModuleOverride(int feature) {
15341406
return null;
1535-
//return moduleOverrides == null ? null : moduleOverrides.get(feature);
15361407
}
15371408

15381409
/**

sdk-java/src/main/java/ly/count/sdk/java/Countly.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ public class Countly implements Usage {
2525
public static Device device = Device.dev;
2626

2727
protected static Countly cly;
28-
protected SDK sdk;
28+
protected SDKCore sdk;
2929
protected CtxCore ctx;
3030
protected Log L;
3131

32-
protected Countly(SDK sdk, CtxCore ctx, Log logger) {
32+
protected Countly(SDKCore sdk, CtxCore ctx, Log logger) {
3333
cly = this;
3434
L = logger;
3535
this.sdk = sdk;
@@ -79,7 +79,7 @@ public static void init(final File directory, final Config config) {
7979

8080
InternalConfig internalConfig = new InternalConfig(config);
8181
Log L = new Log(internalConfig.loggingLevel, internalConfig.logListener);
82-
SDK sdk = new SDK();
82+
SDKCore sdk = new SDKCore();
8383
sdk.init(new CtxCore(sdk, internalConfig, L, directory), L);
8484

8585
// config has been changed, thus recreating ctx

sdk-java/src/main/java/ly/count/sdk/java/Usage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,14 @@ public interface Usage {
111111
/**
112112
* @param id new user / device id string, cannot be empty
113113
* @deprecated Login function to set device (user) id on Countly server to the string specified here.
114-
* Closes current session, then starts new one automatically if {@link Config#autoSessionsTracking} is on, acquires device id.
114+
* Closes current session, then starts new one automatically if Config#autoSessionsTracking is on, acquires device id.
115115
*/
116116
Usage login(String id);
117117

118118
/**
119119
* @deprecated Logout function to make current user anonymous (that is with random id according to
120120
* {@link Config#deviceIdStrategy} and such). Obviously makes sense only after a call to {@link #login(String)},
121-
* so it throws error or does nothing (depending on {@link Config#testMode}) if current id wasn't set using {@link #login(String)}.
121+
* so it throws error or does nothing (depending on Config#testMode) if current id wasn't set using {@link #login(String)}.
122122
*
123123
* Closes current session.
124124
*/

sdk-java/src/main/java/ly/count/sdk/java/internal/InternalConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public byte[] store() {
140140
}
141141
stream.writeInt(sendUpdateEachSeconds);
142142
stream.writeInt(eventsBufferSize);
143-
stream.writeInt(sessionCooldownPeriod);
143+
stream.writeInt(0);//for keeping backwards compatibility, remove in the future. sessionCooldownPeriod
144144
stream.writeBoolean(false);//for keeping backwards compatibility, remove in the future
145145
stream.writeInt(5);//for keeping backwards compatibility, remove in the future (crashReportingANRCheckingPeriod)
146146
stream.writeObject(crashProcessorClass);
@@ -229,7 +229,7 @@ public boolean restore(byte[] data) {
229229
}
230230
sendUpdateEachSeconds = stream.readInt();
231231
eventsBufferSize = stream.readInt();
232-
sessionCooldownPeriod = stream.readInt();
232+
int throwawaySessionCooldownPeriod = stream.readInt();//we are only reading this for backwards compatibility. Throw away in the future
233233
boolean throwawayCountlyTestMode = stream.readBoolean();//we are only reading this for backwards compatibility. Throw away in the future
234234
int throwawayCrashReportingANRCheckingPeriod = stream.readInt();//we are only reading this for backwards compatibility. Throw away in the future. crashReportingANRCheckingPeriod
235235
crashProcessorClass = (String) stream.readObject();

sdk-java/src/main/java/ly/count/sdk/java/internal/SDK.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

sdk-java/src/main/java/ly/count/sdk/java/internal/SDKCore.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import java.util.*;
88
import java.util.concurrent.Future;
99

10-
public abstract class SDKCore implements SDKInterface {
10+
public class SDKCore implements SDKInterface {
1111

1212
protected static SDKCore instance;
1313

@@ -36,7 +36,7 @@ public int getIndex() {
3636
}
3737
}
3838

39-
protected SDKCore() {
39+
public SDKCore() {
4040
this.modules = new TreeMap<>();
4141
instance = this;
4242
sdkStorage = new SDKStorage();
@@ -130,6 +130,8 @@ public void run(int feature, Module module) {
130130
user = null;
131131
config = null;
132132
instance = null;
133+
134+
sdkStorage.stop(ctx, clear);//from original super class
133135
}
134136

135137
private boolean addingConsent(int adding, CoreFeature feature) {
@@ -736,4 +738,11 @@ private boolean processCrash(CtxCore ctx, Long id) {
736738
return false;
737739
}
738740
}
741+
742+
743+
//transferred from original subclass
744+
@Override
745+
public void onRequest(ly.count.sdk.java.internal.CtxCore ctx, Request request) {
746+
onSignal(ctx, SDKCore.Signal.Ping.getIndex(), null);
747+
}
739748
}

0 commit comments

Comments
 (0)