Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Before initialization, while the consent of a feature is not given, or when a feature is not enabled, they return an interface that ignores calls until the feature runs and passes an error to the callbacks of the calls it ignores.
An interface you keep sends its calls to the feature once it runs. Use "Countly.isTracking" to check whether a feature runs.

* Added the health check feature. The SDK now sends a health check request once after each initialization, except in backend mode.
* Added support for SDK behavior settings that let the server control the SDK:
* Switches for tracking, networking, sessions, views, custom events, crash reporting, automatic crash reporting, location, and console logging
* The event queue size, request queue size, session update interval, and settings refresh interval
Expand All @@ -40,6 +41,9 @@
* Added support for server requested SDK log gathering. When the server asks for it, the SDK uploads its own internal log lines, even if logging is disabled. While consent is required, a line is uploaded only while the consent of the feature it belongs to is given.
* Added support for the SDK connection test. When the server asks for it, the SDK checks that it can reach every endpoint it depends on and reports the results.
* Added "setMaxKeyLength(int)" init config method to limit the length of event keys, view names, segmentation keys and custom user property keys. Longer keys are truncated. There is no limit by default, and the key length limit of the SDK behavior settings overrides it.
* Added "disableHealthCheck()" init config method to turn off the health check request.
* The deprecated "event", "timedEvent", "view" and "addCrashReport" calls of the session interface, and "record" and "endAndRecord" of a legacy event, now log a warning that names the call to use instead.
* Failed requests are now logged at debug level, and wrong uses of the session, event, view and crash methods at warning level instead of error level.

* Mitigated an issue where saving the SDK storage while remote config values were changing could empty the storage file.
* Mitigated an issue where a storage file cut short by a stopped process made initialization fail.
Expand All @@ -58,6 +62,8 @@
* Mitigated an issue where backend mode requests carried no device ID type, so the server did not count the users recorded in backend mode as identified.
* Mitigated an issue where a backend mode direct request sent a key twice when the given map contained a key the SDK also sets. The value in the map now replaces the SDK's value, as documented.
* Mitigated an issue where a backend mode direct request changed the given map, and failed with an unmodifiable map.
* Mitigated an issue where "onConsent" and "onConsentRemoval" threw a NullPointerException when one of the given features was null.
* Mitigated an issue where the session update timer logged an error every minute for a session that was created but not begun.

## 26.8.0
* Added support for the Content feature, accessible through the "Countly.instance().content()" interface:
Expand Down
20 changes: 20 additions & 0 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@
protected int networkReadTimeout = 30;

/**
* How long to wait between requests in milliseconds. Used to decrease CPU & I/O load on the device.

Check warning on line 107 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*/
protected int networkRequestCooldown = 1000;

