From 353d8d3980e04c32c233f5eebbe4ef3bc9bce460 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 3 Oct 2023 19:57:38 -0700 Subject: [PATCH] deduplicate code in cleanDataFromModules (#39767) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39767 deduplicate code in cleanDataFromModules changelog: [internal] internal bypass-github-export-checks Reviewed By: cortinico Differential Revision: D49834866 fbshipit-source-id: 6b54a0cfcd58e9c963125d07b736e1377a548393 --- .../react/modules/common/ModuleDataCleaner.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/common/ModuleDataCleaner.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/common/ModuleDataCleaner.java index ed1b526ad1710d..fda3e7cbb511f7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/common/ModuleDataCleaner.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/common/ModuleDataCleaner.java @@ -12,6 +12,7 @@ import com.facebook.react.bridge.NativeModule; import com.facebook.react.bridge.ReactContext; import com.facebook.react.common.ReactConstants; +import java.util.Collection; /** * Cleans sensitive user data from native modules that implement the {@code Cleanable} interface. @@ -45,16 +46,15 @@ public interface Cleanable { */ @Deprecated public static void cleanDataFromModules(CatalystInstance catalystInstance) { - for (NativeModule nativeModule : catalystInstance.getNativeModules()) { - if (nativeModule instanceof Cleanable) { - FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName()); - ((Cleanable) nativeModule).clearSensitiveData(); - } - } + cleanDataFromModules(catalystInstance.getNativeModules()); } public static void cleanDataFromModules(ReactContext reactContext) { - for (NativeModule nativeModule : reactContext.getNativeModules()) { + cleanDataFromModules(reactContext.getNativeModules()); + } + + private static void cleanDataFromModules(Collection nativeModules) { + for (NativeModule nativeModule : nativeModules) { if (nativeModule instanceof Cleanable) { FLog.d(ReactConstants.TAG, "Cleaning data from " + nativeModule.getName()); ((Cleanable) nativeModule).clearSensitiveData();