mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-17 11:27:17 +01:00
492 lines
18 KiB
Java
492 lines
18 KiB
Java
package com.facebook.react.bridge;
|
|
|
|
import android.app.Activity;
|
|
import android.content.Context;
|
|
import android.content.ContextWrapper;
|
|
import android.content.Intent;
|
|
import android.os.Bundle;
|
|
import android.view.LayoutInflater;
|
|
import androidx.annotation.NonNull;
|
|
import androidx.annotation.Nullable;
|
|
import com.facebook.common.logging.FLog;
|
|
import com.facebook.infer.annotation.Assertions;
|
|
import com.facebook.infer.annotation.ThreadConfined;
|
|
import com.facebook.proguard.annotations.DoNotStrip;
|
|
import com.facebook.react.bridge.interop.InteropModuleRegistry;
|
|
import com.facebook.react.bridge.queue.MessageQueueThread;
|
|
import com.facebook.react.bridge.queue.ReactQueueConfiguration;
|
|
import com.facebook.react.common.LifecycleState;
|
|
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
|
|
import java.lang.ref.WeakReference;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes6.dex */
|
|
public abstract class ReactContext extends ContextWrapper {
|
|
private static final String TAG = "ReactContext";
|
|
private final CopyOnWriteArraySet<ActivityEventListener> mActivityEventListeners;
|
|
|
|
@Nullable
|
|
private WeakReference<Activity> mCurrentActivity;
|
|
|
|
@Nullable
|
|
private JSExceptionHandler mExceptionHandlerWrapper;
|
|
|
|
@Nullable
|
|
private LayoutInflater mInflater;
|
|
|
|
@Nullable
|
|
protected InteropModuleRegistry mInteropModuleRegistry;
|
|
private boolean mIsInitialized;
|
|
|
|
@Nullable
|
|
private JSExceptionHandler mJSExceptionHandler;
|
|
|
|
@Nullable
|
|
private MessageQueueThread mJSMessageQueueThread;
|
|
private final CopyOnWriteArraySet<LifecycleEventListener> mLifecycleEventListeners;
|
|
private LifecycleState mLifecycleState;
|
|
|
|
@Nullable
|
|
private MessageQueueThread mNativeModulesMessageQueueThread;
|
|
|
|
@Nullable
|
|
private ReactQueueConfiguration mQueueConfig;
|
|
|
|
@Nullable
|
|
private MessageQueueThread mUiMessageQueueThread;
|
|
private final CopyOnWriteArraySet<WindowFocusChangeListener> mWindowFocusEventListeners;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* renamed from: com.facebook.react.bridge.ReactContext$2, reason: invalid class name */
|
|
public static /* synthetic */ class AnonymousClass2 {
|
|
static final /* synthetic */ int[] $SwitchMap$com$facebook$react$common$LifecycleState;
|
|
|
|
static {
|
|
int[] iArr = new int[LifecycleState.values().length];
|
|
$SwitchMap$com$facebook$react$common$LifecycleState = iArr;
|
|
try {
|
|
iArr[LifecycleState.BEFORE_CREATE.ordinal()] = 1;
|
|
} catch (NoSuchFieldError unused) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$facebook$react$common$LifecycleState[LifecycleState.BEFORE_RESUME.ordinal()] = 2;
|
|
} catch (NoSuchFieldError unused2) {
|
|
}
|
|
try {
|
|
$SwitchMap$com$facebook$react$common$LifecycleState[LifecycleState.RESUMED.ordinal()] = 3;
|
|
} catch (NoSuchFieldError unused3) {
|
|
}
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public class ExceptionHandlerWrapper implements JSExceptionHandler {
|
|
public ExceptionHandlerWrapper() {
|
|
}
|
|
|
|
@Override // com.facebook.react.bridge.JSExceptionHandler
|
|
public void handleException(Exception exc) {
|
|
ReactContext.this.handleException(exc);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@DoNotStrip
|
|
public interface RCTDeviceEventEmitter extends JavaScriptModule {
|
|
void emit(@NonNull String str, @Nullable Object obj);
|
|
}
|
|
|
|
public ReactContext(Context context) {
|
|
super(context);
|
|
this.mLifecycleEventListeners = new CopyOnWriteArraySet<>();
|
|
this.mActivityEventListeners = new CopyOnWriteArraySet<>();
|
|
this.mWindowFocusEventListeners = new CopyOnWriteArraySet<>();
|
|
this.mLifecycleState = LifecycleState.BEFORE_CREATE;
|
|
this.mIsInitialized = false;
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
private void onHostDestroyImpl() {
|
|
UiThreadUtil.assertOnUiThread();
|
|
this.mLifecycleState = LifecycleState.BEFORE_CREATE;
|
|
Iterator<LifecycleEventListener> it2 = this.mLifecycleEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onHostDestroy();
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void addActivityEventListener(ActivityEventListener activityEventListener) {
|
|
this.mActivityEventListeners.add(activityEventListener);
|
|
}
|
|
|
|
public void addLifecycleEventListener(final LifecycleEventListener lifecycleEventListener) {
|
|
int i;
|
|
this.mLifecycleEventListeners.add(lifecycleEventListener);
|
|
if ((!hasActiveReactInstance() && !isBridgeless()) || (i = AnonymousClass2.$SwitchMap$com$facebook$react$common$LifecycleState[this.mLifecycleState.ordinal()]) == 1 || i == 2) {
|
|
return;
|
|
}
|
|
if (i == 3) {
|
|
runOnUiQueueThread(new Runnable() { // from class: com.facebook.react.bridge.ReactContext.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
if (ReactContext.this.mLifecycleEventListeners.contains(lifecycleEventListener)) {
|
|
try {
|
|
lifecycleEventListener.onHostResume();
|
|
} catch (RuntimeException e) {
|
|
ReactContext.this.handleException(e);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
Single$$ExternalSyntheticBUOutline0.m$2("Unhandled lifecycle state.");
|
|
}
|
|
}
|
|
|
|
public void addWindowFocusChangeListener(WindowFocusChangeListener windowFocusChangeListener) {
|
|
this.mWindowFocusEventListeners.add(windowFocusChangeListener);
|
|
}
|
|
|
|
public void assertOnJSQueueThread() {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mJSMessageQueueThread)).assertIsOnThread();
|
|
}
|
|
|
|
public void assertOnNativeModulesQueueThread() {
|
|
if (this.mIsInitialized) {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mNativeModulesMessageQueueThread)).assertIsOnThread();
|
|
} else {
|
|
Single$$ExternalSyntheticBUOutline0.m$2("Tried to call assertOnNativeModulesQueueThread() on an uninitialized ReactContext");
|
|
}
|
|
}
|
|
|
|
public void assertOnUiQueueThread() {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mUiMessageQueueThread)).assertIsOnThread();
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public abstract void destroy();
|
|
|
|
public void emitDeviceEvent(String str, @Nullable Object obj) {
|
|
RCTDeviceEventEmitter rCTDeviceEventEmitter = (RCTDeviceEventEmitter) getJSModule(RCTDeviceEventEmitter.class);
|
|
if (rCTDeviceEventEmitter != null) {
|
|
rCTDeviceEventEmitter.emit(str, obj);
|
|
}
|
|
}
|
|
|
|
public abstract CatalystInstance getCatalystInstance();
|
|
|
|
@Nullable
|
|
public Activity getCurrentActivity() {
|
|
WeakReference<Activity> weakReference = this.mCurrentActivity;
|
|
if (weakReference == null) {
|
|
return null;
|
|
}
|
|
return weakReference.get();
|
|
}
|
|
|
|
public JSExceptionHandler getExceptionHandler() {
|
|
if (this.mExceptionHandlerWrapper == null) {
|
|
this.mExceptionHandlerWrapper = new ExceptionHandlerWrapper();
|
|
}
|
|
return this.mExceptionHandlerWrapper;
|
|
}
|
|
|
|
@Nullable
|
|
@Deprecated(since = "This method is deprecated, please use UIManagerHelper.getUIManager() instead.")
|
|
public abstract UIManager getFabricUIManager();
|
|
|
|
@Nullable
|
|
public abstract CallInvokerHolder getJSCallInvokerHolder();
|
|
|
|
public JSExceptionHandler getJSExceptionHandler() {
|
|
return this.mJSExceptionHandler;
|
|
}
|
|
|
|
@Nullable
|
|
public MessageQueueThread getJSMessageQueueThread() {
|
|
return this.mJSMessageQueueThread;
|
|
}
|
|
|
|
public abstract <T extends JavaScriptModule> T getJSModule(Class<T> cls);
|
|
|
|
@Nullable
|
|
public abstract JavaScriptContextHolder getJavaScriptContextHolder();
|
|
|
|
public LifecycleState getLifecycleState() {
|
|
return this.mLifecycleState;
|
|
}
|
|
|
|
@Nullable
|
|
public abstract <T extends NativeModule> T getNativeModule(Class<T> cls);
|
|
|
|
@Nullable
|
|
public abstract NativeModule getNativeModule(String str);
|
|
|
|
public abstract Collection<NativeModule> getNativeModules();
|
|
|
|
@Nullable
|
|
public MessageQueueThread getNativeModulesMessageQueueThread() {
|
|
return this.mNativeModulesMessageQueueThread;
|
|
}
|
|
|
|
@Nullable
|
|
public abstract String getSourceURL();
|
|
|
|
@Override // android.content.ContextWrapper, android.content.Context
|
|
public Object getSystemService(String str) {
|
|
if (!"layout_inflater".equals(str)) {
|
|
return getBaseContext().getSystemService(str);
|
|
}
|
|
if (this.mInflater == null) {
|
|
this.mInflater = LayoutInflater.from(getBaseContext()).cloneInContext(this);
|
|
}
|
|
return this.mInflater;
|
|
}
|
|
|
|
@Nullable
|
|
public MessageQueueThread getUiMessageQueueThread() {
|
|
return this.mUiMessageQueueThread;
|
|
}
|
|
|
|
public abstract void handleException(Exception exc);
|
|
|
|
@Deprecated
|
|
public abstract boolean hasActiveCatalystInstance();
|
|
|
|
public abstract boolean hasActiveReactInstance();
|
|
|
|
@Deprecated
|
|
public abstract boolean hasCatalystInstance();
|
|
|
|
public boolean hasCurrentActivity() {
|
|
WeakReference<Activity> weakReference = this.mCurrentActivity;
|
|
return (weakReference == null || weakReference.get() == null) ? false : true;
|
|
}
|
|
|
|
public abstract <T extends NativeModule> boolean hasNativeModule(Class<T> cls);
|
|
|
|
public abstract boolean hasReactInstance();
|
|
|
|
public void initializeFromOther(ReactContext reactContext) {
|
|
if (reactContext.hasReactInstance()) {
|
|
initializeMessageQueueThreads(reactContext.mQueueConfig);
|
|
}
|
|
this.mInteropModuleRegistry = reactContext.mInteropModuleRegistry;
|
|
}
|
|
|
|
public void initializeInteropModules() {
|
|
this.mInteropModuleRegistry = new InteropModuleRegistry();
|
|
}
|
|
|
|
public synchronized void initializeMessageQueueThreads(ReactQueueConfiguration reactQueueConfiguration) {
|
|
FLog.d(TAG, "initializeMessageQueueThreads() is called.");
|
|
if (this.mUiMessageQueueThread != null || this.mNativeModulesMessageQueueThread != null || this.mJSMessageQueueThread != null) {
|
|
throw new IllegalStateException("Message queue threads already initialized");
|
|
}
|
|
this.mQueueConfig = reactQueueConfiguration;
|
|
this.mUiMessageQueueThread = reactQueueConfiguration.getUIQueueThread();
|
|
this.mNativeModulesMessageQueueThread = reactQueueConfiguration.getNativeModulesQueueThread();
|
|
MessageQueueThread jSQueueThread = reactQueueConfiguration.getJSQueueThread();
|
|
this.mJSMessageQueueThread = jSQueueThread;
|
|
if (this.mUiMessageQueueThread == null) {
|
|
throw new IllegalStateException("UI thread is null");
|
|
}
|
|
if (this.mNativeModulesMessageQueueThread == null) {
|
|
throw new IllegalStateException("NativeModules thread is null");
|
|
}
|
|
if (jSQueueThread == null) {
|
|
throw new IllegalStateException("JavaScript thread is null");
|
|
}
|
|
this.mIsInitialized = true;
|
|
}
|
|
|
|
public <T extends JavaScriptModule> void internal_registerInteropModule(Class<T> cls, Object obj) {
|
|
InteropModuleRegistry interopModuleRegistry = this.mInteropModuleRegistry;
|
|
if (interopModuleRegistry != null) {
|
|
interopModuleRegistry.registerInteropModule(cls, obj);
|
|
}
|
|
}
|
|
|
|
@Deprecated
|
|
public abstract boolean isBridgeless();
|
|
|
|
public boolean isOnJSQueueThread() {
|
|
return ((MessageQueueThread) Assertions.assertNotNull(this.mJSMessageQueueThread)).isOnThread();
|
|
}
|
|
|
|
public boolean isOnNativeModulesQueueThread() {
|
|
return ((MessageQueueThread) Assertions.assertNotNull(this.mNativeModulesMessageQueueThread)).isOnThread();
|
|
}
|
|
|
|
public boolean isOnUiQueueThread() {
|
|
return ((MessageQueueThread) Assertions.assertNotNull(this.mUiMessageQueueThread)).isOnThread();
|
|
}
|
|
|
|
public void onActivityResult(Activity activity, int i, int i2, @Nullable Intent intent) {
|
|
Iterator<ActivityEventListener> it2 = this.mActivityEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onActivityResult(activity, i, i2, intent);
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onHostDestroy(boolean z) {
|
|
if (z) {
|
|
onHostDestroyImpl();
|
|
} else {
|
|
onHostDestroy();
|
|
}
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onHostPause() {
|
|
this.mLifecycleState = LifecycleState.BEFORE_RESUME;
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_PAUSE_START);
|
|
Iterator<LifecycleEventListener> it2 = this.mLifecycleEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onHostPause();
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_PAUSE_END);
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onHostResume(@Nullable Activity activity) {
|
|
this.mLifecycleState = LifecycleState.RESUMED;
|
|
this.mCurrentActivity = new WeakReference<>(activity);
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_RESUME_START);
|
|
Iterator<LifecycleEventListener> it2 = this.mLifecycleEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onHostResume();
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_HOST_RESUME_END);
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onNewIntent(@Nullable Activity activity, Intent intent) {
|
|
UiThreadUtil.assertOnUiThread();
|
|
this.mCurrentActivity = new WeakReference<>(activity);
|
|
Iterator<ActivityEventListener> it2 = this.mActivityEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onNewIntent(intent);
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onUserLeaveHint(@Nullable Activity activity) {
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_USER_LEAVE_HINT_START);
|
|
Iterator<ActivityEventListener> it2 = this.mActivityEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onUserLeaveHint(activity);
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
ReactMarker.logMarker(ReactMarkerConstants.ON_USER_LEAVE_HINT_END);
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onWindowFocusChange(boolean z) {
|
|
UiThreadUtil.assertOnUiThread();
|
|
Iterator<WindowFocusChangeListener> it2 = this.mWindowFocusEventListeners.iterator();
|
|
while (it2.hasNext()) {
|
|
try {
|
|
it2.next().onWindowFocusChange(z);
|
|
} catch (RuntimeException e) {
|
|
handleException(e);
|
|
}
|
|
}
|
|
}
|
|
|
|
public abstract void registerSegment(int i, String str, Callback callback);
|
|
|
|
public void removeActivityEventListener(ActivityEventListener activityEventListener) {
|
|
this.mActivityEventListeners.remove(activityEventListener);
|
|
}
|
|
|
|
public void removeLifecycleEventListener(LifecycleEventListener lifecycleEventListener) {
|
|
this.mLifecycleEventListeners.remove(lifecycleEventListener);
|
|
}
|
|
|
|
public void removeWindowFocusChangeListener(WindowFocusChangeListener windowFocusChangeListener) {
|
|
this.mWindowFocusEventListeners.remove(windowFocusChangeListener);
|
|
}
|
|
|
|
public void resetPerfStats() {
|
|
MessageQueueThread messageQueueThread = this.mNativeModulesMessageQueueThread;
|
|
if (messageQueueThread != null) {
|
|
messageQueueThread.resetPerfStats();
|
|
}
|
|
MessageQueueThread messageQueueThread2 = this.mJSMessageQueueThread;
|
|
if (messageQueueThread2 != null) {
|
|
messageQueueThread2.resetPerfStats();
|
|
}
|
|
}
|
|
|
|
public boolean runOnJSQueueThread(Runnable runnable) {
|
|
return ((MessageQueueThread) Assertions.assertNotNull(this.mJSMessageQueueThread)).runOnQueue(runnable);
|
|
}
|
|
|
|
public void runOnNativeModulesQueueThread(Runnable runnable) {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mNativeModulesMessageQueueThread)).runOnQueue(runnable);
|
|
}
|
|
|
|
public void runOnUiQueueThread(Runnable runnable) {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mUiMessageQueueThread)).runOnQueue(runnable);
|
|
}
|
|
|
|
public void setJSExceptionHandler(@Nullable JSExceptionHandler jSExceptionHandler) {
|
|
this.mJSExceptionHandler = jSExceptionHandler;
|
|
}
|
|
|
|
public boolean startActivityForResult(Intent intent, int i, Bundle bundle) {
|
|
Activity currentActivity = getCurrentActivity();
|
|
if (currentActivity == null) {
|
|
return false;
|
|
}
|
|
currentActivity.startActivityForResult(intent, i, bundle);
|
|
return true;
|
|
}
|
|
|
|
@ThreadConfined(ThreadConfined.UI)
|
|
public void onHostDestroy() {
|
|
onHostDestroyImpl();
|
|
this.mCurrentActivity = null;
|
|
}
|
|
|
|
public void emitDeviceEvent(String str) {
|
|
emitDeviceEvent(str, null);
|
|
}
|
|
|
|
public void assertOnNativeModulesQueueThread(String str) {
|
|
if (this.mIsInitialized) {
|
|
((MessageQueueThread) Assertions.assertNotNull(this.mNativeModulesMessageQueueThread)).assertIsOnThread(str);
|
|
} else {
|
|
Single$$ExternalSyntheticBUOutline0.m$2("Tried to call assertOnNativeModulesQueueThread(message) on an uninitialized ReactContext");
|
|
}
|
|
}
|
|
}
|