[tp] Fix surface flinger actual timeline flows

The current flow order is surfaceflinger => target app.

The correct order is the other way round.


Bug: b/287949714
Change-Id: I881680e5f429aac54587f0fc45f0b7c3774d5553
diff --git a/src/trace_processor/importers/proto/frame_timeline_event_parser.cc b/src/trace_processor/importers/proto/frame_timeline_event_parser.cc
index 9afec02..5ae343e 100644
--- a/src/trace_processor/importers/proto/frame_timeline_event_parser.cc
+++ b/src/trace_processor/importers/proto/frame_timeline_event_parser.cc
@@ -326,9 +326,9 @@
   auto range = display_token_to_surface_slice_.equal_range(token);
   if (opt_slice_id) {
     for (auto it = range.first; it != range.second; ++it) {
-      SliceId display_slice = *opt_slice_id;  // SurfaceFlinger
       SliceId surface_slice = it->second;     // App
-      context_->flow_tracker->InsertFlow(display_slice, surface_slice);
+      SliceId display_slice = *opt_slice_id;  // SurfaceFlinger
+      context_->flow_tracker->InsertFlow(surface_slice, display_slice);
     }
   }
   display_token_to_surface_slice_.erase(range.first, range.second);
diff --git a/src/trace_processor/metrics/sql/android/jank/relevant_slices.sql b/src/trace_processor/metrics/sql/android/jank/relevant_slices.sql
index da5951a..bd72bd2 100644
--- a/src/trace_processor/metrics/sql/android/jank/relevant_slices.sql
+++ b/src/trace_processor/metrics/sql/android/jank/relevant_slices.sql
@@ -176,9 +176,9 @@
   ON do_frame.upid = app_timeline.upid
     AND do_frame.vsync = CAST(app_timeline.name AS INTEGER)
 JOIN directly_connected_flow(app_timeline.id) flow
-  ON flow.slice_in = app_timeline.id
+  ON flow.slice_out = app_timeline.id
 JOIN actual_frame_timeline_slice sf_timeline
-  ON flow.slice_out = sf_timeline.id
+  ON flow.slice_in = sf_timeline.id
 JOIN android_jank_cuj_sf_process sf_process
   ON sf_timeline.upid = sf_process.upid
 -- In cases where there are multiple layers drawn we would have separate frame timeline