Skip to content

Commit 016f302

Browse files
committed
Updated enum and changed request format
1 parent 6ac68fe commit 016f302

File tree

4 files changed

+34
-27
lines changed

4 files changed

+34
-27
lines changed

Branch-SDK-Automation-TestBed/src/main/java/io/branch/branchandroiddemo/BranchWrapper.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,18 @@ public void setAttributionLevel(Intent intent){
260260
if (testDataStr != null) {
261261

262262
TestData testDataObj = new TestData();
263-
String level = testDataObj.getParamValue(testDataStr,"consumer_protection_attribution_level");
263+
String level = testDataObj.getParamValue(testDataStr,"cpp_level");
264264

265265
//Set the level based on the level value
266-
if (Objects.equals(level, "0")) {
267-
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.FULL);
268-
} else if (Objects.equals(level, "1")) {
269-
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.REDUCED);
270-
} else if (Objects.equals(level, "2")) {
271-
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.MINIMAL);
272-
} else if (Objects.equals(level, "3")) {
273-
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.NONE);
274-
} else {
275-
showLogWindow("Invalid consumer_protection_attribution_level", true, ctx, Constants.SET_ATTRIBUTION_LEVEL);
266+
try {
267+
Defines.BranchAttributionLevel attributionLevel = Defines.BranchAttributionLevel.valueOf(level.toUpperCase());
268+
Branch.getInstance().setConsumerProtectionAttributionLevel(attributionLevel);
269+
} catch (IllegalArgumentException e) {
270+
showLogWindow("Invalid cpp_level", true, ctx, Constants.SET_ATTRIBUTION_LEVEL);
276271
}
277272

278-
279273
} else {
280-
showLogWindow( "Test Data : Null" , true, ctx,Constants.SET_ATTRIBUTION_LEVEL);
274+
showLogWindow( "Test Data: Null" , true, ctx,Constants.SET_ATTRIBUTION_LEVEL);
281275
}
282276
}
283277
}

Branch-SDK/src/main/java/io/branch/referral/Defines.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public enum Jsonkey {
225225
DMA_Ad_User_Data("dma_ad_user_data"),
226226
Is_Meta_Click_Through("is_meta_ct"),
227227

228-
Consumer_Protection_Attribution_Level("consumer_protection_attribution_level");
228+
Consumer_Protection_Attribution_Level("cpp_level");
229229

230230
private final String key;
231231

Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,11 +1438,11 @@ static void loadPartnerParams(JSONObject body, BranchPartnerParameters partnerPa
14381438
* @return A {@link Defines.BranchAttributionLevel} value representing the attribution level set.
14391439
*/
14401440
public Defines.BranchAttributionLevel getConsumerProtectionAttributionLevel() {
1441-
int levelInt = getInteger(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL, -1);
1442-
if (levelInt == -1) {
1443-
return null;
1441+
String levelString = getString(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL);
1442+
if (levelString.equals(NO_STRING_VALUE)) {
1443+
return Defines.BranchAttributionLevel.FULL;
14441444
} else {
1445-
return Defines.BranchAttributionLevel.values()[levelInt];
1445+
return Defines.BranchAttributionLevel.valueOf(levelString);
14461446
}
14471447
}
14481448

@@ -1452,6 +1452,13 @@ public Defines.BranchAttributionLevel getConsumerProtectionAttributionLevel() {
14521452
* @param preference A {@link Defines.BranchAttributionLevel} value containing the desired attribution level.
14531453
*/
14541454
public void setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel preference) {
1455-
setInteger(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL, preference.ordinal());
1455+
setString(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL, preference.toString());
1456+
}
1457+
1458+
/**
1459+
* Returns true if Consumer Protection Attribution Level - KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL value exist in pref helper.
1460+
*/
1461+
boolean isAttributionLevelInitialized() {
1462+
return hasPrefValue(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL);
14561463
}
14571464
}

Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,23 @@ void addDMAParams() {
197197
}
198198
}
199199

200-
void updateConsumerProtectionAttributionLevel() {
201-
try {
202-
if (prefHelper_.getConsumerProtectionAttributionLevel() != null) {
203-
params_.put(Defines.Jsonkey.Consumer_Protection_Attribution_Level.getKey(), prefHelper_.getConsumerProtectionAttributionLevel().ordinal());
200+
private void addConsumerProtectionAttributionLevel() {
201+
if (prefHelper_.isAttributionLevelInitialized()) {
202+
try {
203+
if (getBranchRemoteAPIVersion() == BRANCH_API_VERSION.V1) {
204+
params_.put(Defines.Jsonkey.Consumer_Protection_Attribution_Level.getKey(), prefHelper_.getConsumerProtectionAttributionLevel().toString());
205+
} else {
206+
JSONObject userDataObj = params_.optJSONObject(Defines.Jsonkey.UserData.getKey());
207+
if (userDataObj != null) {
208+
userDataObj.put(Defines.Jsonkey.Consumer_Protection_Attribution_Level.getKey(), prefHelper_.getConsumerProtectionAttributionLevel().toString());
209+
}
210+
}
211+
} catch (JSONException e) {
212+
BranchLogger.d(e.getMessage());
204213
}
205-
} catch (JSONException e) {
206-
BranchLogger.d(e.getMessage());
207214
}
208215
}
209216

210-
211217
/**
212218
* <p>Provides the path to server for this request.
213219
* see {@link Defines.RequestPath} <p>
@@ -634,7 +640,7 @@ void doFinalUpdateOnMainThread() {
634640
if (shouldAddDMAParams()) {
635641
addDMAParams();
636642
}
637-
updateConsumerProtectionAttributionLevel();
643+
addConsumerProtectionAttributionLevel();
638644
}
639645

640646
void doFinalUpdateOnBackgroundThread() {

0 commit comments

Comments
 (0)