Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/appium-automation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
with:
path: qa
repository: BranchMetrics/qentelli-saas-sdk-testing-automation
ref: SDK-2465
token: ${{ secrets.BRANCHLET_ACCESS_TOKEN_PUBLIC }}
# repo's gradle is configured to run on java 17
- name: Setup java for gradle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import org.json.JSONObject;

import java.io.IOException;
import java.util.Objects;

import io.branch.branchandroiddemo.activities.LogDataActivity;
import io.branch.branchandroiddemo.activities.ShowQRCodeActivity;
import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import io.branch.referral.Defines;
import io.branch.referral.QRCode.BranchQRCode;
import io.branch.referral.util.BranchEvent;
import io.branch.referral.util.LinkProperties;
Expand Down Expand Up @@ -250,4 +252,32 @@ public void onFailure(Exception e) {
showLogWindow("Test Data : Null", true, ctx, Constants.CREATE_QR_CODE);
}
}

public void setAttributionLevel(Intent intent){
Common.getInstance().clearLog();
String testDataStr = intent.getStringExtra("testData");
Log.d("Branch SDK", "Intent extra 'testData:'\n" + testDataStr);
if (testDataStr != null) {

TestData testDataObj = new TestData();
String level = testDataObj.getParamValue(testDataStr,"consumer_protection_attribution_level");

//Set the level based on the level value
if (Objects.equals(level, "0")) {
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.FULL);
} else if (Objects.equals(level, "1")) {
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.REDUCED);
} else if (Objects.equals(level, "2")) {
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.MINIMAL);
} else if (Objects.equals(level, "3")) {
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.NONE);
} else {
showLogWindow("Invalid consumer_protection_attribution_level", true, ctx, Constants.SET_ATTRIBUTION_LEVEL);
}


} else {
showLogWindow( "Test Data : Null" , true, ctx,Constants.SET_ATTRIBUTION_LEVEL);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public interface Constants {
String CREATE_QR_CODE = "CreateQRCode";
String SET_DMA_Params = "SetDMAParams";
String INIT_SESSION = "InitSession";

String SET_ATTRIBUTION_LEVEL = "SetAttributionLevel";
String UNKNOWN = "Unknown";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private Button btCreateDeepLink, btNativeShare, btTrackUser,
btCreateQrCode, btSetDMAParams, btLogEvent, btReadLogs, btInitSession;
btCreateQrCode, btSetDMAParams, btLogEvent, btReadLogs, btInitSession, btSetAttributionLevel;
private TextView tvMessage, tvUrl;
ToggleButton trackingCntrlBtn;

Expand All @@ -43,6 +43,7 @@ protected void initialize(){
btTrackUser = findViewById(R.id.bt_track_user);
btInitSession = findViewById(R.id.bt_init_session);
trackingCntrlBtn = findViewById(R.id.tracking_cntrl_btn);
btSetAttributionLevel = findViewById(R.id.bt_set_attribution_level);

btCreateDeepLink.setOnClickListener(this);
btNativeShare.setOnClickListener(this);
Expand All @@ -52,6 +53,7 @@ protected void initialize(){
btReadLogs.setOnClickListener(this);
btTrackUser.setOnClickListener(this);
btInitSession.setOnClickListener(this);
btSetAttributionLevel.setOnClickListener(this);
}

@Override
Expand Down Expand Up @@ -89,6 +91,8 @@ public void onClick(View view) {
branchWrapper.showLogWindow("",false, this, Constants.LOG_DATA);
} else if (view == btCreateQrCode) {
branchWrapper.getQRCode(this, getIntent(), MainActivity.this);
} else if (view == btSetAttributionLevel) {
branchWrapper.setAttributionLevel(getIntent());
}else {
branchWrapper.showLogWindow("",false, this, Constants.UNKNOWN);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@
android:layout_marginBottom="@dimen/_2sdp"
android:text="Send Standard Event"
android:textAllCaps="false" />

<Button
android:id="@+id/bt_set_attribution_level"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/_15sdp"
android:layout_marginTop="@dimen/_2sdp"
android:layout_marginEnd="@dimen/_15sdp"
android:layout_marginBottom="@dimen/_2sdp"
android:text="Set Attribution Level"
android:textAllCaps="false" />

<Button
android:id="@+id/bt_Read_Logs"
android:layout_width="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import io.branch.interfaces.IBranchLoggingCallbacks;
import io.branch.referral.Branch;
import io.branch.referral.BranchLogger;
import io.branch.referral.Defines;

public final class CustomBranchApp extends Application {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Toast;
Expand Down Expand Up @@ -461,6 +460,33 @@ public void onClick(View v) {
});
});

findViewById(R.id.cmdConsumerProtectionPreference).setOnClickListener(v -> {
final String[] options = {"Full", "Reduced", "Minimal", "None"};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Select Consumer Protection Attribution Level")
.setItems(options, (dialog, which) -> {
Defines.BranchAttributionLevel preference;
switch (which) {
case 1:
preference = Defines.BranchAttributionLevel.REDUCED;
break;
case 2:
preference = Defines.BranchAttributionLevel.MINIMAL;
break;
case 3:
preference = Defines.BranchAttributionLevel.NONE;
break;
case 0:
default:
preference = Defines.BranchAttributionLevel.FULL;
break;
}
Branch.getInstance().setConsumerProtectionAttributionLevel(preference);
Toast.makeText(MainActivity.this, "Consumer Protection Preference set to " + options[which], Toast.LENGTH_SHORT).show();
});
builder.create().show();
});

findViewById(R.id.qrCode_btn).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M12,1L3,5v6c0,5.55 3.84,10.74 9,12 5.16,-1.26 9,-6.45 9,-12L21,5l-9,-4zM12,11.99h7c-0.53,4.12 -3.28,7.79 -7,8.94L12,12L5,12L5,6.3l7,-3.11v8.8z"/>

</vector>
6 changes: 6 additions & 0 deletions Branch-SDK-TestBed/src/main/res/layout/main_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@
android:textOff="Disable Tracking"
android:textOn="Enable Tracking" />

<Button
android:id="@+id/cmdConsumerProtectionPreference"
style="@style/testbed_button_style"
android:drawableStart="@drawable/ic_baseline_security_24"
android:text="Consumer Protection Preference" />

<TextView
style="@style/testbed_text_view"
android:text="Events"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.branch.referral;

import android.content.Context;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand All @@ -15,10 +14,7 @@
import org.junit.runner.RunWith;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,20 @@ public void testSetDMAParamsForEEA(){
Assert.assertEquals(prefHelper.getAdPersonalizationConsent(),true);
Assert.assertEquals(prefHelper.getAdUserDataUsageConsent(),false);
}

@Test
public void testConsumerProtectionAttributionLevel() {
Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.REDUCED);
Assert.assertEquals(Defines.BranchAttributionLevel.REDUCED, prefHelper.getConsumerProtectionAttributionLevel());

Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.MINIMAL);
Assert.assertEquals(Defines.BranchAttributionLevel.MINIMAL, prefHelper.getConsumerProtectionAttributionLevel());

Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.NONE);
Assert.assertEquals(Defines.BranchAttributionLevel.NONE, prefHelper.getConsumerProtectionAttributionLevel());