/**
* How long to wait between Device ID change & push token requests, in milliseconds.

Check warning on line 112 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'

Check warning on line 112 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
* Required by Countly server, don't change unless you know what you're doing!
*/
protected int networkImportantRequestCooldown = 5000;
Expand All @@ -126,7 +126,7 @@
* This ensures pinning continues to work after certificate prolongation.
* Certificates ({@link #certificatePins}) on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.

Check warning on line 129 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*/
protected Set<String> publicKeyPins = null;

Expand All @@ -142,7 +142,7 @@
* This ensures pinning continues to work after certificate prolongation.
* Certificates on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.

Check warning on line 145 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*/
protected Set<String> certificatePins = null;

Expand All @@ -168,7 +168,7 @@
/**
* {@link CrashProcessor}-implementing class which is instantiated when application
* crashes or crash is reported programmatically using {@link Session#addCrashReport(Throwable, boolean, String, Map, String...)}.
* Crash processor helps you to add custom data in event of a crash: custom crash segments & crash logs.

Check warning on line 171 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*/
protected String crashProcessorClass = null;

Expand Down Expand Up @@ -278,6 +278,11 @@
*/
protected boolean backoffMechanismEnabled = true;

/**
* Whether the SDK sends its health check after init.
*/
protected boolean healthCheckEnabled = true;

// TODO: storage limits & configuration
// protected int maxRequestsStored = 0;
// protected int storageDirectory = "";
Expand Down Expand Up @@ -713,7 +718,7 @@
}

/**
* Disable update requests completely. Only begin & end requests will be sent + some special

Check warning on line 721 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
* cases if applicable like User Profile change or Push token updated.
*
* @return {@code this} instance for method chaining
Expand Down Expand Up @@ -811,7 +816,7 @@

/**
* How long to wait between requests in seconds.
* Used to decrease CPU & I/O load on the device in case of batch requests.

Check warning on line 819 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*
* @param milliseconds cooldown period in seconds
* @return {@code this} instance for method chaining
Expand All @@ -829,7 +834,7 @@

/**
* Set read timeout in seconds for HTTP requests SDK sends to Countly server. Defaults to 30.
* Used to decrease CPU & I/O load on the device in case of batch requests.

Check warning on line 837 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*
* @param milliseconds read timeout in milliseconds
* @return {@code this} instance for method chaining
Expand Down Expand Up @@ -857,7 +862,7 @@
* This ensures pinning continues to work after certificate prolongation.
* Certificates ({@link #certificatePins}) on the other hand have specific expiry date.
* In case you chose this way of pinning, you MUST ensure that ALL installs of your app
* have both certificates (old & new) until expiry date.

Check warning on line 865 in sdk-java/src/main/java/ly/count/sdk/java/Config.java

View workflow job for this annotation

GitHub Actions / Release checks (26.8.0)

invalid input: '&'
*
* NOTE: when {@link #serverURL} doesn't have {@code "https://"} public key pinning doesn't work
*
Expand Down Expand Up @@ -1595,4 +1600,19 @@
this.backoffMechanismEnabled = false;
return this;
}

/**
* Disable the SDK health check. Once after init the SDK sends the server a short report about
* its own state: how many warnings and errors it logged, the last request the server refused,
* how often it had to wait for a slow server, how often its session, event, view and crash
* methods were called, and which known problems occurred. It carries no data the app recorded.
* The server shows it in the SDK Manager. With this option the report is not sent; the SDK
* keeps counting, as before.
*
* @return {@code this} instance for method chaining
*/
public Config disableHealthCheck() {
this.healthCheckEnabled = false;
return this;
}
}
104 changes: 52 additions & 52 deletions sdk-java/src/main/java/ly/count/sdk/java/Countly.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ly.count.sdk.java;

import java.io.File;
import java.util.Arrays;
import java.util.Map;
import ly.count.sdk.java.internal.Device;
import ly.count.sdk.java.internal.DeviceIdType;
Expand Down Expand Up @@ -100,7 +101,9 @@ public void init(final Config config) {
}

if (isInitialized()) {
L.e("[Countly] Countly shouldn't be initialized twice. Please either use Countly.isInitialized() to check status or call Countly.stop() before second Countly.init(). Calling 'init' the second time will now do nothing");
Log running = cly.L != null ? cly.L : L;
running.w("[Countly] Countly shouldn't be initialized twice. Please either use Countly.isInitialized() to check status or call Countly.stop() before second Countly.init(). Calling 'init' the second time will now do nothing");
running.recordLogCode("w110");
return;
}
internalConfig.setLogger(L);
Expand All @@ -110,7 +113,8 @@ public void init(final Config config) {
}

if (internalConfig.requestQueueMaxSize < 1) {
L.e("[Countly] init: Request queue max size can not be less than 1.");
L.w("[Countly] init: Request queue max size can not be less than 1.");
L.recordLogCode("w121");
internalConfig.requestQueueMaxSize = 1;
}

