Skip to content

Commit 8450fad

Browse files
committed
Testbed update for Mobileboost tests
1 parent 813cbac commit 8450fad

File tree

10 files changed

+155
-10
lines changed

10 files changed

+155
-10
lines changed

Branch-SDK-TestBed/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
</activity>
115115

116116
<activity android:name="io.branch.branchandroidtestbed.SettingsActivity" />
117-
117+
<activity android:name="io.branch.branchandroidtestbed.LogOutputActivity" />
118118
<activity android:name="io.branch.branchandroidtestbed.AutoDeepLinkTestActivity">
119119
<!-- Keys for auto deep linking this activity -->
120120
<meta-data

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/CustomBranchApp.java

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import android.app.Application;
44
import android.util.Log;
55

6+
import java.io.File;
7+
import java.io.FileOutputStream;
8+
import java.io.OutputStreamWriter;
9+
610
import io.branch.interfaces.IBranchLoggingCallbacks;
711
import io.branch.referral.Branch;
812
import io.branch.referral.BranchLogger;
@@ -12,14 +16,37 @@ public final class CustomBranchApp extends Application {
1216
@Override
1317
public void onCreate() {
1418
super.onCreate();
15-
16-
IBranchLoggingCallbacks iBranchLoggingCallbacks = new IBranchLoggingCallbacks() {
19+
20+
IBranchLoggingCallbacks loggingCallbacks = new IBranchLoggingCallbacks() {
1721
@Override
18-
public void onBranchLog(String logMessage, String severityConstantName) {
19-
Log.v( "CustomTag", logMessage);
22+
public void onBranchLog(String tag, String message) {
23+
String logMessage = tag + ": " + message;
24+
Log.d("BranchTestbed", logMessage);
25+
saveLogToFile(logMessage);
2026
}
2127
};
22-
Branch.enableLogging(BranchLogger.BranchLogLevel.VERBOSE); // Pass in iBranchLoggingCallbacks to enable logging redirects
28+
Branch.enableLogging(loggingCallbacks);
2329
Branch.getAutoInstance(this);
2430
}
31+
32+
private void saveLogToFile(String logMessage) {
33+
File logFile = new File(getFilesDir(), "branchlogs.txt");
34+
35+
try {
36+
if (!logFile.exists()) {
37+
boolean fileCreated = logFile.createNewFile();
38+
Log.d("BranchTestbed", "Log file created: " + fileCreated);
39+
}
40+
41+
try (FileOutputStream fos = new FileOutputStream(logFile, true);
42+
OutputStreamWriter writer = new OutputStreamWriter(fos)) {
43+
writer.write(logMessage + "\n");
44+
}
45+
46+
} catch (Exception e) {
47+
Log.e("BranchTestbed", "Error writing to log file", e);
48+
}
49+
}
50+
51+
2552
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package io.branch.branchandroidtestbed;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.Menu;
6+
import android.view.MenuItem;
7+
import android.widget.TextView;
8+
import android.widget.Toast;
9+
10+
import java.io.BufferedReader;
11+
import java.io.File;
12+
import java.io.FileInputStream;
13+
import java.io.InputStreamReader;
14+
15+
public class LogOutputActivity extends Activity {
16+
private TextView logOutputTextView;
17+
private File logFile;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_log_output);
23+
24+
logOutputTextView = findViewById(R.id.logOutputTextView);
25+
logFile = new File(getFilesDir(), "branchlogs.txt");
26+
displayLogs();
27+
}
28+
29+
@Override
30+
public boolean onCreateOptionsMenu(Menu menu) {
31+
getMenuInflater().inflate(R.menu.menu_log_output, menu);
32+
return true;
33+
}
34+
35+
@Override
36+
public boolean onOptionsItemSelected(MenuItem item) {
37+
if (item.getItemId() == R.id.action_clear_logs) {
38+
clearLogs();
39+
return true;
40+
}
41+
return super.onOptionsItemSelected(item);
42+
}
43+
44+
private void displayLogs() {
45+
if (logFile.exists()) {
46+
StringBuilder logContent = new StringBuilder();
47+
48+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(logFile)))) {
49+
String line;
50+
while ((line = reader.readLine()) != null) {
51+
logContent.append(line).append("\n");
52+
}
53+
} catch (Exception e) {
54+
e.printStackTrace();
55+
logContent.append("Error reading log file.");
56+
}
57+
58+
logOutputTextView.setText(logContent.toString());
59+
} else {
60+
logOutputTextView.setText("Log file not found.");
61+
}
62+
}
63+
64+
private void clearLogs() {
65+
if (logFile.exists()) {
66+
if (logFile.delete()) {
67+
Toast.makeText(this, "Logs cleared.", Toast.LENGTH_SHORT).show();
68+
logOutputTextView.setText("Logs cleared.");
69+
finish();
70+
} else {
71+
Toast.makeText(this, "Failed to clear logs.", Toast.LENGTH_SHORT).show();
72+
}
73+
} else {
74+
Toast.makeText(this, "No log file to clear.", Toast.LENGTH_SHORT).show();
75+
}
76+
}
77+
}

