mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Remove the native delta client from Android
Summary: This was an experiment to patch individual deltas in development instead of reloading the whole JS bundle. With improvements such as Fast Refresh that reduces the need for reloads and bundle splitting that reduces the number of modules and memory by 10x, we won't be needing this complex optimization that we never properly made work. This diff removes that code and I will be removing the JS side of things in Metro in a follow-up diff. Reviewed By: fkgozali Differential Revision: D16832709 fbshipit-source-id: 46596a3126d52d7d74f4b9ffc9a6ee9d82ec9522
This commit is contained in:
committed by
Facebook Github Bot
parent
6991e28653
commit
bb625e5238
@@ -56,7 +56,6 @@ import com.facebook.react.bridge.JSIModuleType;
|
||||
import com.facebook.react.bridge.JavaJSExecutor;
|
||||
import com.facebook.react.bridge.JavaScriptExecutor;
|
||||
import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
import com.facebook.react.bridge.NativeModuleCallExceptionHandler;
|
||||
import com.facebook.react.bridge.NativeModuleRegistry;
|
||||
import com.facebook.react.bridge.NotThreadSafeBridgeIdleDebugListener;
|
||||
@@ -279,8 +278,8 @@ public class ReactInstanceManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJSBundleLoadedFromServer(@Nullable NativeDeltaClient nativeDeltaClient) {
|
||||
ReactInstanceManager.this.onJSBundleLoadedFromServer(nativeDeltaClient);
|
||||
public void onJSBundleLoadedFromServer() {
|
||||
ReactInstanceManager.this.onJSBundleLoadedFromServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -389,7 +388,7 @@ public class ReactInstanceManager {
|
||||
&& !devSettings.isRemoteJSDebugEnabled()) {
|
||||
// If there is a up-to-date bundle downloaded from server,
|
||||
// with remote JS debugging disabled, always use that.
|
||||
onJSBundleLoadedFromServer(null);
|
||||
onJSBundleLoadedFromServer();
|
||||
} else {
|
||||
// If dev server is down, disable the remote JS debugging.
|
||||
devSettings.setRemoteJSDebugEnabled(false);
|
||||
@@ -883,15 +882,12 @@ public class ReactInstanceManager {
|
||||
}
|
||||
|
||||
@ThreadConfined(UI)
|
||||
private void onJSBundleLoadedFromServer(@Nullable NativeDeltaClient nativeDeltaClient) {
|
||||
private void onJSBundleLoadedFromServer() {
|
||||
Log.d(ReactConstants.TAG, "ReactInstanceManager.onJSBundleLoadedFromServer()");
|
||||
|
||||
JSBundleLoader bundleLoader =
|
||||
nativeDeltaClient == null
|
||||
? JSBundleLoader.createCachedBundleFromNetworkLoader(
|
||||
mDevSupportManager.getSourceUrl(), mDevSupportManager.getDownloadedJSBundleFile())
|
||||
: JSBundleLoader.createDeltaFromNetworkLoader(
|
||||
mDevSupportManager.getSourceUrl(), nativeDeltaClient);
|
||||
JSBundleLoader.createCachedBundleFromNetworkLoader(
|
||||
mDevSupportManager.getSourceUrl(), mDevSupportManager.getDownloadedJSBundleFile());
|
||||
|
||||
recreateReactContextInBackground(mJavaScriptExecutorFactory, bundleLoader);
|
||||
}
|
||||
|
||||
@@ -233,13 +233,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
jniLoadScriptFromFile(fileName, sourceURL, loadSynchronously);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadScriptFromDeltaBundle(
|
||||
String sourceURL, NativeDeltaClient deltaClient, boolean loadSynchronously) {
|
||||
mSourceURL = sourceURL;
|
||||
jniLoadScriptFromDeltaBundle(sourceURL, deltaClient, loadSynchronously);
|
||||
}
|
||||
|
||||
private native void jniSetSourceURL(String sourceURL);
|
||||
|
||||
private native void jniRegisterSegment(int segmentId, String path);
|
||||
@@ -250,9 +243,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
|
||||
private native void jniLoadScriptFromFile(
|
||||
String fileName, String sourceURL, boolean loadSynchronously);
|
||||
|
||||
private native void jniLoadScriptFromDeltaBundle(
|
||||
String sourceURL, NativeDeltaClient deltaClient, boolean loadSynchronously);
|
||||
|
||||
@Override
|
||||
public void runJSBundle() {
|
||||
Log.d(ReactConstants.TAG, "CatalystInstanceImpl.runJSBundle()");
|
||||
|
||||
@@ -72,28 +72,6 @@ public abstract class JSBundleLoader {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This loader is used to load delta bundles from the dev server. We pass each delta message to
|
||||
* the loader and process it in C++. Passing it as a string leads to inefficiencies due to memory
|
||||
* copies, which will have to be addressed in a follow-up.
|
||||
*
|
||||
* @param nativeDeltaClient
|
||||
*/
|
||||
public static JSBundleLoader createDeltaFromNetworkLoader(
|
||||
final String sourceURL, final NativeDeltaClient nativeDeltaClient) {
|
||||
return new JSBundleLoader() {
|
||||
@Override
|
||||
public String loadScript(JSBundleLoaderDelegate delegate) {
|
||||
try {
|
||||
delegate.loadScriptFromDeltaBundle(sourceURL, nativeDeltaClient, false);
|
||||
return sourceURL;
|
||||
} catch (Exception e) {
|
||||
throw DebugServerException.makeGeneric(sourceURL, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* This loader is used when proxy debugging is enabled. In that case there is no point in fetching
|
||||
* the bundle from device as remote executor will have to do it anyway.
|
||||
|
||||
@@ -32,17 +32,6 @@ public interface JSBundleLoaderDelegate {
|
||||
*/
|
||||
void loadScriptFromFile(String fileName, String sourceURL, boolean loadSynchronously);
|
||||
|
||||
/**
|
||||
* Load a delta bundle from Metro. See {@link JSBundleLoader#createDeltaFromNetworkLoader(String,
|
||||
* NativeDeltaClient)}
|
||||
*
|
||||
* @param sourceURL
|
||||
* @param deltaClient
|
||||
* @param loadSynchronously
|
||||
*/
|
||||
void loadScriptFromDeltaBundle(
|
||||
String sourceURL, NativeDeltaClient deltaClient, boolean loadSynchronously);
|
||||
|
||||
/**
|
||||
* This API is used in situations where the JS bundle is being executed not on the device, but on
|
||||
* a host machine. In that case, we must provide two source URLs for the JS bundle: One to be used
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
package com.facebook.react.bridge;
|
||||
|
||||
import com.facebook.jni.HybridData;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
|
||||
public class NativeDeltaClient {
|
||||
static {
|
||||
ReactBridge.staticInit();
|
||||
}
|
||||
|
||||
// C++ parts
|
||||
private final HybridData mHybridData = initHybrid();
|
||||
|
||||
private static native HybridData initHybrid();
|
||||
|
||||
public native void reset();
|
||||
|
||||
public native void processDelta(ReadableByteChannel deltaMessage);
|
||||
}
|
||||
@@ -1,202 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
||||
* directory of this source tree.
|
||||
*/
|
||||
package com.facebook.react.devsupport;
|
||||
|
||||
import android.util.JsonReader;
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.TreeMap;
|
||||
import okhttp3.Headers;
|
||||
import okio.BufferedSource;
|
||||
|
||||
public abstract class BundleDeltaClient {
|
||||
|
||||
private static final String METRO_DELTA_ID_HEADER = "X-Metro-Delta-ID";
|
||||
@Nullable private String mRevisionId;
|
||||
|
||||
public enum ClientType {
|
||||
NONE,
|
||||
DEV_SUPPORT,
|
||||
NATIVE
|
||||
}
|
||||
|
||||
static boolean isDeltaUrl(String bundleUrl) {
|
||||
return bundleUrl.indexOf(".delta?") != -1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
static BundleDeltaClient create(ClientType type) {
|
||||
switch (type) {
|
||||
case DEV_SUPPORT:
|
||||
return new BundleDeltaJavaClient();
|
||||
case NATIVE:
|
||||
return new BundleDeltaNativeClient();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public abstract boolean canHandle(ClientType type);
|
||||
|
||||
protected abstract Pair<Boolean, NativeDeltaClient> processDelta(
|
||||
BufferedSource body, File outputFile) throws IOException;
|
||||
|
||||
public final synchronized String extendUrlForDelta(String bundleURL) {
|
||||
return mRevisionId != null ? bundleURL + "&revisionId=" + mRevisionId : bundleURL;
|
||||
}
|
||||
|
||||
public synchronized void reset() {
|
||||
mRevisionId = null;
|
||||
}
|
||||
|
||||
public synchronized Pair<Boolean, NativeDeltaClient> processDelta(
|
||||
Headers headers, BufferedSource body, File outputFile) throws IOException {
|
||||
|
||||
mRevisionId = headers.get(METRO_DELTA_ID_HEADER);
|
||||
return processDelta(body, outputFile);
|
||||
}
|
||||
|
||||
private static class BundleDeltaJavaClient extends BundleDeltaClient {
|
||||
|
||||
byte[] mPreCode;
|
||||
byte[] mPostCode;
|
||||
final TreeMap<Number, byte[]> mModules = new TreeMap<Number, byte[]>();
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ClientType type) {
|
||||
return type == ClientType.DEV_SUPPORT;
|
||||
}
|
||||
|
||||
public synchronized void reset() {
|
||||
super.reset();
|
||||
mPreCode = null;
|
||||
mPostCode = null;
|
||||
mModules.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized Pair<Boolean, NativeDeltaClient> processDelta(
|
||||
BufferedSource body, File outputFile) throws IOException {
|
||||
JsonReader jsonReader = new JsonReader(new InputStreamReader(body.inputStream()));
|
||||
jsonReader.beginObject();
|
||||
int numChangedModules = 0;
|
||||
|
||||
while (jsonReader.hasNext()) {
|
||||
String name = jsonReader.nextName();
|
||||
if (name.equals("pre")) {
|
||||
mPreCode = jsonReader.nextString().getBytes();
|
||||
} else if (name.equals("post")) {
|
||||
mPostCode = jsonReader.nextString().getBytes();
|
||||
} else if (name.equals("modules")) {
|
||||
numChangedModules += setModules(jsonReader, mModules);
|
||||
} else if (name.equals("added")) {
|
||||
numChangedModules += setModules(jsonReader, mModules);
|
||||
} else if (name.equals("modified")) {
|
||||
numChangedModules += setModules(jsonReader, mModules);
|
||||
} else if (name.equals("deleted")) {
|
||||
numChangedModules += removeModules(jsonReader, mModules);
|
||||
} else {
|
||||
jsonReader.skipValue();
|
||||
}
|
||||
}
|
||||
|
||||
jsonReader.endObject();
|
||||
jsonReader.close();
|
||||
|
||||
if (numChangedModules == 0) {
|
||||
// If we receive an empty delta, we don't need to save the file again (it'll have the
|
||||
// same content).
|
||||
return Pair.create(Boolean.FALSE, null);
|
||||
}
|
||||
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
|
||||
|
||||
try {
|
||||
fileOutputStream.write(mPreCode);
|
||||
fileOutputStream.write('\n');
|
||||
|
||||
for (byte[] code : mModules.values()) {
|
||||
fileOutputStream.write(code);
|
||||
fileOutputStream.write('\n');
|
||||
}
|
||||
|
||||
fileOutputStream.write(mPostCode);
|
||||
fileOutputStream.write('\n');
|
||||
} finally {
|
||||
fileOutputStream.flush();
|
||||
fileOutputStream.close();
|
||||
}
|
||||
|
||||
return Pair.create(Boolean.TRUE, null);
|
||||
}
|
||||
|
||||
private static int setModules(JsonReader jsonReader, TreeMap<Number, byte[]> map)
|
||||
throws IOException {
|
||||
jsonReader.beginArray();
|
||||
|
||||
int numModules = 0;
|
||||
while (jsonReader.hasNext()) {
|
||||
jsonReader.beginArray();
|
||||
|
||||
int moduleId = jsonReader.nextInt();
|
||||
|
||||
map.put(moduleId, jsonReader.nextString().getBytes());
|
||||
|
||||
jsonReader.endArray();
|
||||
numModules++;
|
||||
}
|
||||
|
||||
jsonReader.endArray();
|
||||
|
||||
return numModules;
|
||||
}
|
||||
|
||||
private static int removeModules(JsonReader jsonReader, TreeMap<Number, byte[]> map)
|
||||
throws IOException {
|
||||
jsonReader.beginArray();
|
||||
|
||||
int numModules = 0;
|
||||
while (jsonReader.hasNext()) {
|
||||
int moduleId = jsonReader.nextInt();
|
||||
|
||||
map.remove(moduleId);
|
||||
|
||||
numModules++;
|
||||
}
|
||||
|
||||
jsonReader.endArray();
|
||||
|
||||
return numModules;
|
||||
}
|
||||
}
|
||||
|
||||
private static class BundleDeltaNativeClient extends BundleDeltaClient {
|
||||
private final NativeDeltaClient nativeClient = new NativeDeltaClient();
|
||||
|
||||
@Override
|
||||
public boolean canHandle(ClientType type) {
|
||||
return type == ClientType.NATIVE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Pair<Boolean, NativeDeltaClient> processDelta(BufferedSource body, File outputFile)
|
||||
throws IOException {
|
||||
nativeClient.processDelta(body);
|
||||
return Pair.create(Boolean.FALSE, nativeClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
nativeClient.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,11 +7,9 @@
|
||||
package com.facebook.react.devsupport;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
import com.facebook.react.common.DebugServerException;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.devsupport.interfaces.DevBundleDownloadListener;
|
||||
@@ -41,12 +39,9 @@ public class BundleDownloader {
|
||||
|
||||
private final OkHttpClient mClient;
|
||||
|
||||
private BundleDeltaClient mBundleDeltaClient;
|
||||
|
||||
private @Nullable Call mDownloadBundleFromURLCall;
|
||||
|
||||
public static class BundleInfo {
|
||||
private @Nullable String mDeltaClientName;
|
||||
private @Nullable String mUrl;
|
||||
private int mFilesChangedCount;
|
||||
|
||||
@@ -59,7 +54,6 @@ public class BundleDownloader {
|
||||
|
||||
try {
|
||||
JSONObject obj = new JSONObject(jsonStr);
|
||||
info.mDeltaClientName = obj.getString("deltaClient");
|
||||
info.mUrl = obj.getString("url");
|
||||
info.mFilesChangedCount = obj.getInt("filesChangedCount");
|
||||
} catch (JSONException e) {
|
||||
@@ -74,7 +68,6 @@ public class BundleDownloader {
|
||||
JSONObject obj = new JSONObject();
|
||||
|
||||
try {
|
||||
obj.put("deltaClient", mDeltaClientName);
|
||||
obj.put("url", mUrl);
|
||||
obj.put("filesChangedCount", mFilesChangedCount);
|
||||
} catch (JSONException e) {
|
||||
@@ -85,10 +78,6 @@ public class BundleDownloader {
|
||||
return obj.toString();
|
||||
}
|
||||
|
||||
public @Nullable String getDeltaClient() {
|
||||
return mDeltaClientName;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return mUrl != null ? mUrl : "unknown";
|
||||
}
|
||||
@@ -106,10 +95,8 @@ public class BundleDownloader {
|
||||
final DevBundleDownloadListener callback,
|
||||
final File outputFile,
|
||||
final String bundleURL,
|
||||
final @Nullable BundleInfo bundleInfo,
|
||||
final BundleDeltaClient.ClientType clientType) {
|
||||
downloadBundleFromURL(
|
||||
callback, outputFile, bundleURL, bundleInfo, clientType, new Request.Builder());
|
||||
final @Nullable BundleInfo bundleInfo) {
|
||||
downloadBundleFromURL(callback, outputFile, bundleURL, bundleInfo, new Request.Builder());
|
||||
}
|
||||
|
||||
public void downloadBundleFromURL(
|
||||
@@ -117,12 +104,11 @@ public class BundleDownloader {
|
||||
final File outputFile,
|
||||
final String bundleURL,
|
||||
final @Nullable BundleInfo bundleInfo,
|
||||
final BundleDeltaClient.ClientType clientType,
|
||||
Request.Builder requestBuilder) {
|
||||
|
||||
final Request request =
|
||||
requestBuilder
|
||||
.url(formatBundleUrl(bundleURL, clientType))
|
||||
.url(formatBundleUrl(bundleURL))
|
||||
// FIXME: there is a bug that makes MultipartStreamReader to never find the end of the
|
||||
// multipart message. This temporarily disables the multipart mode to work around it,
|
||||
// but
|
||||
@@ -165,8 +151,7 @@ public class BundleDownloader {
|
||||
Matcher match = regex.matcher(contentType);
|
||||
try (Response r = response) {
|
||||
if (match.find()) {
|
||||
processMultipartResponse(
|
||||
url, r, match.group(1), outputFile, bundleInfo, clientType, callback);
|
||||
processMultipartResponse(url, r, match.group(1), outputFile, bundleInfo, callback);
|
||||
} else {
|
||||
// In case the server doesn't support multipart/mixed responses, fallback to normal
|
||||
// download.
|
||||
@@ -177,7 +162,6 @@ public class BundleDownloader {
|
||||
Okio.buffer(r.body().source()),
|
||||
outputFile,
|
||||
bundleInfo,
|
||||
clientType,
|
||||
callback);
|
||||
}
|
||||
}
|
||||
@@ -185,12 +169,8 @@ public class BundleDownloader {
|
||||
});
|
||||
}
|
||||
|
||||
private String formatBundleUrl(String bundleURL, BundleDeltaClient.ClientType clientType) {
|
||||
return BundleDeltaClient.isDeltaUrl(bundleURL)
|
||||
&& mBundleDeltaClient != null
|
||||
&& mBundleDeltaClient.canHandle(clientType)
|
||||
? mBundleDeltaClient.extendUrlForDelta(bundleURL)
|
||||
: bundleURL;
|
||||
private String formatBundleUrl(String bundleURL) {
|
||||
return bundleURL;
|
||||
}
|
||||
|
||||
private void processMultipartResponse(
|
||||
@@ -199,7 +179,6 @@ public class BundleDownloader {
|
||||
String boundary,
|
||||
final File outputFile,
|
||||
@Nullable final BundleInfo bundleInfo,
|
||||
final BundleDeltaClient.ClientType clientType,
|
||||
final DevBundleDownloadListener callback)
|
||||
throws IOException {
|
||||
|
||||
@@ -223,14 +202,7 @@ public class BundleDownloader {
|
||||
status = Integer.parseInt(headers.get("X-Http-Status"));
|
||||
}
|
||||
processBundleResult(
|
||||
url,
|
||||
status,
|
||||
Headers.of(headers),
|
||||
body,
|
||||
outputFile,
|
||||
bundleInfo,
|
||||
clientType,
|
||||
callback);
|
||||
url, status, Headers.of(headers), body, outputFile, bundleInfo, callback);
|
||||
} else {
|
||||
if (!headers.containsKey("Content-Type")
|
||||
|| !headers.get("Content-Type").equals("application/json")) {
|
||||
@@ -286,7 +258,6 @@ public class BundleDownloader {
|
||||
BufferedSource body,
|
||||
File outputFile,
|
||||
BundleInfo bundleInfo,
|
||||
BundleDeltaClient.ClientType clientType,
|
||||
DevBundleDownloadListener callback)
|
||||
throws IOException {
|
||||
// Check for server errors. If the server error has the expected form, fail with more info.
|
||||
@@ -311,41 +282,19 @@ public class BundleDownloader {
|
||||
}
|
||||
|
||||
if (bundleInfo != null) {
|
||||
populateBundleInfo(url, headers, clientType, bundleInfo);
|
||||
populateBundleInfo(url, headers, bundleInfo);
|
||||
}
|
||||
|
||||
File tmpFile = new File(outputFile.getPath() + ".tmp");
|
||||
|
||||
boolean bundleWritten;
|
||||
NativeDeltaClient nativeDeltaClient = null;
|
||||
|
||||
if (BundleDeltaClient.isDeltaUrl(url)) {
|
||||
// If the bundle URL has the delta extension, we need to use the delta patching logic.
|
||||
BundleDeltaClient deltaClient = getBundleDeltaClient(clientType);
|
||||
Assertions.assertNotNull(deltaClient);
|
||||
Pair<Boolean, NativeDeltaClient> result = deltaClient.processDelta(headers, body, tmpFile);
|
||||
bundleWritten = result.first;
|
||||
nativeDeltaClient = result.second;
|
||||
} else {
|
||||
mBundleDeltaClient = null;
|
||||
bundleWritten = storePlainJSInFile(body, tmpFile);
|
||||
}
|
||||
|
||||
if (bundleWritten) {
|
||||
if (storePlainJSInFile(body, tmpFile)) {
|
||||
// If we have received a new bundle from the server, move it to its final destination.
|
||||
if (!tmpFile.renameTo(outputFile)) {
|
||||
throw new IOException("Couldn't rename " + tmpFile + " to " + outputFile);
|
||||
}
|
||||
}
|
||||
|
||||
callback.onSuccess(nativeDeltaClient);
|
||||
}
|
||||
|
||||
private BundleDeltaClient getBundleDeltaClient(BundleDeltaClient.ClientType clientType) {
|
||||
if (mBundleDeltaClient == null || !mBundleDeltaClient.canHandle(clientType)) {
|
||||
mBundleDeltaClient = BundleDeltaClient.create(clientType);
|
||||
}
|
||||
return mBundleDeltaClient;
|
||||
callback.onSuccess();
|
||||
}
|
||||
|
||||
private static boolean storePlainJSInFile(BufferedSource body, File outputFile)
|
||||
@@ -363,10 +312,7 @@ public class BundleDownloader {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static void populateBundleInfo(
|
||||
String url, Headers headers, BundleDeltaClient.ClientType clientType, BundleInfo bundleInfo) {
|
||||
bundleInfo.mDeltaClientName =
|
||||
clientType == BundleDeltaClient.ClientType.NONE ? null : clientType.name();
|
||||
private static void populateBundleInfo(String url, Headers headers, BundleInfo bundleInfo) {
|
||||
bundleInfo.mUrl = url;
|
||||
|
||||
String filesChangedCountStr = headers.get("X-Metro-Files-Changed-Count");
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
*/
|
||||
package com.facebook.react.devsupport;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
@@ -27,8 +26,6 @@ public class DevInternalSettings
|
||||
private static final String PREFS_FPS_DEBUG_KEY = "fps_debug";
|
||||
private static final String PREFS_JS_DEV_MODE_DEBUG_KEY = "js_dev_mode_debug";
|
||||
private static final String PREFS_JS_MINIFY_DEBUG_KEY = "js_minify_debug";
|
||||
private static final String PREFS_JS_BUNDLE_DELTAS_KEY = "js_bundle_deltas";
|
||||
private static final String PREFS_JS_BUNDLE_DELTAS_CPP_KEY = "js_bundle_deltas_cpp";
|
||||
private static final String PREFS_ANIMATIONS_DEBUG_KEY = "animations_debug";
|
||||
// This option is no longer exposed in the dev menu UI.
|
||||
// It was renamed in D15958697 so it doesn't get stuck with no way to turn it off:
|
||||
@@ -42,24 +39,12 @@ public class DevInternalSettings
|
||||
private final SharedPreferences mPreferences;
|
||||
private final Listener mListener;
|
||||
private final PackagerConnectionSettings mPackagerConnectionSettings;
|
||||
private final boolean mSupportsNativeDeltaClients;
|
||||
|
||||
public static DevInternalSettings withoutNativeDeltaClient(
|
||||
Context applicationContext, Listener listener) {
|
||||
return new DevInternalSettings(applicationContext, listener, false);
|
||||
}
|
||||
|
||||
public DevInternalSettings(Context applicationContext, Listener listener) {
|
||||
this(applicationContext, listener, true);
|
||||
}
|
||||
|
||||
private DevInternalSettings(
|
||||
Context applicationContext, Listener listener, boolean supportsNativeDeltaClients) {
|
||||
mListener = listener;
|
||||
mPreferences = PreferenceManager.getDefaultSharedPreferences(applicationContext);
|
||||
mPreferences.registerOnSharedPreferenceChangeListener(this);
|
||||
mPackagerConnectionSettings = new PackagerConnectionSettings(applicationContext);
|
||||
mSupportsNativeDeltaClients = supportsNativeDeltaClients;
|
||||
}
|
||||
|
||||
public PackagerConnectionSettings getPackagerConnectionSettings() {
|
||||
@@ -99,8 +84,6 @@ public class DevInternalSettings
|
||||
if (PREFS_FPS_DEBUG_KEY.equals(key)
|
||||
|| PREFS_RELOAD_ON_JS_CHANGE_KEY.equals(key)
|
||||
|| PREFS_JS_DEV_MODE_DEBUG_KEY.equals(key)
|
||||
|| PREFS_JS_BUNDLE_DELTAS_KEY.equals(key)
|
||||
|| PREFS_JS_BUNDLE_DELTAS_CPP_KEY.equals(key)
|
||||
|| PREFS_START_SAMPLING_PROFILER_ON_INIT.equals(key)
|
||||
|| PREFS_JS_MINIFY_DEBUG_KEY.equals(key)) {
|
||||
mListener.onInternalSettingsChanged();
|
||||
@@ -132,27 +115,6 @@ public class DevInternalSettings
|
||||
mPreferences.edit().putBoolean(PREFS_INSPECTOR_DEBUG_KEY, enabled).apply();
|
||||
}
|
||||
|
||||
@SuppressLint("SharedPreferencesUse")
|
||||
public boolean isBundleDeltasEnabled() {
|
||||
return mPreferences.getBoolean(PREFS_JS_BUNDLE_DELTAS_KEY, false);
|
||||
}
|
||||
|
||||
@SuppressLint("SharedPreferencesUse")
|
||||
public void setBundleDeltasEnabled(boolean enabled) {
|
||||
mPreferences.edit().putBoolean(PREFS_JS_BUNDLE_DELTAS_KEY, enabled).apply();
|
||||
}
|
||||
|
||||
@SuppressLint("SharedPreferencesUse")
|
||||
public boolean isBundleDeltasCppEnabled() {
|
||||
return mSupportsNativeDeltaClients
|
||||
&& mPreferences.getBoolean(PREFS_JS_BUNDLE_DELTAS_CPP_KEY, false);
|
||||
}
|
||||
|
||||
@SuppressLint("SharedPreferencesUse")
|
||||
public void setBundleDeltasCppEnabled(boolean enabled) {
|
||||
mPreferences.edit().putBoolean(PREFS_JS_BUNDLE_DELTAS_CPP_KEY, enabled).apply();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isNuclideJSDebugEnabled() {
|
||||
return ReactBuildConfig.IS_INTERNAL_BUILD && ReactBuildConfig.DEBUG;
|
||||
|
||||
@@ -102,7 +102,6 @@ public class DevServerHelper {
|
||||
|
||||
private enum BundleType {
|
||||
BUNDLE("bundle"),
|
||||
DELTA("delta"),
|
||||
MAP("map");
|
||||
|
||||
private final String mTypeID;
|
||||
@@ -397,8 +396,7 @@ public class DevServerHelper {
|
||||
File outputFile,
|
||||
String bundleURL,
|
||||
BundleDownloader.BundleInfo bundleInfo) {
|
||||
mBundleDownloader.downloadBundleFromURL(
|
||||
callback, outputFile, bundleURL, bundleInfo, getDeltaClientType());
|
||||
mBundleDownloader.downloadBundleFromURL(callback, outputFile, bundleURL, bundleInfo);
|
||||
}
|
||||
|
||||
public void downloadBundleFromURL(
|
||||
@@ -408,17 +406,7 @@ public class DevServerHelper {
|
||||
BundleDownloader.BundleInfo bundleInfo,
|
||||
Request.Builder requestBuilder) {
|
||||
mBundleDownloader.downloadBundleFromURL(
|
||||
callback, outputFile, bundleURL, bundleInfo, getDeltaClientType(), requestBuilder);
|
||||
}
|
||||
|
||||
private BundleDeltaClient.ClientType getDeltaClientType() {
|
||||
if (mSettings.isBundleDeltasCppEnabled()) {
|
||||
return BundleDeltaClient.ClientType.NATIVE;
|
||||
} else if (mSettings.isBundleDeltasEnabled()) {
|
||||
return BundleDeltaClient.ClientType.DEV_SUPPORT;
|
||||
} else {
|
||||
return BundleDeltaClient.ClientType.NONE;
|
||||
}
|
||||
callback, outputFile, bundleURL, bundleInfo, requestBuilder);
|
||||
}
|
||||
|
||||
/** @return the host to use when connecting to the bundle server from the host itself. */
|
||||
@@ -475,7 +463,7 @@ public class DevServerHelper {
|
||||
public String getDevServerBundleURL(final String jsModulePath) {
|
||||
return createBundleURL(
|
||||
jsModulePath,
|
||||
mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE,
|
||||
BundleType.BUNDLE,
|
||||
mSettings.getPackagerConnectionSettings().getDebugServerHost());
|
||||
}
|
||||
|
||||
@@ -652,8 +640,7 @@ public class DevServerHelper {
|
||||
}
|
||||
|
||||
public String getSourceUrl(String mainModuleName) {
|
||||
return createBundleURL(
|
||||
mainModuleName, mSettings.isBundleDeltasEnabled() ? BundleType.DELTA : BundleType.BUNDLE);
|
||||
return createBundleURL(mainModuleName, BundleType.BUNDLE);
|
||||
}
|
||||
|
||||
public String getJSBundleURLForRemoteDebugging(String mainModuleName) {
|
||||
|
||||
@@ -30,7 +30,6 @@ import com.facebook.react.bridge.CatalystInstance;
|
||||
import com.facebook.react.bridge.DefaultNativeModuleCallExceptionHandler;
|
||||
import com.facebook.react.bridge.JavaJSExecutor;
|
||||
import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.ReactMarker;
|
||||
import com.facebook.react.bridge.ReactMarkerConstants;
|
||||
@@ -1026,7 +1025,7 @@ public class DevSupportManagerImpl
|
||||
mDevServerHelper.downloadBundleFromURL(
|
||||
new DevBundleDownloadListener() {
|
||||
@Override
|
||||
public void onSuccess(final @Nullable NativeDeltaClient nativeDeltaClient) {
|
||||
public void onSuccess() {
|
||||
mDevLoadingViewController.hide();
|
||||
mDevLoadingViewVisible = false;
|
||||
synchronized (DevSupportManagerImpl.this) {
|
||||
@@ -1034,7 +1033,7 @@ public class DevSupportManagerImpl
|
||||
mBundleStatus.updateTimestamp = System.currentTimeMillis();
|
||||
}
|
||||
if (mBundleDownloadListener != null) {
|
||||
mBundleDownloadListener.onSuccess(nativeDeltaClient);
|
||||
mBundleDownloadListener.onSuccess();
|
||||
}
|
||||
UiThreadUtil.runOnUiThread(
|
||||
new Runnable() {
|
||||
@@ -1042,7 +1041,7 @@ public class DevSupportManagerImpl
|
||||
public void run() {
|
||||
ReactMarker.logMarker(
|
||||
ReactMarkerConstants.DOWNLOAD_END, bundleInfo.toJSONString());
|
||||
mReactInstanceManagerHelper.onJSBundleLoadedFromServer(nativeDeltaClient);
|
||||
mReactInstanceManagerHelper.onJSBundleLoadedFromServer();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+1
-2
@@ -10,7 +10,6 @@ import android.app.Activity;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.JavaJSExecutor;
|
||||
import com.facebook.react.bridge.JavaScriptExecutorFactory;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
|
||||
/**
|
||||
* Interface used by {@link DevSupportManager} for accessing some fields and methods of {@link
|
||||
@@ -22,7 +21,7 @@ public interface ReactInstanceManagerDevHelper {
|
||||
void onReloadWithJSDebugger(JavaJSExecutor.Factory proxyExecutorFactory);
|
||||
|
||||
/** Notify react instance manager about new JS bundle version downloaded from the server. */
|
||||
void onJSBundleLoadedFromServer(@Nullable NativeDeltaClient nativeDeltaClient);
|
||||
void onJSBundleLoadedFromServer();
|
||||
|
||||
/** Request to toggle the react element inspector. */
|
||||
void toggleElementInspector();
|
||||
|
||||
+1
-2
@@ -7,10 +7,9 @@
|
||||
package com.facebook.react.devsupport.interfaces;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.NativeDeltaClient;
|
||||
|
||||
public interface DevBundleDownloadListener {
|
||||
void onSuccess(@Nullable NativeDeltaClient nativeDeltaClient);
|
||||
void onSuccess();
|
||||
|
||||
void onProgress(@Nullable String status, @Nullable Integer done, @Nullable Integer total);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user