-
Couldn't load subscription status.
- Fork 38
[FSSDK-11136] add cmab support #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jaeopt
wants to merge
7
commits into
master
Choose a base branch
from
jae/FSSDK-11136
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
221 changes: 221 additions & 0 deletions
221
android-sdk/src/main/java/com/optimizely/ab/android/sdk/OptimizelyUserContextAndroid.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,221 @@ | ||
| // Copyright 2025, 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. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package com.optimizely.ab.android.sdk; | ||
|
|
||
| import com.optimizely.ab.Optimizely; | ||
| import com.optimizely.ab.OptimizelyForcedDecision; | ||
| import com.optimizely.ab.OptimizelyUserContext; | ||
| import com.optimizely.ab.optimizelydecision.OptimizelyDecideOption; | ||
| import com.optimizely.ab.optimizelydecision.OptimizelyDecision; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
|
|
||
| // This class extends OptimizelyUserContext from the Java-SDK core to maintain backward compatibility | ||
| // with synchronous decide API calls. It ensures proper functionality for legacy implementations | ||
| // that rely on synchronous behavior, while excluding feature flags that require asynchronous decisions. | ||
|
|
||
| public class OptimizelyUserContextAndroid extends OptimizelyUserContext { | ||
| public OptimizelyUserContextAndroid(@NonNull Optimizely optimizely, | ||
| @NonNull String userId, | ||
| @NonNull Map<String, ?> attributes) { | ||
| super(optimizely, userId, attributes); | ||
| } | ||
|
|
||
| public OptimizelyUserContextAndroid(@NonNull Optimizely optimizely, | ||
| @NonNull String userId, | ||
| @NonNull Map<String, ?> attributes, | ||
| @Nullable Map<String, OptimizelyForcedDecision> forcedDecisionsMap, | ||
| @Nullable List<String> qualifiedSegments) { | ||
| super(optimizely, userId, attributes, forcedDecisionsMap, qualifiedSegments); | ||
| } | ||
|
|
||
| public OptimizelyUserContextAndroid(@NonNull Optimizely optimizely, | ||
| @NonNull String userId, | ||
| @NonNull Map<String, ?> attributes, | ||
| @Nullable Map<String, OptimizelyForcedDecision> forcedDecisionsMap, | ||
| @Nullable List<String> qualifiedSegments, | ||
| @Nullable Boolean shouldIdentifyUser) { | ||
| super(optimizely, userId, attributes, forcedDecisionsMap, qualifiedSegments, shouldIdentifyUser); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a decision result ({@link OptimizelyDecision}) for a given flag key and a user context, which contains all data required to deliver the flag. | ||
| * <ul> | ||
| * <li>If the SDK finds an error, it’ll return a decision with <b>null</b> for <b>variationKey</b>. The decision will include an error message in <b>reasons</b>. | ||
| * </ul> | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideAsync() API. | ||
| * </p> | ||
| * @param key A flag key for which a decision will be made. | ||
| * @param options A list of options for decision-making. | ||
| * @return A decision result. | ||
| */ | ||
| @Override | ||
| public OptimizelyDecision decide(@NonNull String key, | ||
| @NonNull List<OptimizelyDecideOption> options) { | ||
| return optimizely.decideSync(copy(), key, options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a decision result ({@link OptimizelyDecision}) for a given flag key and a user context, which contains all data required to deliver the flag. | ||
| * | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideAsync() API. | ||
| * </p> | ||
| * @param key A flag key for which a decision will be made. | ||
| * @return A decision result. | ||
| */ | ||
| @Override | ||
| public OptimizelyDecision decide(@NonNull String key) { | ||
| return decide(key, Collections.emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a key-map of decision results ({@link OptimizelyDecision}) for multiple flag keys and a user context. | ||
| * <ul> | ||
| * <li>If the SDK finds an error for a key, the response will include a decision for the key showing <b>reasons</b> for the error. | ||
| * <li>The SDK will always return key-mapped decisions. When it can not process requests, it’ll return an empty map after logging the errors. | ||
| * </ul> | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideForKeysAsync() API. | ||
| * </p> | ||
| * @param keys A list of flag keys for which decisions will be made. | ||
| * @param options A list of options for decision-making. | ||
| * @return All decision results mapped by flag keys. | ||
| */ | ||
| @Override | ||
| public Map<String, OptimizelyDecision> decideForKeys(@NonNull List<String> keys, | ||
| @NonNull List<OptimizelyDecideOption> options) { | ||
| return optimizely.decideForKeysSync(copy(), keys, options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a key-map of decision results for multiple flag keys and a user context. | ||
| * | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideForKeysAsync() API. | ||
| * </p> | ||
| * @param keys A list of flag keys for which decisions will be made. | ||
| * @return All decision results mapped by flag keys. | ||
| */ | ||
| @Override | ||
| public Map<String, OptimizelyDecision> decideForKeys(@NonNull List<String> keys) { | ||
| return decideForKeys(keys, Collections.emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a key-map of decision results ({@link OptimizelyDecision}) for all active flag keys. | ||
| * | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideAllAsync() API. | ||
| * </p> | ||
| * @param options A list of options for decision-making. | ||
| * @return All decision results mapped by flag keys. | ||
| */ | ||
| @Override | ||
| public Map<String, OptimizelyDecision> decideAll(@NonNull List<OptimizelyDecideOption> options) { | ||
| return optimizely.decideAllSync(copy(), options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a key-map of decision results ({@link OptimizelyDecision}) for all active flag keys. | ||
| * | ||
| * <p> | ||
| * Note: This API is specifically designed for synchronous decision-making only. | ||
| * For asynchronous decision-making, use the decideAllAsync() API. | ||
| * </p> | ||
| * @return A dictionary of all decision results, mapped by flag keys. | ||
| */ | ||
| @Override | ||
| public Map<String, OptimizelyDecision> decideAll() { | ||
| return decideAll(Collections.emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a decision result asynchronously for a given flag key and a user context. | ||
| * | ||
| * @param key A flag key for which a decision will be made. | ||
| * @param callback A callback to invoke when the decision is available. | ||
| * @param options A list of options for decision-making. | ||
| */ | ||
| public void decideAsync(@Nonnull String key, | ||
| @Nonnull OptimizelyDecisionCallback callback, | ||
| @Nonnull List<OptimizelyDecideOption> options) { | ||
| optimizely.decideAsync(copy(), key, callback, options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a decision result asynchronously for a given flag key and a user context. | ||
| * | ||
| * @param key A flag key for which a decision will be made. | ||
| * @param callback A callback to invoke when the decision is available. | ||
| */ | ||
| public void decideAsync(@Nonnull String key, @Nonnull OptimizelyDecisionCallback callback) { | ||
| decideAsync(key, callback, Collections.emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns decision results asynchronously for multiple flag keys. | ||
| * | ||
| * @param keys A list of flag keys for which decisions will be made. | ||
| * @param callback A callback to invoke when decisions are available. | ||
| * @param options A list of options for decision-making. | ||
| */ | ||
| public void decideForKeysAsync(@Nonnull List<String> keys, | ||
| @Nonnull OptimizelyDecisionsCallback callback, | ||
| @Nonnull List<OptimizelyDecideOption> options) { | ||
| optimizely.decideForKeysAsync(copy(), keys, callback, options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns decision results asynchronously for multiple flag keys. | ||
| * | ||
| * @param keys A list of flag keys for which decisions will be made. | ||
| * @param callback A callback to invoke when decisions are available. | ||
| */ | ||
| public void decideForKeysAsync(@Nonnull List<String> keys, @Nonnull OptimizelyDecisionsCallback callback) { | ||
| decideForKeysAsync(keys, callback, Collections.emptyList()); | ||
| } | ||
|
|
||
| /** | ||
| * Returns decision results asynchronously for all active flag keys. | ||
| * | ||
| * @param callback A callback to invoke when decisions are available. | ||
| * @param options A list of options for decision-making. | ||
| */ | ||
| public void decideAllAsync(@Nonnull OptimizelyDecisionsCallback callback, | ||
| @Nonnull List<OptimizelyDecideOption> options) { | ||
| optimizely.decideAllAsync(copy(), callback, options); | ||
| } | ||
|
|
||
| /** | ||
| * Returns decision results asynchronously for all active flag keys. | ||
| * | ||
| * @param callback A callback to invoke when decisions are available. | ||
| */ | ||
| public void decideAllAsync(@Nonnull OptimizelyDecisionsCallback callback) { | ||
| decideAllAsync(callback, Collections.emptyList()); | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For swift CmabClient is internal, here it is public, why this difference?