From a8ac852b05bc99c29a90da0aee2c277b1efeb730 Mon Sep 17 00:00:00 2001 From: Joao Ribeiro <922529+jribeiro@users.noreply.github.com> Date: Mon, 31 Oct 2022 01:24:26 +0100 Subject: [PATCH] chore: test redaction/unredaction through java on Android --- .../java/com/example/MainApplication.java | 37 ++++++++++++++++++- README.md | 4 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Example/android/app/src/main/java/com/example/MainApplication.java b/Example/android/app/src/main/java/com/example/MainApplication.java index af633d1..c633feb 100644 --- a/Example/android/app/src/main/java/com/example/MainApplication.java +++ b/Example/android/app/src/main/java/com/example/MainApplication.java @@ -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; @@ -92,14 +94,47 @@ private static void initializeFlipper( @Nullable @Override public List redactedViews(@NonNull Activity activity) { - return new ArrayList() {{ + ArrayList redacted = new ArrayList() {{ add(activity.getWindow().getDecorView()); }}; + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + List globalWindowViews = WindowInspector.getGlobalWindowViews(); + + for(int i=0; i < globalWindowViews.size(); i++){ + ArrayList 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 unredactedViews(@NonNull Activity activity) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + List globalWindowViews = WindowInspector.getGlobalWindowViews(); + ArrayList unredacted = new ArrayList<>(); + + for(int i=0; i < globalWindowViews.size(); i++){ + ArrayList 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; } } diff --git a/README.md b/README.md index d4eacd6..e1b3234 100755 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ Try our **online demo** at the bottom of our homepage at