EZ refactor to remove lint warns and move to java 8 apis (#37170)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/37170

EZ refactor to remove lint warns

changelog: [internal] internal

Reviewed By: philIip

Differential Revision: D45378239

fbshipit-source-id: 3a9c80976e10dce8491d5cff3abaa394bad18f97
This commit is contained in:
David Vacca
2023-05-02 12:31:11 -07:00
committed by Facebook GitHub Bot
parent 3f7c2b2215
commit 99f88ce33b
6 changed files with 56 additions and 155 deletions
@@ -76,14 +76,11 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase {
final SimpleSettableFuture<Void> semaphore = new SimpleSettableFuture<>();
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
if (contextToDestroy != null) {
contextToDestroy.destroy();
}
semaphore.set(null);
() -> {
if (contextToDestroy != null) {
contextToDestroy.destroy();
}
semaphore.set(null);
});
semaphore.getOrThrow();
}
@@ -137,14 +134,10 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase {
final SimpleSettableFuture<TimingModule> simpleSettableFuture =
new SimpleSettableFuture<TimingModule>();
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
ReactChoreographer.initialize();
TimingModule timingModule =
new TimingModule(getContext(), mock(DevSupportManager.class));
simpleSettableFuture.set(timingModule);
}
() -> {
ReactChoreographer.initialize();
TimingModule timingModule = new TimingModule(getContext(), mock(DevSupportManager.class));
simpleSettableFuture.set(timingModule);
});
try {
return simpleSettableFuture.get(5000, TimeUnit.MILLISECONDS);
@@ -188,15 +181,12 @@ public abstract class ReactIntegrationTestCase extends AndroidTestCase {
protected static void initializeJavaModule(final BaseJavaModule javaModule) {
final Semaphore semaphore = new Semaphore(0);
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
javaModule.initialize();
if (javaModule instanceof LifecycleEventListener) {
((LifecycleEventListener) javaModule).onHostResume();
}
semaphore.release();
() -> {
javaModule.initialize();
if (javaModule instanceof LifecycleEventListener) {
((LifecycleEventListener) javaModule).onHostResume();
}
semaphore.release();
});
try {
SoftAssertions.assertCondition(
@@ -26,14 +26,14 @@ public final class FallbackJSBundleLoader extends JSBundleLoader {
/* package */ static final String TAG = "FallbackJSBundleLoader";
// Loaders to delegate to, with the preferred one at the top.
private Stack<JSBundleLoader> mLoaders;
private final Stack<JSBundleLoader> mLoaders;
// Reasons why we fell-back on previous loaders, in order of occurrence.
private final ArrayList<Exception> mRecoveredErrors = new ArrayList<>();
/** @param loaders Loaders for the sources to try, in descending order of preference. */
public FallbackJSBundleLoader(List<JSBundleLoader> loaders) {
mLoaders = new Stack();
mLoaders = new Stack<>();
ListIterator<JSBundleLoader> it = loaders.listIterator(loaders.size());
while (it.hasPrevious()) {
mLoaders.push(it.previous());
@@ -9,11 +9,9 @@ package com.facebook.react.bridge;
import android.content.Context;
import com.facebook.react.common.DebugServerException;
import java.util.Objects;
/**
* A class that stores JS bundle information and allows a {@link JSBundleLoaderDelegate} (e.g.
* {@link CatalystInstance}) to load a correct bundle through {@link ReactBridge}.
*/
/** A class that stores JS bundle information and allows a {@link JSBundleLoaderDelegate}. */
public abstract class JSBundleLoader {
/**
@@ -67,7 +65,8 @@ public abstract class JSBundleLoader {
delegate.loadScriptFromFile(cachedFileLocation, sourceURL, false);
return sourceURL;
} catch (Exception e) {
throw DebugServerException.makeGeneric(sourceURL, e.getMessage(), e);
throw DebugServerException.makeGeneric(
sourceURL, Objects.toString(e.getMessage(), ""), e);
}
}
};
@@ -86,7 +85,8 @@ public abstract class JSBundleLoader {
delegate.loadSplitBundleFromFile(cachedFileLocation, sourceURL);
return sourceURL;
} catch (Exception e) {
throw DebugServerException.makeGeneric(sourceURL, e.getMessage(), e);
throw DebugServerException.makeGeneric(
sourceURL, Objects.toString(e.getMessage(), ""), e);
}
}
};
@@ -13,5 +13,5 @@ import com.facebook.react.common.mapbuffer.ReadableMapBuffer;
@DoNotStripAny
public interface ReactJsExceptionHandler {
public void reportJsException(ReadableMapBuffer errorMap);
void reportJsException(ReadableMapBuffer errorMap);
}
@@ -9,6 +9,7 @@ package com.facebook.react.common;
import android.net.Uri;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import org.json.JSONException;
@@ -27,12 +28,13 @@ public class DebugServerException extends RuntimeException {
+ "\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:<PORT> tcp:<PORT>' to forward requests from your device\n"
+ "\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:<PORT>\n\n";
public static DebugServerException makeGeneric(String url, String reason, Throwable t) {
public static DebugServerException makeGeneric(
@NonNull String url, @NonNull String reason, Throwable t) {
return makeGeneric(url, reason, "", t);
}
public static DebugServerException makeGeneric(
String url, String reason, String extra, Throwable t) {
@NonNull String url, @NonNull String reason, @NonNull String extra, Throwable t) {
Uri uri = Uri.parse(url);
String message = GENERIC_ERROR_MESSAGE.replace("<PORT>", String.valueOf(uri.getPort()));
@@ -83,9 +83,6 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
private static final String EXOPACKAGE_LOCATION_FORMAT =
"/data/local/tmp/exopackage/%s//secondary-dex";
public static final String EMOJI_HUNDRED_POINTS_SYMBOL = " \uD83D\uDCAF";
public static final String EMOJI_FACE_WITH_NO_GOOD_GESTURE = " \uD83D\uDE45";
private final Context mApplicationContext;
private final ShakeDetector mShakeDetector;
private final BroadcastReceiver mReloadAppBroadcastReceiver;
@@ -104,24 +101,23 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
private boolean mDevLoadingViewVisible = false;
private int mPendingJSSplitBundleRequests = 0;
private @Nullable ReactContext mCurrentContext;
private DevInternalSettings mDevSettings;
private final DevInternalSettings mDevSettings;
private boolean mIsReceiverRegistered = false;
private boolean mIsShakeDetectorStarted = false;
private boolean mIsDevSupportEnabled = false;
private @Nullable RedBoxHandler mRedBoxHandler;
private @Nullable final RedBoxHandler mRedBoxHandler;
private @Nullable String mLastErrorTitle;
private @Nullable StackFrame[] mLastErrorStack;
private @Nullable ErrorType mLastErrorType;
private int mLastErrorCookie = 0;
private @Nullable DevBundleDownloadListener mBundleDownloadListener;
private @Nullable final DevBundleDownloadListener mBundleDownloadListener;
private @Nullable List<ErrorCustomizer> mErrorCustomizers;
private @Nullable PackagerLocationCustomizer mPackagerLocationCustomizer;
private InspectorPackagerConnection.BundleStatus mBundleStatus;
private final InspectorPackagerConnection.BundleStatus mBundleStatus;
private @Nullable Map<String, RequestHandler> mCustomPackagerCommandHandlers;
private @Nullable final Map<String, RequestHandler> mCustomPackagerCommandHandlers;
private @Nullable Activity currentActivity;
private @Nullable final SurfaceDelegateFactory mSurfaceDelegateFactory;
public DevSupportManagerBase(
@@ -138,38 +134,15 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
mReactInstanceDevHelper = reactInstanceDevHelper;
mApplicationContext = applicationContext;
mJSAppBundleName = packagerPathForJSBundleName;
mDevSettings =
new DevInternalSettings(
applicationContext,
new DevInternalSettings.Listener() {
@Override
public void onInternalSettingsChanged() {
reloadSettings();
}
});
mDevSettings = new DevInternalSettings(applicationContext, this::reloadSettings);
mBundleStatus = new InspectorPackagerConnection.BundleStatus();
mDevServerHelper =
new DevServerHelper(
mDevSettings,
mApplicationContext.getPackageName(),
new InspectorPackagerConnection.BundleStatusProvider() {
@Override
public InspectorPackagerConnection.BundleStatus getBundleStatus() {
return mBundleStatus;
}
});
mDevSettings, mApplicationContext.getPackageName(), () -> mBundleStatus);
mBundleDownloadListener = devBundleDownloadListener;
// Prepare shake gesture detector (will be started/stopped from #reload)
mShakeDetector =
new ShakeDetector(
new ShakeDetector.ShakeListener() {
@Override
public void onShake() {
showDevOptionsDialog();
}
},
minNumShakes);
mShakeDetector = new ShakeDetector(this::showDevOptionsDialog, minNumShakes);
mCustomPackagerCommandHandlers = customPackagerCommandHandlers;
@@ -566,20 +539,11 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
.setCustomTitle(textView)
.setItems(
options.keySet().toArray(new String[0]),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
optionHandlers[which].onOptionSelected();
mDevOptionsDialog = null;
}
})
.setOnCancelListener(
new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
mDevOptionsDialog = null;
}
(dialog, which) -> {
optionHandlers[which].onOptionSelected();
mDevOptionsDialog = null;
})
.setOnCancelListener(dialog -> mDevOptionsDialog = null)
.create();
mDevOptionsDialog.show();
if (mCurrentContext != null) {
@@ -609,7 +573,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
}
@Override
public RedBoxHandler getRedBoxHandler() {
public @Nullable RedBoxHandler getRedBoxHandler() {
return mRedBoxHandler;
}
@@ -837,13 +801,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
@Override
public void onFailure(Exception cause) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
hideSplitBundleDevLoadingView();
}
});
UiThreadUtil.runOnUiThread(() -> hideSplitBundleDevLoadingView());
callback.onError(bundleUrl, cause);
}
},
@@ -869,13 +827,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
@Override
public void isPackagerRunning(final PackagerStatusCallback callback) {
Runnable checkPackagerRunning =
new Runnable() {
@Override
public void run() {
mDevServerHelper.isPackagerRunning(callback);
}
};
Runnable checkPackagerRunning = () -> mDevServerHelper.isPackagerRunning(callback);
if (mPackagerLocationCustomizer != null) {
mPackagerLocationCustomizer.run(checkPackagerRunning);
} else {
@@ -946,18 +898,8 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
public void reloadJSFromServer(final String bundleURL) {
reloadJSFromServer(
bundleURL,
new BundleLoadCallback() {
@Override
public void onSuccess() {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mReactInstanceDevHelper.onJSBundleLoadedFromServer();
}
});
}
});
() ->
UiThreadUtil.runOnUiThread(() -> mReactInstanceDevHelper.onJSBundleLoadedFromServer()));
}
public void reloadJSFromServer(final String bundleURL, final BundleLoadCallback callback) {
@@ -1047,12 +989,9 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
}
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mDevSettings.setHotModuleReplacementEnabled(isHotModuleReplacementEnabled);
handleReloadJS();
}
() -> {
mDevSettings.setHotModuleReplacementEnabled(isHotModuleReplacementEnabled);
handleReloadJS();
});
}
@@ -1063,12 +1002,9 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
}
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled);
handleReloadJS();
}
() -> {
mDevSettings.setRemoteJSDebugEnabled(isRemoteJSDebugEnabled);
handleReloadJS();
});
}
@@ -1078,13 +1014,7 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
return;
}
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mDevSettings.setFpsDebugEnabled(isFpsDebugEnabled);
}
});
UiThreadUtil.runOnUiThread(() -> mDevSettings.setFpsDebugEnabled(isFpsDebugEnabled));
}
@Override
@@ -1094,12 +1024,9 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
}
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
mDevSettings.setElementInspectorEnabled(!mDevSettings.isElementInspectorEnabled());
mReactInstanceDevHelper.toggleElementInspector();
}
() -> {
mDevSettings.setElementInspectorEnabled(!mDevSettings.isElementInspectorEnabled());
mReactInstanceDevHelper.toggleElementInspector();
});
}
@@ -1150,35 +1077,17 @@ public abstract class DevSupportManagerBase implements DevSupportManager {
public void onPackagerReloadCommand() {
// Disable debugger to resume the JsVM & avoid thread locks while reloading
mDevServerHelper.disableDebugger();
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
handleReloadJS();
}
});
UiThreadUtil.runOnUiThread(() -> handleReloadJS());
}
@Override
public void onPackagerDevMenuCommand() {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
showDevOptionsDialog();
}
});
UiThreadUtil.runOnUiThread(() -> showDevOptionsDialog());
}
@Override
public void onCaptureHeapCommand(final Responder responder) {
UiThreadUtil.runOnUiThread(
new Runnable() {
@Override
public void run() {
handleCaptureHeap(responder);
}
});
UiThreadUtil.runOnUiThread(() -> handleCaptureHeap(responder));
}
@Override