diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4642eb7..0cb21db1b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## XX.XX.XX +* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()". + ## 25.4.0 * ! Minor breaking change ! Removed Secure.ANDROID_ID usage in device id generation. The SDK now exclusively uses random UUIDs for device id generation. * ! Minor breaking change ! Server Configuration is now enabled by default. Changes made on SDK Manager > SDK Configuration on your server will affect SDK behavior directly. diff --git a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java index 8aedaefa0..aef3f2192 100644 --- a/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java +++ b/sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java @@ -202,6 +202,7 @@ public class CountlyConfig { // Requests older than this value in hours would be dropped (0 means this feature is disabled) int dropAgeHours = 0; String sdkBehaviorSettings; + boolean sdkBehaviorSettingsDisabled = false; /** * THIS VARIABLE SHOULD NOT BE USED @@ -1012,6 +1013,16 @@ public synchronized CountlyConfig setSDKBehaviorSettings(String sdkBehaviorSetti return this; } + /** + * Disable the SDK behavior settings + * + * @return Returns the same config object for convenient linking + */ + public synchronized CountlyConfig disableSDKBehaviorSettings() { + this.sdkBehaviorSettingsDisabled = true; + return this; + } + /** * APM configuration interface to be used with CountlyConfig */ diff --git a/sdk/src/main/java/ly/count/android/sdk/ModuleConfiguration.java b/sdk/src/main/java/ly/count/android/sdk/ModuleConfiguration.java index ca7ff943d..99aa28fde 100644 --- a/sdk/src/main/java/ly/count/android/sdk/ModuleConfiguration.java +++ b/sdk/src/main/java/ly/count/android/sdk/ModuleConfiguration.java @@ -56,6 +56,7 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider { Integer serverConfigUpdateInterval; int currentServerConfigUpdateInterval = 4; long lastServerConfigFetchTimestamp = -1; + private boolean serverConfigDisabled = false; ModuleConfiguration(@NonNull Countly cly, @NonNull CountlyConfig config) { super(cly, config); @@ -66,22 +67,27 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider { immediateRequestGenerator = config.immediateRequestGenerator; serverConfigUpdateTimer = new CountlyTimer(); serverConfigUpdateInterval = currentServerConfigUpdateInterval; + serverConfigDisabled = config.sdkBehaviorSettingsDisabled; config.countlyStore.setConfigurationProvider(this); - //load the previously saved configuration - loadConfigFromStorage(config.sdkBehaviorSettings); - - //update the config variables according to the new state - updateConfigVariables(config); + if (!serverConfigDisabled) { + //load the previously saved configuration + loadConfigFromStorage(config.sdkBehaviorSettings); + + //update the config variables according to the new state + updateConfigVariables(config); + } } @Override void initFinished(@NonNull final CountlyConfig config) { //once the SDK has loaded, init fetching the server config L.d("[ModuleConfiguration] initFinished"); - fetchConfigFromServer(config); - startServerConfigUpdateTimer(); + if (!serverConfigDisabled) { + fetchConfigFromServer(config); + startServerConfigUpdateTimer(); + } } @Override @@ -110,7 +116,6 @@ public void run() { * Reads from storage to local json objects */ void loadConfigFromStorage(@Nullable String sdkBehaviorSettings) { - String sConfig = storageProvider.getServerConfig(); if (Utils.isNullOrEmpty(sConfig)) { @@ -256,6 +261,9 @@ void saveAndStoreDownloadedConfig(@NonNull JSONObject config, @NonNull CountlyCo * } */ void fetchConfigFromServer(@NonNull CountlyConfig config) { + if (serverConfigDisabled) { + return; + } L.v("[ModuleConfiguration] fetchConfigFromServer"); // why _cly? because module configuration is created before module device id, so we need to access it like this @@ -283,6 +291,10 @@ void fetchConfigFromServer(@NonNull CountlyConfig config) { } void fetchIfTimeIsUpForFetchingServerConfig() { + if (serverConfigDisabled) { + return; + } + if (lastServerConfigFetchTimestamp > 0) { long currentTime = UtilsTime.currentTimestampMs(); long timePassed = currentTime - lastServerConfigFetchTimestamp;