Fix crash in adsmanager login by nolonger assuming only one react context exists at once
Reviewed By: lexs Differential Revision: D3252624 fb-gh-sync-id: e1d1c914be4e0caab953478f12441b440bd1f894 fbshipit-source-id: e1d1c914be4e0caab953478f12441b440bd1f894
This commit is contained in:
parent
34ec6a91a9
commit
0a7a228fbb
|
@ -16,6 +16,7 @@ import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
@ -310,12 +311,14 @@ public class DevSupportManagerImpl implements DevSupportManager {
|
||||||
@Override
|
@Override
|
||||||
public void onOptionSelected() {
|
public void onOptionSelected() {
|
||||||
try {
|
try {
|
||||||
String heapDumpPath = mApplicationContext.getCacheDir() + "/heapdump.json";
|
String heapDumpPath = mApplicationContext.getCacheDir().getPath();
|
||||||
JSCHeapCapture.captureHeap(heapDumpPath, 60000);
|
List<String> captureFiles = JSCHeapCapture.captureHeap(heapDumpPath, 60000);
|
||||||
Toast.makeText(
|
for (String captureFile : captureFiles) {
|
||||||
mCurrentContext,
|
Toast.makeText(
|
||||||
"Heap captured to " + heapDumpPath,
|
mCurrentContext,
|
||||||
Toast.LENGTH_LONG).show();
|
"Heap captured to " + captureFile,
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
} catch (JSCHeapCapture.CaptureException e) {
|
} catch (JSCHeapCapture.CaptureException e) {
|
||||||
showNewJavaError(e.getMessage(), e);
|
showNewJavaError(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,11 @@ package com.facebook.react.devsupport;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.facebook.react.bridge.JavaScriptModule;
|
import com.facebook.react.bridge.JavaScriptModule;
|
||||||
import com.facebook.react.bridge.ReactApplicationContext;
|
import com.facebook.react.bridge.ReactApplicationContext;
|
||||||
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
||||||
|
@ -33,28 +38,41 @@ public class JSCHeapCapture extends ReactContextBaseJavaModule {
|
||||||
private int mOperationToken;
|
private int mOperationToken;
|
||||||
private @Nullable String mOperationError;
|
private @Nullable String mOperationError;
|
||||||
|
|
||||||
private static @Nullable JSCHeapCapture sJSCHeapCapture = null;
|
private static final HashSet<JSCHeapCapture> sRegisteredDumpers = new HashSet<>();
|
||||||
|
|
||||||
private static synchronized void registerHeapCapture(JSCHeapCapture dumper) {
|
private static synchronized void registerHeapCapture(JSCHeapCapture dumper) {
|
||||||
if (sJSCHeapCapture != null) {
|
if (sRegisteredDumpers.contains(dumper)) {
|
||||||
throw new RuntimeException(
|
throw new RuntimeException(
|
||||||
"JSCHeapCapture already registered. Are you running more than one JSC?");
|
"a JSCHeapCapture registered more than once");
|
||||||
}
|
}
|
||||||
sJSCHeapCapture = dumper;
|
sRegisteredDumpers.add(dumper);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static synchronized void unregisterHeapCapture(JSCHeapCapture dumper) {
|
private static synchronized void unregisterHeapCapture(JSCHeapCapture dumper) {
|
||||||
if (sJSCHeapCapture != dumper) {
|
sRegisteredDumpers.remove(dumper);
|
||||||
throw new RuntimeException("Can't unregister JSCHeapCapture that is not registered.");
|
|
||||||
}
|
|
||||||
sJSCHeapCapture = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static synchronized void captureHeap(String path, long timeout) throws CaptureException {
|
public static synchronized List<String> captureHeap(String path, long timeout)
|
||||||
if (sJSCHeapCapture == null) {
|
throws CaptureException {
|
||||||
throw new CaptureException("No JSC registered.");
|
LinkedList<String> captureFiles = new LinkedList<>();
|
||||||
|
if (sRegisteredDumpers.isEmpty()) {
|
||||||
|
throw new CaptureException("No JSC registered");
|
||||||
}
|
}
|
||||||
sJSCHeapCapture.captureHeapHelper(path, timeout);
|
|
||||||
|
int disambiguate = 0;
|
||||||
|
File f = new File(path + "/capture" + Integer.toString(disambiguate) + ".json");
|
||||||
|
while (f.delete()) {
|
||||||
|
disambiguate++;
|
||||||
|
f = new File(path + "/capture" + Integer.toString(disambiguate) + ".json");
|
||||||
|
}
|
||||||
|
|
||||||
|
disambiguate = 0;
|
||||||
|
for (JSCHeapCapture dumper : sRegisteredDumpers) {
|
||||||
|
String file = path + "/capture" + Integer.toString(disambiguate) + ".json";
|
||||||
|
dumper.captureHeapHelper(file, timeout);
|
||||||
|
captureFiles.add(file);
|
||||||
|
}
|
||||||
|
return captureFiles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSCHeapCapture(ReactApplicationContext reactContext) {
|
public JSCHeapCapture(ReactApplicationContext reactContext) {
|
||||||
|
|
Loading…
Reference in New Issue