Skip to content

Commit

Permalink
Got native Android integration validator logs printing to the JS cons…
Browse files Browse the repository at this point in the history
…ole for easier access for the user

Got native Android integration validator logs printing to the JS console for easier access for the user
  • Loading branch information
rob-gioia-branch committed Oct 7, 2024
1 parent 5ce0da7 commit 3dc377e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions android/src/main/java/io/branch/rnbranch/RNBranchModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import javax.annotation.Nonnull;

Expand Down Expand Up @@ -1258,4 +1260,23 @@ public void validateSDKIntegration() {
Log.d(REACT_CLASS,"Integration Validator Code Called");
IntegrationValidator.validate(mActivity);
}

@ReactMethod
public void readLogs(Promise promise) {
try {
Process process = Runtime.getRuntime().exec("logcat -d BranchSDK_Doctor:V *:S");
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));

StringBuilder log = new StringBuilder();
String line = "";
while ((line = bufferedReader.readLine()) != null) {
log.append(line + "\n");
}
String logs = new String(log);
promise.resolve(logs);
} catch (Exception e) {
promise.reject("Error reading logs", e);
}
}
}
4 changes: 4 additions & 0 deletions branchreactnativetestbed/components/BranchWrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export default class BranchWrapper {

validateSDKIntegration = async () => {
branch.validateSDKIntegration();

await branch.readLogs().then( val => {
console.log(val);
});
};

viewFirstReferringParams = async () => {
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ interface Branch {
setPreInstallPartner: (partner: string) => void;
setDMAParamsForEEA: (eeaRegion: boolean, adPersonalizationConsent: boolean, adUserDataUsageConsent: boolean) => void;
validateSDKIntegration: () => void;
readLogs: () => Promise<string>;
}
declare const branch: Branch;
export default branch;
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,13 @@ class Branch {

validateSDKIntegration = () => {
RNBranch.validateSDKIntegration();
this.readLogs();
};

readLogs = () => {
return RNBranch.readLogs();
}

/*** PreInstall Parameters ***/
setPreInstallCampaign = (campaign) =>
RNBranch.setPreinstallCampaign(campaign);
Expand Down

0 comments on commit 3dc377e

Please sign in to comment.