|
35 | 35 | import io.flutter.ObservatoryConnector;
|
36 | 36 | import io.flutter.bazel.Workspace;
|
37 | 37 | import io.flutter.bazel.WorkspaceCache;
|
| 38 | +import io.flutter.dart.DtdRequest; |
38 | 39 | import io.flutter.dart.DtdUtils;
|
39 | 40 | import io.flutter.dart.FlutterDartAnalysisServer;
|
40 | 41 | import io.flutter.logging.FlutterConsoleLogManager;
|
@@ -686,8 +687,8 @@ class FlutterAppDaemonEventListener implements DaemonEvent.Listener {
|
686 | 687 |
|
687 | 688 | private final @NotNull FlutterApp app;
|
688 | 689 | private final @NotNull ProgressHelper progress;
|
689 |
| - private String appVmServiceUri; |
690 |
| - private final DtdUtils dtdUtils = new DtdUtils(); |
| 690 | + private @Nullable String appVmServiceUri; |
| 691 | + private static final @NotNull DtdUtils dtdUtils = new DtdUtils(); |
691 | 692 |
|
692 | 693 |
|
693 | 694 | FlutterAppDaemonEventListener(@NotNull FlutterApp app, @NotNull Project project) {
|
@@ -751,7 +752,7 @@ public void onAppDebugPort(@NotNull DaemonEvent.AppDebugPort debugInfo) {
|
751 | 752 | final JsonObject params = new JsonObject();
|
752 | 753 | params.addProperty("uri", debugInfo.wsUri);
|
753 | 754 | params.addProperty("name", debugInfo.appId);
|
754 |
| - sendDtdRequest("ConnectedApp.registerVmService", params); |
| 755 | + sendDtdRequest(DtdRequest.REGISTER_VM_SERVICE, params); |
755 | 756 |
|
756 | 757 | // Print the conneciton info to the console.
|
757 | 758 | final ConsoleView console = app.getConsole();
|
@@ -821,27 +822,30 @@ public void onAppStopped(@NotNull DaemonEvent.AppStopped stopped) {
|
821 | 822 |
|
822 | 823 | final JsonObject params = new JsonObject();
|
823 | 824 | params.addProperty("uri", appVmServiceUri);
|
824 |
| - sendDtdRequest("ConnectedApp.unregisterVmService", params); |
| 825 | + sendDtdRequest(DtdRequest.UNREGISTER_VM_SERVICE, params); |
825 | 826 |
|
826 | 827 | progress.cancel();
|
827 | 828 | app.getProcessHandler().destroyProcess();
|
828 | 829 | }
|
829 | 830 |
|
830 |
| - private void sendDtdRequest(@NotNull String requestName, @NotNull JsonObject params) { |
| 831 | + private void sendDtdRequest(@NotNull DtdRequest dtdRequest, @NotNull JsonObject params) { |
831 | 832 | try {
|
832 | 833 | final DartToolingDaemonService dtdService = dtdUtils.readyDtdService(app.getProject()).get();
|
833 | 834 | if (dtdService == null) {
|
834 | 835 | return;
|
835 | 836 | }
|
836 |
| - // This removes secret from params when we print out after receiving response. |
| 837 | + // Requests for this class require sending a secret to DTD to verify that this is a trusted client; however, we don't want to log the |
| 838 | + // secret. The DTD service class in the Dart plugin automatically adds the secret to the params, so without making an initial copy of |
| 839 | + // the input params, the secret would be logged. |
| 840 | + // TODO(helin24 in Dart plugin): Add secret to a copy of the request params. |
837 | 841 | JsonObject initialParams = params.deepCopy();
|
838 |
| - dtdService.sendRequest(requestName, params, true, object -> { |
| 842 | + dtdService.sendRequest(dtdRequest.type, params, true, object -> { |
839 | 843 | final JsonObject result = object.getAsJsonObject("result");
|
840 | 844 | final JsonPrimitive type = result != null ? result.getAsJsonPrimitive("type") : null;
|
841 | 845 | if (type != null && "Success".equals(type.getAsString())) {
|
842 |
| - LOG.info("Successful request " + requestName + " to DTD with params: " + initialParams); |
| 846 | + LOG.info("Successful request " + dtdRequest.type + " to DTD with params: " + initialParams); |
843 | 847 | } else {
|
844 |
| - LOG.warn("Failed request " + requestName + "to DTD with params: " + initialParams); |
| 848 | + LOG.warn("Failed request " + dtdRequest.type + "to DTD with params: " + initialParams); |
845 | 849 | LOG.warn("Result: " + result);
|
846 | 850 | }
|
847 | 851 | });
|
|
0 commit comments