Expand Down Expand Up @@ -211,9 +215,7 @@ public static boolean isTracking(Config.Feature feature) {
*/
public static Session session() {
if (!isInitialized()) {
if (cly.L != null) {
cly.L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");

return null;
}
Expand All @@ -237,9 +239,7 @@ public static ModuleBackendMode.BackendMode backendMode() {
*/
public ModuleBackendMode.BackendMode backendM() {
if (!isInitialized()) {
if (cly.L != null) {
cly.L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return null;
} else {
ModuleBackendMode mbm = cly.sdk.module(ModuleBackendMode.class);
Expand Down Expand Up @@ -353,19 +353,44 @@ public Usage changeDeviceIdWithoutMerge(String id) {
*/
public static void onConsent(Config.Feature... features) {
if (!isInitialized()) {
Log.recordLogCodeWhileNotInitialized("w101");
} else {
if (cly.L != null) {
cly.L.e("[Countly] SDK is not initialized yet.");
cly.L.i("[Countly] onConsent: features = " + Arrays.toString(features));
}
} else {
cly.sdk.onConsent(consentFeatureIndexes("onConsent", features));
}
}

/**
* The feature bits a consent call names. A call that names no feature, or a {@code null}
* feature, is reported as log code w402; such a name is ignored.
*
* @param call the consent call, for the log
* @param features the features the call names
* @return the bits of the named features
*/
private static int consentFeatureIndexes(String call, Config.Feature... features) {
int ftrs = 0;
if (features == null || features.length == 0) {
if (cly.L != null) {
cly.L.e("[Countly] onConsent: features = " + features);
cly.L.w("[Countly] " + call + ", no feature is given, the call does nothing");
cly.L.recordLogCode("w402");
}
int ftrs = 0;
for (Config.Feature f : features) {
ftrs = ftrs | f.getIndex();
return ftrs;
}

for (Config.Feature f : features) {
if (f == null) {
if (cly.L != null) {
cly.L.w("[Countly] " + call + ", a 'null' feature is given, it is ignored");
cly.L.recordLogCode("w402");
}
continue;
}
cly.sdk.onConsent(ftrs);
ftrs = ftrs | f.getIndex();
}
return ftrs;
}

/**
Expand All @@ -377,18 +402,12 @@ public static void onConsent(Config.Feature... features) {
*/
public static void onConsentRemoval(Config.Feature... features) {
if (cly.L != null) {
cly.L.e("[Countly] onConsentRemoval: features = " + features);
cly.L.i("[Countly] onConsentRemoval: features = " + Arrays.toString(features));
}
if (!isInitialized()) {
if (cly.L != null) {
cly.L.e("[Countly] onConsentRemoval: SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
} else {
int ftrs = 0;
for (Config.Feature f : features) {
ftrs = ftrs | f.getIndex();
}
cly.sdk.onConsentRemoval(cly.sdk.config, ftrs);
cly.sdk.onConsentRemoval(cly.sdk.config, consentFeatureIndexes("onConsentRemoval", features));
}
}

Expand All @@ -401,9 +420,7 @@ public static void onConsentRemoval(Config.Feature... features) {
*/
public ModuleFeedback.Feedback feedback() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantFeedback;
}
return sdk.feedback();
Expand All @@ -420,9 +437,7 @@ public ModuleFeedback.Feedback feedback() {
*/
public ModuleContent.Content content() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] content, SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantContent;
}
return sdk.content();
Expand All @@ -436,9 +451,7 @@ public ModuleContent.Content content() {
*/
public ModuleRemoteConfig.RemoteConfig remoteConfig() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] remoteConfig, SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantRemoteConfig;
}
return sdk.remoteConfig();
Expand All @@ -452,9 +465,7 @@ public ModuleRemoteConfig.RemoteConfig remoteConfig() {
*/
public ModuleDeviceIdCore.DeviceId deviceId() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantDeviceId;
}
return sdk.deviceId();
Expand All @@ -481,9 +492,7 @@ public Event event(String key) {
*/
public ModuleEvents.Events events() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantEvents;
}
return sdk.events();
Expand All @@ -497,9 +506,7 @@ public ModuleEvents.Events events() {
*/
public ModuleCrashes.Crashes crashes() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantCrashes;
}
return sdk.crashes();
Expand All @@ -513,9 +520,7 @@ public ModuleCrashes.Crashes crashes() {
*/
public ModuleViews.Views views() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantViews;
}
return sdk.views();
Expand All @@ -542,9 +547,7 @@ public Event timedEvent(String key) {
*/
public ModuleUserProfile.UserProfile userProfile() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] userProfile, SDK is not initialized yet.");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantUserProfile;
}
return sdk.userProfile();
Expand All @@ -558,10 +561,7 @@ public ModuleUserProfile.UserProfile userProfile() {
*/
public ModuleLocation.Location location() {
if (!isInitialized()) {
// L is null before init, so this has to be guarded like every sibling accessor.
if (L != null) {
L.e("Countly.sharedInstance().init must be called before accessing location");
}
Log.recordLogCodeWhileNotInitialized("w101");
return SDKCore.dormantLocation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ private boolean prepareAndSend(final InternalConfig config, final Request reques
if (uploadsGatheredLogs) {
L.onLogBatchSent();
}
if (!backendMode && responseTimeMs.get() >= 0 && responseTimeMs.get() < config.getConfigurationProvider().getBOMAcceptedTimeoutSeconds() * 1000L) {
L.logConsecutiveBackoffRequest();
}
if (!backOffIfTheServerIsSlow(config, request, responseTimeMs.get())) {
check(config);
}
Expand Down Expand Up @@ -309,6 +312,7 @@ private boolean isOlderThanDropAge(@Nonnull InternalConfig config, @Nonnull Requ
*/
private boolean dropWithoutSending(@Nonnull InternalConfig config, @Nonnull Request request) {
L.w("[Networking] dropWithoutSending, request [" + request.storageId() + "] is older than the request drop age of [" + config.getConfigurationProvider().getRequestDropAgeHours() + "] hours set by the SDK behavior settings, dropping it without sending");
L.recordLogCode("w330");
if (!Boolean.TRUE.equals(storageForRequestQueue.removeRequest(request))) {
L.e("[Networking] dropWithoutSending, failed to remove request [" + request.storageId() + "], the queue drain stops here");
return false;
Expand Down Expand Up @@ -390,8 +394,12 @@ private boolean backOffIfTheServerIsSlow(@Nonnull InternalConfig config, @Nonnul
}

int durationSeconds = provider.getBOMDuration();
L.i("[Networking] backOffIfTheServerIsSlow, the server took [" + responseTimeMs + "] ms to answer request [" + request.storageId() + "] and [" + queuedRequests + "] requests remain queued, holding the request queue back for [" + durationSeconds + "] seconds");
return startBackoff(config, durationSeconds);
if (!startBackoff(config, durationSeconds)) {
return false;
}
L.w("[Networking] backOffIfTheServerIsSlow, the server took [" + responseTimeMs + "] ms to answer request [" + request.storageId() + "] and [" + queuedRequests + "] requests remain queued, holding the request queue back for [" + durationSeconds + "] seconds");
L.logBackoffRequest();
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ public void record() {
return;
}

L.w("[EventImpl] record, this function is deprecated, use 'events().recordEvent' instead");
L.recordLogCode("w120");
L.recordUsage(HealthCheckCounter.AREA_EVENTS, "record:d");
recordInternal();
}

/**
* Hands the event to its recorder once.
*/
private void recordInternal() {
if (recorder != null && !invalid) {
invalid = true;
recorder.recordEvent(this);
Expand All @@ -117,8 +127,11 @@ public void endAndRecord() {
return;
}

L.w("[EventImpl] endAndRecord, this function is deprecated, use 'events().endEvent' instead");
L.recordLogCode("w120");
L.recordUsage(HealthCheckCounter.AREA_EVENTS, "endAndRecord:d");
setDuration((TimeUtils.timestampMs() - timestamp) / 1000);
record();
recordInternal();
}

@Override
Expand Down
Loading
Loading