Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

import android.os.SystemClock;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.ReactIgnorableMountingException;
import com.facebook.react.bridge.ReactNoCrashSoftException;
Expand All @@ -30,6 +31,7 @@
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

@Nullsafe(Nullsafe.Mode.LOCAL)
public class MountItemDispatcher {

private static final String TAG = "MountItemDispatcher";
Expand All @@ -39,14 +41,11 @@ public class MountItemDispatcher {
private final MountingManager mMountingManager;
private final ItemDispatchListener mItemDispatchListener;

@NonNull
private final ConcurrentLinkedQueue<DispatchCommandMountItem> mViewCommandMountItems =
new ConcurrentLinkedQueue<>();

@NonNull
private final ConcurrentLinkedQueue<MountItem> mMountItems = new ConcurrentLinkedQueue<>();

@NonNull
private final ConcurrentLinkedQueue<MountItem> mPreMountItems = new ConcurrentLinkedQueue<>();

private boolean mInDispatch = false;
Expand Down Expand Up @@ -122,6 +121,7 @@ public void tryDispatchMountItems() {
public void dispatchMountItems(Queue<MountItem> mountItems) {
while (!mountItems.isEmpty()) {
MountItem item = mountItems.poll();
Assertions.assertNotNull(item);
try {
item.execute(mMountingManager);
} catch (RetryableMountingLayerException e) {
Expand Down Expand Up @@ -343,7 +343,8 @@ private void executeOrEnqueue(MountItem item) {
item.getSurfaceId());
}
SurfaceMountingManager surfaceMountingManager =
mMountingManager.getSurfaceManager(item.getSurfaceId());
mMountingManager.getSurfaceManagerEnforced(
item.getSurfaceId(), "MountItemDispatcher::executeOrEnqueue");
surfaceMountingManager.scheduleMountItemOnViewAttach(item);
} else {
item.execute(mMountingManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@

import android.view.View;
import androidx.annotation.AnyThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.infer.annotation.ThreadConfined;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactSoftExceptionLogger;
Expand Down Expand Up @@ -45,11 +46,11 @@
* Class responsible for actually dispatching view updates enqueued via {@link
* FabricUIManager#scheduleMountItem} on the UI thread.
*/
@Nullsafe(Nullsafe.Mode.LOCAL)
public class MountingManager {
public static final String TAG = MountingManager.class.getSimpleName();
private static final int MAX_STOPPED_SURFACE_IDS_LENGTH = 15;

@NonNull
private final ConcurrentHashMap<Integer, SurfaceMountingManager> mSurfaceIdToManager =
new ConcurrentHashMap<>(); // any thread

Expand All @@ -58,10 +59,10 @@ public class MountingManager {
@Nullable private SurfaceMountingManager mMostRecentSurfaceMountingManager;
@Nullable private SurfaceMountingManager mLastQueriedSurfaceMountingManager;

@NonNull private final JSResponderHandler mJSResponderHandler = new JSResponderHandler();
@NonNull private final ViewManagerRegistry mViewManagerRegistry;
@NonNull private final MountItemExecutor mMountItemExecutor;
@NonNull private final RootViewManager mRootViewManager = new RootViewManager();
private final JSResponderHandler mJSResponderHandler = new JSResponderHandler();
private final ViewManagerRegistry mViewManagerRegistry;
private final MountItemExecutor mMountItemExecutor;
private final RootViewManager mRootViewManager = new RootViewManager();

public interface MountItemExecutor {
@UiThread
Expand All @@ -70,8 +71,7 @@ public interface MountItemExecutor {
}

public MountingManager(
@NonNull ViewManagerRegistry viewManagerRegistry,
@NonNull MountItemExecutor mountItemExecutor) {
ViewManagerRegistry viewManagerRegistry, MountItemExecutor mountItemExecutor) {
mViewManagerRegistry = viewManagerRegistry;
mMountItemExecutor = mountItemExecutor;
}
Expand Down Expand Up @@ -116,7 +116,7 @@ public SurfaceMountingManager startSurface(

@AnyThread
public void attachRootView(
final int surfaceId, @NonNull final View rootView, ThemedReactContext themedReactContext) {
final int surfaceId, final View rootView, ThemedReactContext themedReactContext) {
SurfaceMountingManager surfaceMountingManager =
getSurfaceManagerEnforced(surfaceId, "attachView");

Expand All @@ -136,6 +136,7 @@ public void stopSurface(final int surfaceId) {
// Maximum number of stopped surfaces to keep track of
while (mStoppedSurfaceIds.size() >= MAX_STOPPED_SURFACE_IDS_LENGTH) {
Integer staleStoppedId = mStoppedSurfaceIds.get(0);
Assertions.assertNotNull(staleStoppedId);
mSurfaceIdToManager.remove(staleStoppedId.intValue());
mStoppedSurfaceIds.remove(staleStoppedId);
FLog.d(TAG, "Removing stale SurfaceMountingManager: [%d]", staleStoppedId.intValue());
Expand Down Expand Up @@ -175,7 +176,6 @@ public SurfaceMountingManager getSurfaceManager(int surfaceId) {
return surfaceMountingManager;
}

@NonNull
public SurfaceMountingManager getSurfaceManagerEnforced(int surfaceId, String context) {
SurfaceMountingManager surfaceMountingManager = getSurfaceManager(surfaceId);

Expand Down Expand Up @@ -250,7 +250,6 @@ public SurfaceMountingManager getSurfaceManagerForView(int reactTag) {
return null;
}

@NonNull
@AnyThread
public SurfaceMountingManager getSurfaceManagerForViewEnforced(int reactTag) {
SurfaceMountingManager surfaceMountingManager = getSurfaceManagerForView(reactTag);
Expand All @@ -276,7 +275,7 @@ public void receiveCommand(
}

public void receiveCommand(
int surfaceId, int reactTag, @NonNull String commandId, @Nullable ReadableArray commandArgs) {
int surfaceId, int reactTag, String commandId, @Nullable ReadableArray commandArgs) {
UiThreadUtil.assertOnUiThread();
getSurfaceManagerEnforced(surfaceId, "receiveCommand:string")
.receiveCommand(reactTag, commandId, commandArgs);
Expand Down Expand Up @@ -357,15 +356,15 @@ public void clearJSResponder() {
*/
@AnyThread
public long measure(
@NonNull ReactContext context,
@NonNull String componentName,
@NonNull ReadableMap localData,
@NonNull ReadableMap props,
@NonNull ReadableMap state,
ReactContext context,
String componentName,
ReadableMap localData,
ReadableMap props,
ReadableMap state,
float width,
@NonNull YogaMeasureMode widthMode,
YogaMeasureMode widthMode,
float height,
@NonNull YogaMeasureMode heightMode,
YogaMeasureMode heightMode,
@Nullable float[] attachmentsPositions) {

return mViewManagerRegistry
Expand Down Expand Up @@ -400,15 +399,15 @@ public long measure(
*/
@AnyThread
public long measureMapBuffer(
@NonNull ReactContext context,
@NonNull String componentName,
@NonNull MapBuffer localData,
@NonNull MapBuffer props,
ReactContext context,
String componentName,
MapBuffer localData,
MapBuffer props,
@Nullable MapBuffer state,
float width,
@NonNull YogaMeasureMode widthMode,
YogaMeasureMode widthMode,
float height,
@NonNull YogaMeasureMode heightMode,
YogaMeasureMode heightMode,
@Nullable float[] attachmentsPositions) {

return mViewManagerRegistry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.net.Uri;
import android.os.ParcelFileDescriptor;
import androidx.annotation.Nullable;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.bridge.ReactContext;
Expand All @@ -23,6 +24,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Nullsafe(Nullsafe.Mode.LOCAL)
public final class BlobProvider extends ContentProvider {

private static final int PIPE_CAPACITY = 65536;
Expand Down Expand Up @@ -72,6 +74,9 @@ public int update(Uri uri, ContentValues values, String selection, String[] sele
if (context instanceof ReactApplication) {
ReactNativeHost host = ((ReactApplication) context).getReactNativeHost();
ReactContext reactContext = host.getReactInstanceManager().getCurrentReactContext();
if (reactContext == null) {
throw new RuntimeException("No ReactContext associated with BlobProvider");
}
blobModule = reactContext.getNativeModule(BlobModule.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
package com.facebook.react.modules.blob;

import android.util.Base64;
import androidx.annotation.Nullable;
import com.facebook.fbreact.specs.NativeFileReaderModuleSpec;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.module.annotations.ReactModule;

@Nullsafe(Nullsafe.Mode.LOCAL)
@ReactModule(name = NativeFileReaderModuleSpec.NAME)
public class FileReaderModule extends NativeFileReaderModuleSpec {

Expand All @@ -23,7 +26,7 @@ public FileReaderModule(ReactApplicationContext reactContext) {
super(reactContext);
}

private BlobModule getBlobModule(String reason) {
private @Nullable BlobModule getBlobModule(String reason) {
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();

if (reactApplicationContext != null) {
Expand All @@ -46,8 +49,13 @@ public void readAsText(ReadableMap blob, String encoding, Promise promise) {
return;
}

byte[] bytes =
blobModule.resolve(blob.getString("blobId"), blob.getInt("offset"), blob.getInt("size"));
String blobId = blob.getString("blobId");
if (blobId == null) {
promise.reject(ERROR_INVALID_BLOB, "The specified blob does not contain a blobId");
return;
}

byte[] bytes = blobModule.resolve(blobId, blob.getInt("offset"), blob.getInt("size"));

if (bytes == null) {
promise.reject(ERROR_INVALID_BLOB, "The specified blob is invalid");
Expand All @@ -74,8 +82,13 @@ public void readAsDataURL(ReadableMap blob, Promise promise) {
return;
}

byte[] bytes =
blobModule.resolve(blob.getString("blobId"), blob.getInt("offset"), blob.getInt("size"));
String blobId = blob.getString("blobId");
if (blobId == null) {
promise.reject(ERROR_INVALID_BLOB, "The specified blob does not contain a blobId");
return;
}

byte[] bytes = blobModule.resolve(blobId, blob.getInt("offset"), blob.getInt("size"));

if (bytes == null) {
promise.reject(ERROR_INVALID_BLOB, "The specified blob is invalid");
Expand All @@ -86,7 +99,9 @@ public void readAsDataURL(ReadableMap blob, Promise promise) {
StringBuilder sb = new StringBuilder();
sb.append("data:");

if (blob.hasKey("type") && !blob.getString("type").isEmpty()) {
if (blob.hasKey("type")
&& blob.getString("type") != null
&& !blob.getString("type").isEmpty()) {
sb.append(blob.getString("type"));
} else {
sb.append("application/octet-stream");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@
import android.content.DialogInterface.OnClickListener;
import android.content.DialogInterface.OnDismissListener;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import com.facebook.common.logging.FLog;
import com.facebook.fbreact.specs.NativeDialogManagerAndroidSpec;
import com.facebook.infer.annotation.Assertions;
import com.facebook.infer.annotation.Nullsafe;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactApplicationContext;
Expand All @@ -29,6 +30,7 @@
import com.facebook.react.module.annotations.ReactModule;
import java.util.Map;

@Nullsafe(Nullsafe.Mode.LOCAL)
@ReactModule(name = NativeDialogManagerAndroidSpec.NAME)
public class DialogModule extends NativeDialogManagerAndroidSpec implements LifecycleEventListener {

Expand Down Expand Up @@ -59,12 +61,13 @@ public DialogModule(ReactApplicationContext reactContext) {
super(reactContext);
}

@Nullsafe(Nullsafe.Mode.LOCAL)
private class FragmentManagerHelper {
private final @NonNull FragmentManager mFragmentManager;
private final FragmentManager mFragmentManager;

private @Nullable Object mFragmentToShow;

public FragmentManagerHelper(@NonNull FragmentManager fragmentManager) {
public FragmentManagerHelper(FragmentManager fragmentManager) {
mFragmentManager = fragmentManager;
}

Expand Down Expand Up @@ -110,6 +113,7 @@ public void showNewAlert(Bundle arguments, Callback actionCallback) {
}
}

@Nullsafe(Nullsafe.Mode.LOCAL)
/* package */ class AlertFragmentListener implements OnClickListener, OnDismissListener {

private final Callback mCallback;
Expand All @@ -130,7 +134,7 @@ public void onClick(DialogInterface dialog, int which) {
}

@Override
public void onDismiss(DialogInterface dialog) {
public void onDismiss(@Nullable DialogInterface dialog) {
if (!mCallbackConsumed) {
if (getReactApplicationContext().hasActiveReactInstance()) {
mCallback.invoke(ACTION_DISMISSED);
Expand Down Expand Up @@ -198,6 +202,7 @@ public void showAlert(
}
if (options.hasKey(KEY_ITEMS)) {
ReadableArray items = options.getArray(KEY_ITEMS);
Assertions.assertNotNull(items);
CharSequence[] itemsArray = new CharSequence[items.size()];
for (int i = 0; i < items.size(); i++) {
itemsArray[i] = items.getString(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.os.Looper;
import androidx.annotation.Nullable;
import com.facebook.common.logging.FLog;
import com.facebook.infer.annotation.Nullsafe;
import java.io.IOException;
import java.nio.channels.ClosedChannelException;
import java.util.concurrent.TimeUnit;
Expand All @@ -22,6 +23,7 @@
import okio.ByteString;

/** A wrapper around WebSocketClient that reconnects automatically */
@Nullsafe(Nullsafe.Mode.LOCAL)
public final class ReconnectingWebSocket extends WebSocketListener {
private static final String TAG = ReconnectingWebSocket.class.getSimpleName();

Expand Down Expand Up @@ -138,7 +140,8 @@ public synchronized void onOpen(WebSocket webSocket, Response response) {
}

@Override
public synchronized void onFailure(WebSocket webSocket, Throwable t, Response response) {
public synchronized void onFailure(
@Nullable WebSocket webSocket, Throwable t, @Nullable Response response) {
if (mWebSocket != null) {
abort("Websocket exception", t);
}
Expand Down
Loading
Loading