Skip to content
Draft
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
39 changes: 39 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 @@ -245,6 +245,20 @@ public class Config {
protected boolean locationEnabled = true;
protected boolean autoSendUserProperties = true;

/**
* Seed value for the SDK behavior settings. Used on first init only,
* when no settings have yet been persisted; subsequent inits use the
* value pulled from storage.
*/
protected String sdkBehaviorSettings = null;

/**
* If {@code true}, the SDK skips the periodic {@code /o/sdk?method=sc}
* fetch. The seed JSON from {@link #setSdkBehaviorSettings(String)} (or
* a previously-persisted snapshot) is still applied.
*/
protected boolean sdkBehaviorSettingsRequestsDisabled = false;

// TODO: storage limits & configuration
// protected int maxRequestsStored = 0;
// protected int storageDirectory = "";
Expand Down Expand Up @@ -1497,4 +1511,29 @@ public Config disableAutoSendUserProperties() {
this.autoSendUserProperties = false;
return this;
}

/**
* Provide an initial SDK behavior settings payload to apply at init time,
* before the first {@code /o/sdk?method=sc} fetch returns. The value is
* the same JSON shape the Countly server emits: {@code {"v":1,"t":<ts>,
* "c":{...}}}. The seed is only used when nothing has been persisted yet.
*
* @param sdkBehaviorSettings serialized config JSON, or {@code null} for none
* @return {@code this} instance for method chaining
*/
public Config setSdkBehaviorSettings(String sdkBehaviorSettings) {
this.sdkBehaviorSettings = sdkBehaviorSettings;
return this;
}

/**
* Disable the periodic SDK behavior settings fetch from the server. Any
* seed JSON or previously-persisted snapshot is still applied at init.
*
* @return {@code this} instance for method chaining
*/
public Config disableSdkBehaviorSettingsUpdates() {
this.sdkBehaviorSettingsRequestsDisabled = true;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ly.count.sdk.java.internal;

/**
* Source of truth for the runtime feature toggles that come from
* the server-driven SDK behavior settings ({@code /o/sdk?method=sc}).
*
* The default implementation lives in {@link ModuleConfiguration}. When no
* behavior settings have been received, every getter returns {@code true}
* (the safe default) so the SDK behaves identically to a pre-feature build.
*/
public interface ConfigurationProvider {

boolean getNetworkingEnabled();

boolean getTrackingEnabled();

boolean getSessionTrackingEnabled();

boolean getViewTrackingEnabled();

boolean getCustomEventTrackingEnabled();

boolean getCrashReportingEnabled();

boolean getLocationTrackingEnabled();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public enum CoreFeature {
DeviceId(1 << 20, ModuleDeviceIdCore::new),
Requests(1 << 21, ModuleRequests::new),
Logs(1 << 22),
Feedback(1 << 23, ModuleFeedback::new);
Feedback(1 << 23, ModuleFeedback::new),
Configuration(1 << 24, ModuleConfiguration::new);

private final int index;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ protected Tasks.Task<Boolean> submit(final InternalConfig config) {
return new Tasks.Task<Boolean>(Tasks.ID_STRICT) {
@Override
public Boolean call() throws Exception {
if (!config.getNetworkingEnabled()) {
L.d("[Networking] submit, networking disabled by SDK behavior settings; skipping queue drain");
return false;
}
final Request request = storageForRequestQueue.getNextRequest();
if (request == null) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ public class InternalConfig extends Config {
protected IdGenerator viewIdGenerator;
protected IdGenerator eventIdGenerator;
protected ViewIdProvider viewIdProvider;
/**
* Set by {@link ModuleConfiguration} at construction time; remains
* {@code null} until that module runs, which means callers must
* tolerate that absence (treat it as "no overrides yet").
*/
public ConfigurationProvider configProvider;

/**
* Shouldn't be used!
Expand Down Expand Up @@ -144,13 +150,26 @@ public void setDefaultNetworking(boolean defaultNetworking) {
}

/**
* This feature is not yet implemented
* and always return true
* Whether the SDK is currently allowed to perform network requests.
* Defaults to {@code true}; the value is overridden when a SDK
* behavior settings payload from the server toggles {@code networking}
* off (see {@link ModuleConfiguration}).
*
* @return true
* @return {@code true} if networking is allowed
*/
public boolean getNetworkingEnabled() {
return true;
if (configProvider == null) {
return true;
}
return configProvider.getNetworkingEnabled();
}

public String getSdkBehaviorSettings() {
return sdkBehaviorSettings;
}

public boolean isSdkBehaviorSettingsRequestsDisabled() {
return sdkBehaviorSettingsRequestsDisabled;
}

/**
Expand Down
Loading
Loading