|
31 | 31 | import android.content.pm.PackageInfo;
|
32 | 32 | import android.content.pm.PackageManager;
|
33 | 33 | import android.hardware.SensorManager;
|
| 34 | +import android.net.Uri; |
| 35 | +import android.os.AsyncTask; |
34 | 36 | import android.view.WindowManager;
|
35 | 37 | import android.widget.Toast;
|
36 | 38 |
|
|
50 | 52 | import com.facebook.react.devsupport.StackTraceHelper.StackFrame;
|
51 | 53 | import com.facebook.react.modules.debug.DeveloperSettings;
|
52 | 54 |
|
| 55 | +import okhttp3.MediaType; |
| 56 | +import okhttp3.OkHttpClient; |
| 57 | +import okhttp3.Request; |
| 58 | +import okhttp3.RequestBody; |
| 59 | + |
53 | 60 | /**
|
54 | 61 | * Interface for accessing and interacting with development features. Following features
|
55 | 62 | * are supported through this manager class:
|
@@ -114,6 +121,40 @@ private static enum ErrorType {
|
114 | 121 | private int mLastErrorCookie = 0;
|
115 | 122 | private @Nullable ErrorType mLastErrorType;
|
116 | 123 |
|
| 124 | + |
| 125 | + private static class JscProfileTask extends AsyncTask<String, Void, Void> { |
| 126 | + private static final MediaType JSON = |
| 127 | + MediaType.parse("application/json; charset=utf-8"); |
| 128 | + |
| 129 | + private final String mSourceUrl; |
| 130 | + |
| 131 | + private JscProfileTask(String sourceUrl) { |
| 132 | + mSourceUrl = sourceUrl; |
| 133 | + } |
| 134 | + |
| 135 | + @Override |
| 136 | + protected Void doInBackground(String... jsonData) { |
| 137 | + try { |
| 138 | + String jscProfileUrl = |
| 139 | + Uri.parse(mSourceUrl).buildUpon() |
| 140 | + .path("/jsc-profile") |
| 141 | + .query(null) |
| 142 | + .build() |
| 143 | + .toString(); |
| 144 | + OkHttpClient client = new OkHttpClient(); |
| 145 | + for (String json: jsonData) { |
| 146 | + RequestBody body = RequestBody.create(JSON, json); |
| 147 | + Request request = |
| 148 | + new Request.Builder().url(jscProfileUrl).post(body).build(); |
| 149 | + client.newCall(request).execute(); |
| 150 | + } |
| 151 | + } catch (IOException e) { |
| 152 | + FLog.e(ReactConstants.TAG, "Failed not talk to server", e); |
| 153 | + } |
| 154 | + return null; |
| 155 | + } |
| 156 | + } |
| 157 | + |
117 | 158 | public DevSupportManagerImpl(
|
118 | 159 | Context applicationContext,
|
119 | 160 | ReactInstanceDevCommandsHandler reactInstanceCommandsHandler,
|
@@ -389,6 +430,11 @@ public void onOptionSelected() {
|
389 | 430 | ? "Started JSC Sampling Profiler"
|
390 | 431 | : "Stopped JSC Sampling Profiler",
|
391 | 432 | Toast.LENGTH_LONG).show();
|
| 433 | + if (result != null) { |
| 434 | + new JscProfileTask(getSourceUrl()).executeOnExecutor( |
| 435 | + AsyncTask.THREAD_POOL_EXECUTOR, |
| 436 | + result); |
| 437 | + } |
392 | 438 | }
|
393 | 439 | } catch (JSCSamplingProfiler.ProfilerException e) {
|
394 | 440 | showNewJavaError(e.getMessage(), e);
|
|
0 commit comments