Branch-SDK-TestBed/src/main/java/io/branch/branchandroidtestbed/MainActivity.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,13 @@ public void onChannelSelected(String channelName) {
414414
}
415415
});
416416

417+
findViewById(R.id.viewLogsButton).setOnClickListener(new View.OnClickListener() {
418+
@Override
419+
public void onClick(View v) {
420+
Intent intent = new Intent(MainActivity.this, LogOutputActivity.class);
421+
startActivity(intent);
422+
}
423+
});
417424

418425
findViewById(R.id.notif_btn).setOnClickListener(new OnClickListener() {
419426
@Override
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<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">
2+
3+
<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"/>
4+
5+
</vector>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent">
5+
6+
<TextView
7+
android:id="@+id/logOutputTextView"
8+
android:layout_width="match_parent"
9+
android:layout_height="match_parent"
10+
android:padding="16dp"
11+
android:textSize="14sp"
12+
android:text="Logs will appear here" />
13+
</RelativeLayout>

Branch-SDK-TestBed/src/main/res/layout/main_activity.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@
133133
android:text="Misc."
134134
/>
135135

136+
<Button
137+
android:id="@+id/viewLogsButton"
138+
style="@style/testbed_button_style"
139+
android:drawableStart="@drawable/baseline_document_scanner_24"
140+
android:text="Load Branch Logs" />
141+
142+
136143
<Button
137144
android:id="@+id/notif_btn"
138145
style="@style/testbed_button_style"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android">
3+
<item
4+
android:id="@+id/action_clear_logs"
5+
android:title="Clear Logs"
6+
android:showAsAction="always" />
7+
</menu>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2596,13 +2596,15 @@ public static void setFBAppID(String fbAppID) {
25962596
*/
25972597
public void setConsumerProtectionAttributionLevel(Defines.BranchAttributionLevel level) {
25982598
prefHelper_.setConsumerProtectionAttributionLevel(level);
2599+
BranchLogger.v("Set Consumer Protection Preference to " + level);
25992600

26002601
if (level == Defines.BranchAttributionLevel.NONE) {
26012602
trackingController.disableTracking(context_, true, null);
26022603
} else {
2603-
trackingController.disableTracking(context_, false, null);
2604+
if (initState_ != SESSION_STATE.INITIALISED) {
2605+
trackingController.disableTracking(context_, false, null);
2606+
}
26042607
}
26052608

2606-
BranchLogger.v("Set Consumer Protection Preference to " + level);
26072609
}
26082610
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#Sun Apr 07 13:06:19 PDT 2024
1+
#Wed Nov 06 12:51:09 PST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
55
networkTimeout=10000
66
zipStoreBase=GRADLE_USER_HOME
77
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)