12
12
async_trait:: async_trait,
13
13
async_utils:: hanging_get:: client:: HangingGetStream ,
14
14
fidl:: endpoints:: create_proxy,
15
+ fidl_fuchsia_input_interaction_observation as interaction_observation,
15
16
fidl_fuchsia_ui_pointerinjector as pointerinjector,
16
17
fidl_fuchsia_ui_pointerinjector_configuration as pointerinjector_config,
17
18
fuchsia_component:: client:: connect_to_protocol,
@@ -46,6 +47,9 @@ pub struct TouchInjectorHandler {
46
47
47
48
/// The FIDL proxy used to get configuration details for pointer injection.
48
49
configuration_proxy : pointerinjector_config:: SetupProxy ,
50
+
51
+ /// The FIDL proxy used to report touch activity to the activity service.
52
+ aggregator_proxy : interaction_observation:: AggregatorProxy ,
49
53
}
50
54
51
55
#[ derive( Debug ) ]
@@ -88,6 +92,11 @@ impl UnhandledInputHandler for TouchInjectorHandler {
88
92
fx_log_err ! ( "{}" , e) ;
89
93
}
90
94
95
+ // Report the event to the Activity Service.
96
+ if let Err ( e) = self . report_touch_activity ( event_time) . await {
97
+ fx_log_err ! ( "report_touch_activity failed: {}" , e) ;
98
+ }
99
+
91
100
// Consume the input event.
92
101
vec ! [ input_device:: InputEvent :: from( unhandled_input_event) . into_handled( ) ]
93
102
}
@@ -111,8 +120,15 @@ impl TouchInjectorHandler {
111
120
pub async fn new ( display_size : Size ) -> Result < Rc < Self > , Error > {
112
121
let configuration_proxy = connect_to_protocol :: < pointerinjector_config:: SetupMarker > ( ) ?;
113
122
let injector_registry_proxy = connect_to_protocol :: < pointerinjector:: RegistryMarker > ( ) ?;
123
+ let aggregator_proxy = connect_to_protocol :: < interaction_observation:: AggregatorMarker > ( ) ?;
114
124
115
- Self :: new_handler ( configuration_proxy, injector_registry_proxy, display_size) . await
125
+ Self :: new_handler (
126
+ aggregator_proxy,
127
+ configuration_proxy,
128
+ injector_registry_proxy,
129
+ display_size,
130
+ )
131
+ . await
116
132
}
117
133
118
134
/// Creates a new touch handler that holds touch pointer injectors.
@@ -133,8 +149,15 @@ impl TouchInjectorHandler {
133
149
configuration_proxy : pointerinjector_config:: SetupProxy ,
134
150
display_size : Size ,
135
151
) -> Result < Rc < Self > , Error > {
152
+ let aggregator_proxy = connect_to_protocol :: < interaction_observation:: AggregatorMarker > ( ) ?;
136
153
let injector_registry_proxy = connect_to_protocol :: < pointerinjector:: RegistryMarker > ( ) ?;
137
- Self :: new_handler ( configuration_proxy, injector_registry_proxy, display_size) . await
154
+ Self :: new_handler (
155
+ aggregator_proxy,
156
+ configuration_proxy,
157
+ injector_registry_proxy,
158
+ display_size,
159
+ )
160
+ . await
138
161
}
139
162
140
163
/// Creates a new touch handler that holds touch pointer injectors.
@@ -144,6 +167,7 @@ impl TouchInjectorHandler {
144
167
/// fasync::Task::local(handler.clone().watch_viewport()).detach();
145
168
///
146
169
/// # Parameters
170
+ /// - `aggregator_proxy`: A proxy used to report to the activity service
147
171
/// - `configuration_proxy`: A proxy used to get configuration details for pointer
148
172
/// injection.
149
173
/// - `injector_registry_proxy`: A proxy used to register new pointer injectors. If
@@ -153,6 +177,7 @@ impl TouchInjectorHandler {
153
177
/// # Errors
154
178
/// If unable to get injection view refs from `configuration_proxy`.
155
179
async fn new_handler (
180
+ aggregator_proxy : interaction_observation:: AggregatorProxy ,
156
181
configuration_proxy : pointerinjector_config:: SetupProxy ,
157
182
injector_registry_proxy : pointerinjector:: RegistryProxy ,
158
183
display_size : Size ,
@@ -167,6 +192,7 @@ impl TouchInjectorHandler {
167
192
display_size,
168
193
injector_registry_proxy,
169
194
configuration_proxy,
195
+ aggregator_proxy,
170
196
} ) ;
171
197
172
198
Ok ( handler)
@@ -365,6 +391,11 @@ impl TouchInjectorHandler {
365
391
}
366
392
}
367
393
394
+ /// Reports the given event_time to the activity service.
395
+ async fn report_touch_activity ( & self , event_time : zx:: Time ) -> Result < ( ) , fidl:: Error > {
396
+ self . aggregator_proxy . report_discrete_activity ( event_time. into_nanos ( ) ) . await
397
+ }
398
+
368
399
/// Watches for viewport updates from the scene manager.
369
400
pub async fn watch_viewport ( self : Rc < Self > ) {
370
401
let configuration_proxy = self . configuration_proxy . clone ( ) ;
@@ -511,6 +542,27 @@ mod tests {
511
542
}
512
543
}
513
544
545
+ /// Handles |fidl_fuchsia_interaction_observation::AggregatorRequest|s.
546
+ async fn handle_aggregator_request_stream (
547
+ mut stream : interaction_observation:: AggregatorRequestStream ,
548
+ expected_time : i64 ,
549
+ ) {
550
+ if let Some ( request) = stream. next ( ) . await {
551
+ match request {
552
+ Ok ( interaction_observation:: AggregatorRequest :: ReportDiscreteActivity {
553
+ event_time,
554
+ responder,
555
+ } ) => {
556
+ assert_eq ! ( event_time, expected_time) ;
557
+ responder. send ( ) . expect ( "failed to respond" ) ;
558
+ }
559
+ other => panic ! ( "expected aggregator report request, but got {:?}" , other) ,
560
+ } ;
561
+ } else {
562
+ panic ! ( "AggregatorRequestStream failed." ) ;
563
+ }
564
+ }
565
+
514
566
// Creates a |pointerinjector::Viewport|.
515
567
fn create_viewport ( min : f32 , max : f32 ) -> pointerinjector:: Viewport {
516
568
pointerinjector:: Viewport {
@@ -527,13 +579,17 @@ mod tests {
527
579
let mut exec = fasync:: TestExecutor :: new ( ) . expect ( "executor needed" ) ;
528
580
529
581
// Create touch handler.
582
+ let ( aggregator_proxy, _) =
583
+ fidl:: endpoints:: create_proxy_and_stream :: < interaction_observation:: AggregatorMarker > ( )
584
+ . expect ( "Failed to create interaction observation Aggregator proxy and stream." ) ;
530
585
let ( configuration_proxy, mut configuration_request_stream) =
531
586
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector_config:: SetupMarker > ( )
532
587
. expect ( "Failed to create pointerinjector Setup proxy and stream." ) ;
533
588
let ( injector_registry_proxy, _injector_registry_request_stream) =
534
589
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector:: RegistryMarker > ( )
535
590
. expect ( "Failed to create pointerinjector Registry proxy and stream." ) ;
536
591
let touch_handler_fut = TouchInjectorHandler :: new_handler (
592
+ aggregator_proxy,
537
593
configuration_proxy,
538
594
injector_registry_proxy,
539
595
Size { width : DISPLAY_WIDTH , height : DISPLAY_HEIGHT } ,
@@ -632,6 +688,9 @@ mod tests {
632
688
let mut exec = fasync:: TestExecutor :: new ( ) . expect ( "executor needed" ) ;
633
689
634
690
// Set up fidl streams.
691
+ let ( aggregator_proxy, _) =
692
+ fidl:: endpoints:: create_proxy_and_stream :: < interaction_observation:: AggregatorMarker > ( )
693
+ . expect ( "Failed to create interaction observation Aggregator proxy and stream." ) ;
635
694
let ( configuration_proxy, mut configuration_request_stream) =
636
695
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector_config:: SetupMarker > ( )
637
696
. expect ( "Failed to create pointerinjector Setup proxy and stream." ) ;
@@ -643,6 +702,7 @@ mod tests {
643
702
644
703
// Create TouchInjectorHandler.
645
704
let touch_handler_fut = TouchInjectorHandler :: new_handler (
705
+ aggregator_proxy,
646
706
configuration_proxy,
647
707
injector_registry_proxy,
648
708
Size { width : DISPLAY_WIDTH , height : DISPLAY_HEIGHT } ,
@@ -685,13 +745,17 @@ mod tests {
685
745
let mut exec = fasync:: TestExecutor :: new ( ) . expect ( "executor needed" ) ;
686
746
687
747
// Create touch handler.
748
+ let ( aggregator_proxy, aggregator_request_stream) =
749
+ fidl:: endpoints:: create_proxy_and_stream :: < interaction_observation:: AggregatorMarker > ( )
750
+ . expect ( "Failed to create interaction observation Aggregator proxy and stream." ) ;
688
751
let ( configuration_proxy, mut configuration_request_stream) =
689
752
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector_config:: SetupMarker > ( )
690
753
. expect ( "Failed to create pointerinjector Setup proxy and stream." ) ;
691
754
let ( injector_registry_proxy, _injector_registry_request_stream) =
692
755
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector:: RegistryMarker > ( )
693
756
. expect ( "Failed to create pointerinjector Registry proxy and stream." ) ;
694
757
let touch_handler_fut = TouchInjectorHandler :: new_handler (
758
+ aggregator_proxy,
695
759
configuration_proxy,
696
760
injector_registry_proxy,
697
761
Size { width : DISPLAY_WIDTH , height : DISPLAY_HEIGHT } ,
@@ -769,8 +833,12 @@ mod tests {
769
833
// matches `expected_event`.
770
834
let device_fut =
771
835
handle_device_request_stream ( injector_device_request_stream, expected_event) ;
772
- let ( handle_result, _) =
773
- exec. run_singlethreaded ( futures:: future:: join ( handle_event_fut, device_fut) ) ;
836
+ let aggregator_fut =
837
+ handle_aggregator_request_stream ( aggregator_request_stream, event_time. into_nanos ( ) ) ;
838
+ let ( handle_result, _) = exec. run_singlethreaded ( futures:: future:: join (
839
+ handle_event_fut,
840
+ futures:: future:: join ( device_fut, aggregator_fut) ,
841
+ ) ) ;
774
842
775
843
// No unhandled events.
776
844
assert_matches ! (
@@ -785,13 +853,17 @@ mod tests {
785
853
let mut exec = fasync:: TestExecutor :: new ( ) . expect ( "executor needed" ) ;
786
854
787
855
// Create touch handler.
856
+ let ( aggregator_proxy, _) =
857
+ fidl:: endpoints:: create_proxy_and_stream :: < interaction_observation:: AggregatorMarker > ( )
858
+ . expect ( "Failed to create interaction observation Aggregator proxy and stream." ) ;
788
859
let ( configuration_proxy, mut configuration_request_stream) =
789
860
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector_config:: SetupMarker > ( )
790
861
. expect ( "Failed to create pointerinjector Setup proxy and stream." ) ;
791
862
let ( injector_registry_proxy, mut injector_registry_request_stream) =
792
863
fidl:: endpoints:: create_proxy_and_stream :: < pointerinjector:: RegistryMarker > ( )
793
864
. expect ( "Failed to create pointerinjector Registry proxy and stream." ) ;
794
865
let touch_handler_fut = TouchInjectorHandler :: new_handler (
866
+ aggregator_proxy,
795
867
configuration_proxy,
796
868
injector_registry_proxy,
797
869
Size { width : DISPLAY_WIDTH , height : DISPLAY_HEIGHT } ,
0 commit comments