Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 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,26 @@ 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,"cpp_level");

//Set the level based on the level value
try {
Defines.BranchAttributionLevel attributionLevel = Defines.BranchAttributionLevel.valueOf(level.toUpperCase());
Branch.getInstance().setConsumerProtectionAttributionLevel(attributionLevel);
} catch (IllegalArgumentException e) {
showLogWindow("Invalid cpp_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
2 changes: 1 addition & 1 deletion Branch-SDK-TestBed/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
</activity>

<activity android:name="io.branch.branchandroidtestbed.SettingsActivity" />

<activity android:name="io.branch.branchandroidtestbed.LogOutputActivity" />
<activity android:name="io.branch.branchandroidtestbed.AutoDeepLinkTestActivity">
<!-- Keys for auto deep linking this activity -->
<meta-data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,47 @@
import android.app.Application;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;

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
public void onCreate() {
super.onCreate();

IBranchLoggingCallbacks iBranchLoggingCallbacks = new IBranchLoggingCallbacks() {
@Override
public void onBranchLog(String logMessage, String severityConstantName) {
Log.v( "CustomTag", logMessage);
}

IBranchLoggingCallbacks loggingCallbacks = (message, tag) -> {
Log.d("BranchTestbed", message);
saveLogToFile(message);
};
Branch.enableLogging(BranchLogger.BranchLogLevel.VERBOSE); // Pass in iBranchLoggingCallbacks to enable logging redirects
Branch.enableLogging(loggingCallbacks);

Branch.getAutoInstance(this);
}

private void saveLogToFile(String logMessage) {
File logFile = new File(getFilesDir(), "branchlogs.txt");

try {
if (!logFile.exists()) {
boolean fileCreated = logFile.createNewFile();
Log.d("BranchTestbed", "Log file created: " + fileCreated);
}

try (FileOutputStream fos = new FileOutputStream(logFile, true);
OutputStreamWriter writer = new OutputStreamWriter(fos)) {
writer.write(logMessage + "\n");
}

} catch (Exception e) {
Log.e("BranchTestbed", "Error writing to log file", e);
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.branch.branchandroidtestbed;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class LogOutputActivity extends Activity {
private TextView logOutputTextView;
private File logFile;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_output);

logOutputTextView = findViewById(R.id.logOutputTextView);
logFile = new File(getFilesDir(), "branchlogs.txt");
displayLogs();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_log_output, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_clear_logs) {
clearLogs();
return true;
}
return super.onOptionsItemSelected(item);
}

private void displayLogs() {
if (logFile.exists()) {
StringBuilder logContent = new StringBuilder();

try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile)))) {
String line;
while ((line = reader.readLine()) != null) {
logContent.append(line).append("\n");
}
} catch (Exception e) {
e.printStackTrace();
logContent.append("Error reading log file.");
}

logOutputTextView.setText(logContent.toString());
} else {
logOutputTextView.setText("Log file not found.");
}
}

private void clearLogs() {
if (logFile.exists()) {
if (logFile.delete()) {
Toast.makeText(this, "Logs cleared.", Toast.LENGTH_SHORT).show();
logOutputTextView.setText("Logs cleared.");
finish();
} else {
Toast.makeText(this, "Failed to clear logs.", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(this, "No log file to clear.", Toast.LENGTH_SHORT).show();
}
}
}
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 @@ -415,6 +414,13 @@ public void onChannelSelected(String channelName) {
}
});

findViewById(R.id.viewLogsButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, LogOutputActivity.class);
startActivity(intent);
}
});

findViewById(R.id.notif_btn).setOnClickListener(new OnClickListener() {
@Override
Expand Down Expand Up @@ -461,6 +467,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 Expand Up @@ -565,8 +598,18 @@ public void onClick(View v) {
.setSearchQuery("product name")
.addCustomDataProperty("Custom_Event_Property_Key1", "Custom_Event_Property_val1")
.addContentItems(branchUniversalObject)
.logEvent(MainActivity.this);
Toast.makeText(getApplicationContext(), "Sent Branch Content Event", Toast.LENGTH_SHORT).show();
.logEvent(MainActivity.this, new BranchEvent.BranchLogEventCallback() {
@Override
public void onSuccess(int responseCode) {
Toast.makeText(getApplicationContext(), "Sent Branch Content Event: " + responseCode, Toast.LENGTH_SHORT).show();
}

@Override
public void onFailure(Exception e) {
Log.d("BranchSDK_Tester", e.toString());
Toast.makeText(getApplicationContext(), "Error sending Branch Content Event: " + e.toString(), Toast.LENGTH_SHORT).show();
}
});
}
});

Expand All @@ -580,8 +623,18 @@ public void onClick(View v) {
.setDescription("User created an account")
.addCustomDataProperty("registrationID", "12345")
.addContentItems(branchUniversalObject)
.logEvent(MainActivity.this);
Toast.makeText(getApplicationContext(), "Sent Branch Lifecycle Event", Toast.LENGTH_SHORT).show();
.logEvent(MainActivity.this, new BranchEvent.BranchLogEventCallback() {
@Override
public void onSuccess(int responseCode) {
Toast.makeText(getApplicationContext(), "Sent Branch Lifecycle Event: " + responseCode, Toast.LENGTH_SHORT).show();
}

@Override
public void onFailure(Exception e) {
Log.d("BranchSDK_Tester", e.toString());
Toast.makeText(getApplicationContext(), "Error sending Branch Lifecycle Event: " + e.toString(), Toast.LENGTH_SHORT).show();
}
});
}
});

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="M7,3H4v3H2V1h5V3zM22,6V1h-5v2h3v3H22zM7,21H4v-3H2v5h5V21zM20,18v3h-3v2h5v-5H20zM19,18c0,1.1 -0.9,2 -2,2H7c-1.1,0 -2,-0.9 -2,-2V6c0,-1.1 0.9,-2 2,-2h10c1.1,0 2,0.9 2,2V18zM15,8H9v2h6V8zM15,11H9v2h6V11zM15,14H9v2h6V14z"/>

</vector>
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>
18 changes: 18 additions & 0 deletions Branch-SDK-TestBed/src/main/res/layout/activity_log_output.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<TextView
android:id="@+id/logOutputTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="14sp"
android:text="Logs will appear here" />
</ScrollView>
</RelativeLayout>
Loading
Loading