Skip to content

Commit

Permalink
Add AppIdentity and DeviceIdentity to Inspector
Browse files Browse the repository at this point in the history
Reviewed By: Hypuk

Differential Revision: D5924011

fbshipit-source-id: a81d420dbe1a5ede203d2fa313548e19664b9587
  • Loading branch information
pakoito authored and facebook-github-bot committed Oct 3, 2017
1 parent 96f23e7 commit da14fad
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 5 deletions.
4 changes: 4 additions & 0 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,13 @@ - (void)start
BOOL useCustomJSC =
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
[self.delegate shouldBridgeUseCustomJSC:self];
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// The arg is a cache dir. It's not used with standard JSC.
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
("OwnerIdentity", "ReactNative")
("AppIdentity", [(escapedAppName ?: @"unknown") UTF8String])
("DeviceIdentity", [(escapedDeviceName ?: @"unknown") UTF8String])
("UseCustomJSC", (bool)useCustomJSC)
#if RCT_PROFILE
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public CatalystInstance build() {
}
JavaScriptExecutor executor = null;
try {
executor = new JSCJavaScriptExecutorFactory().create();
executor = new JSCJavaScriptExecutorFactory("ReactTestHelperApp", "ReactTestHelperDevice").create();
} catch (Exception e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

package com.facebook.react;

import static com.facebook.react.modules.systeminfo.AndroidInfoHelpers.getFriendlyDeviceName;

import android.app.Activity;
import android.app.Application;
import android.net.Uri;
import android.os.Build;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSBundleLoader;
import com.facebook.react.bridge.JSCJavaScriptExecutorFactory;
Expand Down Expand Up @@ -262,12 +266,15 @@ public ReactInstanceManager build() {
mUIImplementationProvider = new UIImplementationProvider();
}

String appName = Uri.encode(mApplication.getPackageName());
String deviceName = Uri.encode(getFriendlyDeviceName());

return new ReactInstanceManager(
mApplication,
mCurrentActivity,
mDefaultHardwareBackBtnHandler,
mJavaScriptExecutorFactory == null
? new JSCJavaScriptExecutorFactory()
? new JSCJavaScriptExecutorFactory(appName, deviceName)
: mJavaScriptExecutorFactory,
(mJSBundleLoader == null && mJSBundleAssetUrl != null)
? JSBundleLoader.createAssetLoader(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@
package com.facebook.react.bridge;

public class JSCJavaScriptExecutorFactory implements JavaScriptExecutorFactory {
private final String mAppName;
private final String mDeviceName;

public JSCJavaScriptExecutorFactory(String appName, String deviceName) {
this.mAppName = appName;
this.mDeviceName = deviceName;
}

@Override
public JavaScriptExecutor create() throws Exception {
WritableNativeMap jscConfig = new WritableNativeMap();
jscConfig.putString("OwnerIdentity", "ReactNative");
jscConfig.putString("AppIdentity", mAppName);
jscConfig.putString("OwnerIdentity", mDeviceName);
return new JSCJavaScriptExecutor(jscConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public static String getInspectorProxyHost() {
return getServerIpAddress(INSPECTOR_PROXY_PORT);
}

// FIXME(festevezga): This method is duplicated in an internal module. Any changes should be applied to both.
public static String getFriendlyDeviceName() {
if (isRunningOnGenymotion()) {
// Genymotion already has a friendly name by default
Expand Down
9 changes: 7 additions & 2 deletions ReactCommon/cxxreact/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,14 @@ void JSCExecutor::initOnJSVMThread() throw(JSException) {
Object::getGlobalObject(m_context).setPrivate(this);

if (canUseInspector(m_context)) {
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "main").getString();
const std::string ownerId = m_jscConfig.getDefault("OwnerIdentity", "unknown").getString();
const std::string appId = m_jscConfig.getDefault("AppIdentity", "unknown").getString();
const std::string deviceId = m_jscConfig.getDefault("DeviceIdentity", "unknown").getString();
const std::function<bool()> checkIsInspectedRemote = [&ownerId, &appId, &deviceId](){
return false;
};
IInspector* pInspector = JSC_JSInspectorGetInstance(true);
pInspector->registerGlobalContext(ownerId, m_context);
pInspector->registerGlobalContext(ownerId, checkIsInspectedRemote, m_context);
}

installNativeHook<&JSCExecutor::nativeFlushQueueImmediate>("nativeFlushQueueImmediate");
Expand Down
4 changes: 3 additions & 1 deletion ReactCommon/jschelpers/InspectorInterfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@

#pragma once

#include <functional>
#include <memory>
#include <string>
#include <vector>

#include <JavaScriptCore/JSBase.h>

namespace facebook {
Expand Down Expand Up @@ -44,7 +46,7 @@ class ILocalConnection : public IDestructible {
// Note: not destructible!
class IInspector {
public:
virtual void registerGlobalContext(std::string title, JSGlobalContextRef ctx) = 0;
virtual void registerGlobalContext(const std::string& title, const std::function<bool()> &checkIsInspectedRemote, JSGlobalContextRef ctx) = 0;
virtual void unregisterGlobalContext(JSGlobalContextRef ctx) = 0;

virtual std::vector<InspectorPage> getPages() const = 0;
Expand Down

0 comments on commit da14fad

Please sign in to comment.