• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2025, The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 use crate::Transport;
16 use liberror::Result;
17 
18 /// Trait for a device-local fastboot-like session.
19 pub trait LocalSession {
20     /// Updates the context of the local session.
21     /// Polls inputs, updates graphics, and so forth.
update(&mut self, buf: &mut [u8]) -> Result<usize>22     async fn update(&mut self, buf: &mut [u8]) -> Result<usize>;
23 
24     /// This is a hack to allow test structures to capture outgoing packets.
process_outgoing_packet(&mut self, _: &[u8])25     async fn process_outgoing_packet(&mut self, _: &[u8]) {}
26 }
27 
28 impl<T: LocalSession> Transport for T {
receive_packet(&mut self, out: &mut [u8]) -> Result<usize>29     async fn receive_packet(&mut self, out: &mut [u8]) -> Result<usize> {
30         self.update(out).await
31     }
32 
send_packet(&mut self, buf: &[u8]) -> Result<()>33     async fn send_packet(&mut self, buf: &[u8]) -> Result<()> {
34         self.process_outgoing_packet(buf).await;
35         Ok(())
36     }
37 }
38