From c66a3d4fbf3168b320a22b710fc851d0f792d0e0 Mon Sep 17 00:00:00 2001 From: Jae Kim <45045038+jaeopt@users.noreply.github.com> Date: Mon, 8 May 2023 09:43:57 -0700 Subject: [PATCH] fix(ats): add proguard rule for ODPEvent (#456) * add proguard rule for ODPEvent * clean up * clean up --- proguard-rules.txt | 2 ++ test-app/build.gradle | 6 ++++++ .../ab/android/test_app/MyApplication.kt | 2 +- .../test_app/Samples/APISamplesInJava.java | 18 +++++++++++++++--- .../test_app/Samples/APISamplesInKotlin.kt | 16 +++++++++++++++- 5 files changed, 39 insertions(+), 5 deletions(-) diff --git a/proguard-rules.txt b/proguard-rules.txt index d9a28f3a..c827f9be 100644 --- a/proguard-rules.txt +++ b/proguard-rules.txt @@ -24,6 +24,8 @@ -keepclassmembers class com.optimizely.ab.config.** { *; } +# Keep Payload classes that get sent to the ODP server +-keep class com.optimizely.ab.odp.ODPEvent { *; } # Keep Payload classes that get sent to Optimizely's backend -keep class com.optimizely.ab.event.internal.payload.** { *; } diff --git a/test-app/build.gradle b/test-app/build.gradle index e07aacc5..1e0d1508 100644 --- a/test-app/build.gradle +++ b/test-app/build.gradle @@ -17,6 +17,12 @@ android { unitTests.returnDefaultValues = true } buildTypes { + debug { + // enable proguard for debug mode (keep both of these to detect issues while testing) + minifyEnabled true + debuggable false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' diff --git a/test-app/src/main/java/com/optimizely/ab/android/test_app/MyApplication.kt b/test-app/src/main/java/com/optimizely/ab/android/test_app/MyApplication.kt index ce16faaf..abfe9ce6 100644 --- a/test-app/src/main/java/com/optimizely/ab/android/test_app/MyApplication.kt +++ b/test-app/src/main/java/com/optimizely/ab/android/test_app/MyApplication.kt @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2016-2021, Optimizely, Inc. and contributors * + * Copyright 2016-2021, 2023 Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * diff --git a/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInJava.java b/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInJava.java index fdabf826..3b7016dd 100644 --- a/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInJava.java +++ b/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInJava.java @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2020, 2022, Optimizely, Inc. and contributors * + * Copyright 2020, 2022-2023, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -90,9 +90,9 @@ static public void samplesAll(Context context) { samplesForDoc_NotificatonListener(context); samplesForDoc_OlderVersions(context); samplesForDoc_ForcedDecision(context); + samplesForDoc_ODP(context); } - static public void samplesForDecide(Context context) { // this default-options will be applied to all following decide calls. List defaultDecideOptions = Arrays.asList(OptimizelyDecideOption.DISABLE_DECISION_EVENT); @@ -859,4 +859,16 @@ static public void samplesForDoc_ForcedDecision(Context context) { success = user.removeAllForcedDecisions(); } -} \ No newline at end of file + static public void samplesForDoc_ODP(Context context) { + OptimizelyManager optimizelyManager = OptimizelyManager.builder().withSDKKey("VivZyCGPHY369D4z8T9yG").build(context); + optimizelyManager.initialize(context, null, (OptimizelyClient client) -> { + OptimizelyUserContext userContext = client.createUserContext("user_123"); + userContext.fetchQualifiedSegments((status) -> { + Log.d("Optimizely", "[ODP] segments = " + userContext.getQualifiedSegments()); + OptimizelyDecision optDecision = userContext.decide("odp-flag-1"); + Log.d("Optimizely", "[ODP] decision = " + optDecision.toString()); + }); + }); + } + +} diff --git a/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInKotlin.kt b/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInKotlin.kt index 1107d5de..342bbef9 100644 --- a/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInKotlin.kt +++ b/test-app/src/main/java/com/optimizely/ab/android/test_app/Samples/APISamplesInKotlin.kt @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2022, Optimizely, Inc. and contributors * + * Copyright 2022-2023, Optimizely, Inc. and contributors * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * @@ -76,6 +76,7 @@ object APISamplesInKotlin { samplesForDoc_NotificatonListener(context) samplesForDoc_OlderVersions(context) samplesForDoc_ForcedDecision(context) + samplesForDoc_ODP(context) } fun samplesForDecide(context: Context) { @@ -828,6 +829,19 @@ object APISamplesInKotlin { success = user.removeAllForcedDecisions() } + fun samplesForDoc_ODP(context: Context?) { + val optimizelyManager = + OptimizelyManager.builder().withSDKKey("VivZyCGPHY369D4z8T9yG").build(context) + optimizelyManager.initialize(context!!, null) { client: OptimizelyClient -> + val userContext = client.createUserContext("user_123") + userContext!!.fetchQualifiedSegments { status: Boolean? -> + Log.d("Optimizely", "[ODP] segments = " + userContext.qualifiedSegments) + val optDecision = userContext.decide("odp-flag-1") + Log.d("Optimizely", "[ODP] decision = $optDecision") + } + } + } + }