Branch.getInstance().setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel.FULL);
Assert.assertEquals(Defines.BranchAttributionLevel.FULL, prefHelper.getConsumerProtectionAttributionLevel());
}

}
28 changes: 28 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/Branch.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,21 @@ public static void setCDNBaseUrl(String url) {
* ({@code false}).
* @param callback An optional {@link TrackingStateCallback} instance for receiving callback notifications about
* the change in tracking state. This parameter can be {@code null} if no callback actions are needed.
* @deprecated Use {@link #setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel)} instead.
*/
public void disableTracking(boolean disableTracking, @Nullable TrackingStateCallback callback) {
trackingController.disableTracking(context_, disableTracking, callback);
}

/**
* Toggles the tracking state of the SDK. When tracking is disabled, the SDK will not track any user data or state,
* and it will not initiate any network calls except for deep linking operations.
* Re-enabling tracking will reinitialize the Branch session and resume normal SDK operations.
*
* @param disableTracking A boolean value indicating whether tracking should be disabled ({@code true}) or enabled
* ({@code false}).
* @deprecated Use {@link #setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel)} instead.
*/
public void disableTracking(boolean disableTracking) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you test this with the delayed init plus disable tracking by default?

disableTracking(disableTracking, null);
}
Expand Down Expand Up @@ -2576,4 +2587,21 @@ public static void setFBAppID(String fbAppID) {
BranchLogger.w("setFBAppID: fbAppID cannot be empty or null");
}
}

