Skip to content

Commit

Permalink
chore: test redaction/unredaction through java on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
jribeiro committed Oct 31, 2022
1 parent ad3fed9 commit a8ac852
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.view.View;
import android.view.inspector.WindowInspector;

import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
Expand Down Expand Up @@ -92,14 +94,47 @@ private static void initializeFlipper(
@Nullable
@Override
public List<View> redactedViews(@NonNull Activity activity) {
return new ArrayList<View>() {{
ArrayList<View> redacted = new ArrayList<View>() {{
add(activity.getWindow().getDecorView());
}};

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
List<View> globalWindowViews = WindowInspector.getGlobalWindowViews();

for(int i=0; i < globalWindowViews.size(); i++){
ArrayList<View> changeLocationViews = new ArrayList<>();
globalWindowViews.get(i).findViewsWithText(changeLocationViews, "Change Bundle Location", View.FIND_VIEWS_WITH_TEXT);
if (changeLocationViews.size() > 0) {
for (int j = 0; j < changeLocationViews.size(); j++) {
redacted.add((View) changeLocationViews.get(j).getParent());
}
}
}
}

return redacted;
}

@Nullable
@Override
public List<View> unredactedViews(@NonNull Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
List<View> globalWindowViews = WindowInspector.getGlobalWindowViews();
ArrayList<View> unredacted = new ArrayList<>();

for(int i=0; i < globalWindowViews.size(); i++){
ArrayList<View> configureBundlerViews = new ArrayList<>();
globalWindowViews.get(i).findViewsWithText(configureBundlerViews, "Configure Bundler", View.FIND_VIEWS_WITH_TEXT);
if (configureBundlerViews.size() > 0) {
for (int j = 0; j < configureBundlerViews.size(); j++) {
unredacted.add((View) configureBundlerViews.get(j));
}
}
}

return unredacted;
}

return null;
}
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Try our **online demo** at the bottom of our homepage at <https://cobrowse.io/#t

```bash
npm install --save cobrowse-sdk-react-native
react-native link
(cd ios && pod install)
```
**Note:** For iOS you need to be using Pods to manage dependencies for `react-native link` to work out of the box (and also remember to run `pod install` after the link step).
**Note:** For older versions of React Native, you may need to run `react-native link` before running `pod install`.

### Add your License Key

Expand Down

0 comments on commit a8ac852

Please sign in to comment.