Skip to content

Commit c66a3d4

Browse files
authored
fix(ats): add proguard rule for ODPEvent (#456)
* add proguard rule for ODPEvent * clean up * clean up
1 parent 7b74992 commit c66a3d4

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

proguard-rules.txt

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
-keepclassmembers class com.optimizely.ab.config.** {
2525
*;
2626
}
27+
# Keep Payload classes that get sent to the ODP server
28+
-keep class com.optimizely.ab.odp.ODPEvent { *; }
2729

2830
# Keep Payload classes that get sent to Optimizely's backend
2931
-keep class com.optimizely.ab.event.internal.payload.** { *; }

test-app/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ android {
1717
unitTests.returnDefaultValues = true
1818
}
1919
buildTypes {
20+
debug {
21+
// enable proguard for debug mode (keep both of these to detect issues while testing)
22+
minifyEnabled true
23+
debuggable false
24+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
25+
}
2026
release {
2127
minifyEnabled true
2228
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

test-app/src/main/java/com/optimizely/ab/android/test_app/MyApplication.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2016-2021, Optimizely, Inc. and contributors *
2+
* Copyright 2016-2021, 2023 Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *

test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInJava.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2020, 2022, Optimizely, Inc. and contributors *
2+
* Copyright 2020, 2022-2023, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -90,9 +90,9 @@ static public void samplesAll(Context context) {
9090
samplesForDoc_NotificatonListener(context);
9191
samplesForDoc_OlderVersions(context);
9292
samplesForDoc_ForcedDecision(context);
93+
samplesForDoc_ODP(context);
9394
}
9495

95-
9696
static public void samplesForDecide(Context context) {
9797
// this default-options will be applied to all following decide calls.
9898
List<OptimizelyDecideOption> defaultDecideOptions = Arrays.asList(OptimizelyDecideOption.DISABLE_DECISION_EVENT);
@@ -859,4 +859,16 @@ static public void samplesForDoc_ForcedDecision(Context context) {
859859
success = user.removeAllForcedDecisions();
860860
}
861861

862-
}
862+
static public void samplesForDoc_ODP(Context context) {
863+
OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("VivZyCGPHY369D4z8T9yG").build(context);
864+
optimizelyManager.initialize(context, null, (OptimizelyClient client) -> {
865+
OptimizelyUserContext userContext = client.createUserContext("user_123");
866+
userContext.fetchQualifiedSegments((status) -> {
867+
Log.d("Optimizely", "[ODP] segments = " + userContext.getQualifiedSegments());
868+
OptimizelyDecision optDecision = userContext.decide("odp-flag-1");
869+
Log.d("Optimizely", "[ODP] decision = " + optDecision.toString());
870+
});
871+
});
872+
}
873+
874+
}

test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInKotlin.kt

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2022, Optimizely, Inc. and contributors *
2+
* Copyright 2022-2023, Optimizely, Inc. and contributors *
33
* *
44
* Licensed under the Apache License, Version 2.0 (the "License"); *
55
* you may not use this file except in compliance with the License. *
@@ -76,6 +76,7 @@ object APISamplesInKotlin {
7676
samplesForDoc_NotificatonListener(context)
7777
samplesForDoc_OlderVersions(context)
7878
samplesForDoc_ForcedDecision(context)
79+
samplesForDoc_ODP(context)
7980
}
8081

8182
fun samplesForDecide(context: Context) {
@@ -828,6 +829,19 @@ object APISamplesInKotlin {
828829
success = user.removeAllForcedDecisions()
829830
}
830831

832+
fun samplesForDoc_ODP(context: Context?) {
833+
val optimizelyManager =
834+
OptimizelyManager.builder().withSDKKey("VivZyCGPHY369D4z8T9yG").build(context)
835+
optimizelyManager.initialize(context!!, null) { client: OptimizelyClient ->
836+
val userContext = client.createUserContext("user_123")
837+
userContext!!.fetchQualifiedSegments { status: Boolean? ->
838+
Log.d("Optimizely", "[ODP] segments = " + userContext.qualifiedSegments)
839+
val optDecision = userContext.decide("odp-flag-1")
840+
Log.d("Optimizely", "[ODP] decision = $optDecision")
841+
}
842+
}
843+
}
844+
831845
}
832846

833847

0 commit comments

Comments
 (0)