Skip to content

Commit 167cd36

Browse files
authored
Merge pull request #483 from Countly/disable_sc
feat: disable server config call
2 parents e00940a + 2eab782 commit 167cd36

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## XX.XX.XX
2+
* Added a config method to disable server config in the initialization "disableSDKBehaviorSettings()".
3+
14
## 25.4.0
25
* ! Minor breaking change ! Removed Secure.ANDROID_ID usage in device id generation. The SDK now exclusively uses random UUIDs for device id generation.
36
* ! 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.

sdk/src/main/java/ly/count/android/sdk/CountlyConfig.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public class CountlyConfig {
202202
// Requests older than this value in hours would be dropped (0 means this feature is disabled)
203203
int dropAgeHours = 0;
204204
String sdkBehaviorSettings;
205+
boolean sdkBehaviorSettingsDisabled = false;
205206

206207
/**
207208
* THIS VARIABLE SHOULD NOT BE USED
@@ -1012,6 +1013,16 @@ public synchronized CountlyConfig setSDKBehaviorSettings(String sdkBehaviorSetti
10121013
return this;
10131014
}
10141015

1016+
/**
1017+
* Disable the SDK behavior settings
1018+
*
1019+
* @return Returns the same config object for convenient linking
1020+
*/
1021+
public synchronized CountlyConfig disableSDKBehaviorSettings() {
1022+
this.sdkBehaviorSettingsDisabled = true;
1023+
return this;
1024+
}
1025+
10151026
/**
10161027
* APM configuration interface to be used with CountlyConfig
10171028
*/

sdk/src/main/java/ly/count/android/sdk/ModuleConfiguration.java

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider {
5656
Integer serverConfigUpdateInterval;
5757
int currentServerConfigUpdateInterval = 4;
5858
long lastServerConfigFetchTimestamp = -1;
59+
private boolean serverConfigDisabled = false;
5960

6061
ModuleConfiguration(@NonNull Countly cly, @NonNull CountlyConfig config) {
6162
super(cly, config);
@@ -66,22 +67,27 @@ class ModuleConfiguration extends ModuleBase implements ConfigurationProvider {
6667
immediateRequestGenerator = config.immediateRequestGenerator;
6768
serverConfigUpdateTimer = new CountlyTimer();
6869
serverConfigUpdateInterval = currentServerConfigUpdateInterval;
70+
serverConfigDisabled = config.sdkBehaviorSettingsDisabled;
6971

7072
config.countlyStore.setConfigurationProvider(this);
7173

72-
//load the previously saved configuration
73-
loadConfigFromStorage(config.sdkBehaviorSettings);
74-
75-
//update the config variables according to the new state
76-
updateConfigVariables(config);
74+
if (!serverConfigDisabled) {
75+
//load the previously saved configuration
76+
loadConfigFromStorage(config.sdkBehaviorSettings);
77+
78+
//update the config variables according to the new state
79+
updateConfigVariables(config);
80+
}
7781
}
7882

7983
@Override
8084
void initFinished(@NonNull final CountlyConfig config) {
8185
//once the SDK has loaded, init fetching the server config
8286
L.d("[ModuleConfiguration] initFinished");
83-
fetchConfigFromServer(config);
84-
startServerConfigUpdateTimer();
87+
if (!serverConfigDisabled) {
88+
fetchConfigFromServer(config);
89+
startServerConfigUpdateTimer();
90+
}
8591
}
8692

8793
@Override
@@ -110,7 +116,6 @@ public void run() {
110116
* Reads from storage to local json objects
111117
*/
112118
void loadConfigFromStorage(@Nullable String sdkBehaviorSettings) {
113-
114119
String sConfig = storageProvider.getServerConfig();
115120

116121
if (Utils.isNullOrEmpty(sConfig)) {
@@ -256,6 +261,9 @@ void saveAndStoreDownloadedConfig(@NonNull JSONObject config, @NonNull CountlyCo
256261
* }
257262
*/
258263
void fetchConfigFromServer(@NonNull CountlyConfig config) {
264+
if (serverConfigDisabled) {
265+
return;
266+
}
259267
L.v("[ModuleConfiguration] fetchConfigFromServer");
260268

261269
// 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) {
283291
}
284292

285293
void fetchIfTimeIsUpForFetchingServerConfig() {
294+
if (serverConfigDisabled) {
295+
return;
296+
}
297+
286298
if (lastServerConfigFetchTimestamp > 0) {
287299
long currentTime = UtilsTime.currentTimestampMs();
288300
long timePassed = currentTime - lastServerConfigFetchTimestamp;

0 commit comments

Comments
 (0)