/**
* Sets the consumer protection attribution level
*
* @param level The consumer protection attribution level {@link Defines.BranchAttributionLevel}.
*/
public void setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel level) {
prefHelper_.setConsumerProtectionAttributionLevel(level);

if (level == Defines.BranchAttributionLevel.NONE) {
trackingController.disableTracking(context_, true, null);
} else {
trackingController.disableTracking(context_, false, null);
}

BranchLogger.v("Set Consumer Protection Preference to " + level);
}
}
51 changes: 50 additions & 1 deletion Branch-SDK/src/main/java/io/branch/referral/Defines.java
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,9 @@ public enum Jsonkey {
DMA_EEA("dma_eea"),
DMA_Ad_Personalization("dma_ad_personalization"),
DMA_Ad_User_Data("dma_ad_user_data"),
Is_Meta_Click_Through("is_meta_ct");
Is_Meta_Click_Through("is_meta_ct"),

Consumer_Protection_Attribution_Level("consumer_protection_attribution_level");

private final String key;

Expand Down Expand Up @@ -392,4 +394,51 @@ public String toString() {
return key;
}
}

/**
* <p>
* Defines Branch Attribution Level
* </p>
*/
public enum BranchAttributionLevel {
/**
* Full Attribution (Default)
* - Advertising Ids
* - Device Ids
* - Local IP
* - Persisted Non-Aggregate Ids
* - Persisted Aggregate Ids
* - Ads Postbacks / Webhooks
* - Data Integrations Webhooks
* - SAN Callouts
* - Privacy Frameworks
* - Deep Linking
*/
FULL,
/**
* Reduced Attribution (Non-Ads + Privacy Frameworks)
* - Device Ids
* - Local IP
* - Data Integrations Webhooks
* - Privacy Frameworks
* - Deep Linking
*/
REDUCED,

/**
* Minimal Attribution - Analytics Only
* - Device Ids
* - Local IP
* - Data Integrations Webhooks
* - Deep Linking
*/
MINIMAL,

/**
* No Attribution - No Analytics (GDPR, CCPA)
* - Only Deterministic Deep Linking
* - Disables all other Branch requests
*/
NONE
}
}
25 changes: 24 additions & 1 deletion Branch-SDK/src/main/java/io/branch/referral/PrefHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class PrefHelper {
private static final String KEY_DMA_AD_PERSONALIZATION = "bnc_dma_ad_personalization";
private static final String KEY_DMA_AD_USER_DATA = "bnc_dma_ad_user_data";
private static final String KEY_LOG_IAP_AS_EVENTS = "bnc_log_iap_as_events";

private static final String KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL = "bnc_consumer_protection_attribution_level";
static final String KEY_ORIGINAL_INSTALL_TIME = "bnc_original_install_time";
static final String KEY_LAST_KNOWN_UPDATE_TIME = "bnc_last_known_update_time";
static final String KEY_PREVIOUS_UPDATE_TIME = "bnc_previous_update_time";
Expand Down Expand Up @@ -1431,4 +1431,27 @@ static void loadPartnerParams(JSONObject body, BranchPartnerParameters partnerPa
}
body.put(Defines.Jsonkey.PartnerData.getKey(), partnerData);
}

/**
* <p>Gets the {@link Defines.BranchAttributionLevel} value that has been set.</p>
*
* @return A {@link Defines.BranchAttributionLevel} value representing the attribution level set.
*/
public Defines.BranchAttributionLevel getConsumerProtectionAttributionLevel() {
int levelInt = getInteger(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL, -1);
if (levelInt == -1) {
return null;
} else {
return Defines.BranchAttributionLevel.values()[levelInt];
}
}

/**
* <p>Sets the {@link Defines.BranchAttributionLevel} value via the Branch API.</p>
*
* @param preference A {@link Defines.BranchAttributionLevel} value containing the desired attribution level.
*/
public void setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel preference) {
setInteger(KEY_CONSUMER_PROTECTION_ATTRIBUTION_LEVEL, preference.ordinal());
}
}
11 changes: 11 additions & 0 deletions Branch-SDK/src/main/java/io/branch/referral/ServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ void addDMAParams() {
}
}

void updateConsumerProtectionAttributionLevel() {
try {
if (prefHelper_.getConsumerProtectionAttributionLevel() != null) {
params_.put(Defines.Jsonkey.Consumer_Protection_Attribution_Level.getKey(), prefHelper_.getConsumerProtectionAttributionLevel().ordinal());
}
} catch (JSONException e) {
BranchLogger.d(e.getMessage());
}
}


/**
* <p>Provides the path to server for this request.
Expand Down Expand Up @@ -624,6 +634,7 @@ void doFinalUpdateOnMainThread() {
if (shouldAddDMAParams()) {
addDMAParams();
}
updateConsumerProtectionAttributionLevel();
}

void doFinalUpdateOnBackgroundThread() {
Expand Down