Skip to content

Commit

Permalink
[Java] Module RC init and refactor for preparations (#140)
Browse files Browse the repository at this point in the history
* feat: rc init

* Update CHANGELOG.md

---------

Co-authored-by: Artūrs Kadiķis <[email protected]>
  • Loading branch information
arifBurakDemiray and ArtursKadikis authored Oct 31, 2023
1 parent 0a29fe9 commit 6e99812
Show file tree
Hide file tree
Showing 14 changed files with 168 additions and 477 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
* Session update time duration increased to 60 seconds from 30 seconds.
* Adding remaining request queue size information to every request.
* Adding application version information to every request.
* Added the remote config feature.
* Remote Config module is accessible through "Countly::instance()::remoteConfig()" call.
* Added configuration functions to configure Remote Config module on init:
* 'enableRemoteConfigValueCaching' to enable caching of remote config values
* 'enrollABOnRCDownload' to enroll A/B tests when remote config values downloaded
* 'enableRemoteConfigAutomaticTriggers' to automatically download remote config values on init
* 'remoteConfigRegisterGlobalCallback(RCDownloadCallback callback)' to register a remote config callback
* Added the ability to set the user profile picture with an URL

* Fixed a bug where it was not possible to send a profile picture with binary data
Expand Down
74 changes: 61 additions & 13 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import ly.count.sdk.java.internal.Byteable;
import ly.count.sdk.java.internal.CoreFeature;
import ly.count.sdk.java.internal.Log;
import ly.count.sdk.java.internal.LogCallback;
import ly.count.sdk.java.internal.ModuleBase;
import ly.count.sdk.java.internal.RCDownloadCallback;
import ly.count.sdk.java.internal.Utils;

/**
Expand Down Expand Up @@ -81,9 +84,9 @@ public enum Feature {
CrashReporting(CoreFeature.CrashReporting.getIndex()),
Location(CoreFeature.Location.getIndex()),
UserProfiles(CoreFeature.UserProfiles.getIndex()),
Feedback(CoreFeature.Feedback.getIndex());
Feedback(CoreFeature.Feedback.getIndex()),
RemoteConfig(CoreFeature.RemoteConfig.getIndex());
// StarRating(1 << 12),
// RemoteConfig(1 << 13),
// PerformanceMonitoring(1 << 14);

private final int index;
Expand All @@ -109,12 +112,8 @@ public static Config.Feature byIndex(int index) {
return Location;
} else if (index == UserProfiles.index) {
return UserProfiles;
// } else if (index == StarRating.index) {
// return StarRating;
// } else if (index == RemoteConfig.index) {
// return RemoteConfig;
// } else if (index == PerformanceMonitoring.index) {
// return PerformanceMonitoring;
} else if (index == RemoteConfig.index) {
return RemoteConfig;
} else if (index == Feedback.index) {
return Feedback;
} else {
Expand Down Expand Up @@ -447,17 +446,26 @@ public boolean restore(byte[] data, Log L) {

//endregion

//region Remote Config Module fields
//Begin Remote Config Module Fields

/**
* If remote config automatic fetching should be enabled
*/
protected Boolean enableAutomaticRemoteConfig = null;
protected boolean enableRemoteConfigAutomaticDownloadTriggers = false;

/**
* After how much time the request is canceled and timeout error returned
* If remote config value caching should be enabled
*/
protected Long remoteConfigUpdateRequestTimeout = null;
protected boolean enableRemoteConfigValueCaching = false;

/**
* If automatic remote config enrollment should be enabled
*/
protected boolean enableAutoEnrollFlag = false;

protected List<RCDownloadCallback> remoteConfigGlobalCallbacks = new ArrayList<>();

//End Remote Config Module Fields

/**
* Maximum in memory request queue size.
Expand Down Expand Up @@ -1563,5 +1571,45 @@ public Config setSdkPlatform(String platform) {
public String getSdkPlatform() {
return sdkPlatform;
}
}

/**
* Enable automatic download of remote config values
*
* @return {@code this} instance for method chaining
*/
public Config enableRemoteConfigAutomaticTriggers() {
this.enableRemoteConfigAutomaticDownloadTriggers = true;
return this;
}

/**
* Enable caching of remote config values
*
* @return {@code this} instance for method chaining
*/
public Config enableRemoteConfigValueCaching() {
this.enableRemoteConfigValueCaching = true;
return this;
}

/**
* Enable automatic enroll for AB
*
* @return {@code this} instance for method chaining
*/
public Config enrollABOnRCDownload() {
this.enableAutoEnrollFlag = true;
return this;
}

/**
* Register a callback to be called when remote config is downloaded
*
* @param callback to be called see {@link RCDownloadCallback}
* @return {@code this} instance for method chaining
*/
public Config remoteConfigRegisterGlobalCallback(RCDownloadCallback callback) {
remoteConfigGlobalCallbacks.add(callback);
return this;
}
}
16 changes: 16 additions & 0 deletions sdk-java/src/main/java/ly/count/sdk/java/Countly.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ly.count.sdk.java.internal.ModuleBackendMode;
import ly.count.sdk.java.internal.ModuleEvents;
import ly.count.sdk.java.internal.ModuleFeedback;
import ly.count.sdk.java.internal.ModuleRemoteConfig;
import ly.count.sdk.java.internal.SDKCore;

/**
Expand Down Expand Up @@ -345,6 +346,21 @@ public ModuleFeedback.Feedback feedback() {
return sdk.feedback();
}

/**
* <code>RemoteConfig</code> interface to use remote config feature.
*
* @return {@link ModuleRemoteConfig.RemoteConfig} instance.
*/
public ModuleRemoteConfig.RemoteConfig remoteConfig() {
if (!isInitialized()) {
if (L != null) {
L.e("[Countly] remoteConfig, SDK is not initialized yet.");
}
return null;
}
return sdk.remoteConfig();
}

/**
* Record event with provided key.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,20 @@ public Boolean getStarRatingDisabledForNewVersion() {
//endregion

//region remote config
public Boolean getRemoteConfigAutomaticUpdateEnabled() {
return enableAutomaticRemoteConfig;
public boolean isRemoteConfigAutomaticDownloadTriggersEnabled() {
return enableRemoteConfigAutomaticDownloadTriggers;
}

public Long getRemoteConfigUpdateTimeoutLength() {
return remoteConfigUpdateRequestTimeout;
public boolean isRemoteConfigValueCachingEnabled() {
return enableRemoteConfigValueCaching;
}

public boolean isAutoEnrollFlagEnabled() {
return enableAutoEnrollFlag;
}

public List<RCDownloadCallback> getRemoteConfigGlobalCallbackList() {
return remoteConfigGlobalCallbacks;
}
//endregion

Expand Down
Loading

0 comments on commit 6e99812

Please sign in to comment.