Skip to content

Commit

Permalink
[Java] Ability to override platform (#83)
Browse files Browse the repository at this point in the history
* feat: sdk platform

* fix: change to ooss name
  • Loading branch information
arifBurakDemiray authored Sep 28, 2023
1 parent f122322 commit d3ccbaf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
27 changes: 25 additions & 2 deletions sdk-java/src/main/java/ly/count/sdk/java/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.Set;
import ly.count.sdk.java.internal.Byteable;
import ly.count.sdk.java.internal.CoreFeature;
import ly.count.sdk.java.internal.ImmediateRequestGenerator;
import ly.count.sdk.java.internal.Log;
import ly.count.sdk.java.internal.LogCallback;
import ly.count.sdk.java.internal.ModuleBase;
Expand Down Expand Up @@ -467,7 +466,10 @@ public boolean restore(byte[] data, Log L) {
*/
File sdkStorageRootDirectory = null;

protected ImmediateRequestGenerator immediateRequestGenerator = null;
/**
* If sdk used across multiple platforms
*/
protected String sdkPlatform = System.getProperty("os.name");

// /**
// * Maximum size of all string keys
Expand Down Expand Up @@ -1522,5 +1524,26 @@ public Config setMetricOverride(Map<String, String> metricOverride) {
this.metricOverride.putAll(metricOverride);
return this;
}

/**
* Default sdk platform is os name
* If you want to override it, you can use this method
*
* @param platform sdk platform
* @return {@code this} instance for method chaining
*/
public Config setSdkPlatform(String platform) {
this.sdkPlatform = platform;
return this;
}

/**
* Getter for {@link #sdkPlatform}
*
* @return {@link #sdkPlatform} value
*/
public String getSdkPlatform() {
return sdkPlatform;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

class ViewImpl implements View {
private Log L = null;

static final String EVENT = "[CLY]_view";
static final String NAME = "name";
static final String VISIT = "visit";
static final String VISIT_VALUE = "1";
static final String SEGMENT = "segment";
static final String SEGMENT_VALUE = System.getProperty("os.name");
static final String START = "start";
static final String START_VALUE = "1";
static final String EXIT = "exit";
Expand Down Expand Up @@ -49,7 +47,7 @@ public void start(boolean firstView) {
this.started = true;
this.firstView = firstView;

start = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, VISIT, VISIT_VALUE, SEGMENT, Device.dev.getOS());
start = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, VISIT, VISIT_VALUE, SEGMENT, SDKCore.instance.config.getSdkPlatform());

if (firstView) {
start.addSegment(START, START_VALUE);
Expand All @@ -76,8 +74,7 @@ public void stop(boolean lastView) {
return;
}
ended = true;

EventImpl event = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, SEGMENT, SEGMENT_VALUE);
EventImpl event = (EventImpl) session.event(EVENT).addSegments(NAME, this.name, SEGMENT, SDKCore.instance.config.getSdkPlatform());

long startTs = Device.dev.uniqueTimestamp();
long endTs = start.getTimestamp();
Expand Down
14 changes: 0 additions & 14 deletions sdk-java/src/test/java/ly/count/sdk/java/internal/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,4 @@ private static Map<String, String> parseRequestParams(File file) throws IOExcept
return paramMap;
}
}

static File getSdkStorageRootDirectory() {
// System specific folder structure
String[] sdkStorageRootPath = { System.getProperty("user.home"), "__COUNTLY", "java_test" };
return new File(String.join(File.separator, sdkStorageRootPath));
}

static void checkSdkStorageRootDirectoryExist(File directory) {
if (!(directory.exists() && directory.isDirectory())) {
if (!directory.mkdirs()) {
throw new RuntimeException("Directory creation failed");
}
}
}
}

0 comments on commit d3ccbaf

Please sign in to comment.