Skip to content

Commit

Permalink
Implement new HostTargetMetadata fields (Android Bridgeless)
Browse files Browse the repository at this point in the history
Summary:
Follows D58288489, D58415181.

Implements the remaining `HostTargetMetadata` fields, sent by the debugger on `ReactNativeApplication.metadataUpdated`, on **Android Bridgeless**.

This will be used to display details such as the app name and React Native version in the debugger frontend.

Changelog: [Internal]

Differential Revision: D59271755
  • Loading branch information
huntie authored and facebook-github-bot committed Jul 2, 2024
1 parent 6e046d5 commit 04a21b5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import com.facebook.react.modules.appearance.AppearanceModule;
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
import com.facebook.react.runtime.internal.bolts.Task;
import com.facebook.react.runtime.internal.bolts.TaskCompletionSource;
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
Expand All @@ -73,6 +74,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
Expand Down Expand Up @@ -486,6 +488,11 @@ public void onResume() {
}
}

@DoNotStrip
private Map<String, String> getHostMetadata() {
return AndroidInfoHelpers.getInspectorHostMetadata(mContext);
}

/**
* Entrypoint to destroy the ReactInstance. If the ReactInstance is reloading, will wait until
* reload is finished, before destroying.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,31 @@ void JReactHostInspectorTarget::registerNatives() {

jsinspector_modern::HostTargetMetadata
JReactHostInspectorTarget::getMetadata() {
return {
jsinspector_modern::HostTargetMetadata metadata = {
.integrationName = "Android Bridgeless (ReactHostImpl)",
};

if (auto javaReactHostImplStrong = javaReactHostImpl_->get()) {
auto javaMetadata = javaReactHostImplStrong->getHostMetadata();
auto mapClass = findClassLocal("java/util/Map");
auto getMethod = mapClass->getMethod<jobject(jobject)>("get");

auto appIdentifier =
getMethod(javaMetadata, make_jstring("appIdentifier").get());
auto deviceName = getMethod(javaMetadata, make_jstring("deviceName").get());
auto platform = getMethod(javaMetadata, make_jstring("platform").get());
auto reactNativeVersion =
getMethod(javaMetadata, make_jstring("reactNativeVersion").get());

metadata.appIdentifier =
appIdentifier ? appIdentifier->toString() : nullptr;
metadata.deviceName = deviceName ? deviceName->toString() : nullptr;
metadata.platform = platform ? platform->toString() : nullptr;
metadata.reactNativeVersion =
reactNativeVersion ? reactNativeVersion->toString() : nullptr;
}

return metadata;
}

void JReactHostInspectorTarget::onReload(const PageReloadRequest& request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ struct JReactHostImpl : public jni::JavaClass<JReactHostImpl> {
"setPausedInDebuggerMessage");
method(self(), message ? jni::make_jstring(*message) : nullptr);
}

jni::local_ref<jni::JMap<jstring, jstring>> getHostMetadata() const {
static auto method =
javaClassStatic()
->getMethod<jni::local_ref<jni::JMap<jstring, jstring>>()>(
"getHostMetadata");
return method(self());
}
};

class JReactHostInspectorTarget
Expand Down

0 comments on commit 04a21b5

Please sign in to comment.