Merge "Uwb Hal: use fs::write instead of File::write" am: 995445a080
am: ccd01a2756
Original change: https://android-review.googlesource.com/c/platform/hardware/interfaces/+/2575093 Change-Id: I1a54e290d09397f402ead1d8dd5dbcba4d67f23d Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
9329fd19e0
1 changed files with 10 additions and 17 deletions
|
@ -6,8 +6,8 @@ use android_hardware_uwb::binder;
|
|||
use async_trait::async_trait;
|
||||
use binder::{Result, Strong};
|
||||
|
||||
use tokio::fs::File;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::fs::{self, File};
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
use std::os::fd::AsRawFd;
|
||||
|
@ -22,7 +22,6 @@ enum State {
|
|||
callbacks: Strong<dyn IUwbClientCallback>,
|
||||
#[allow(dead_code)]
|
||||
tasks: tokio::task::JoinSet<()>,
|
||||
write: File,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -65,17 +64,11 @@ impl IUwbChipAsyncServer for UwbChip {
|
|||
async fn open(&self, callbacks: &Strong<dyn IUwbClientCallback>) -> Result<()> {
|
||||
log::debug!("open: {:?}", &self.path);
|
||||
|
||||
let serial = File::open(&self.path)
|
||||
let mut serial = File::open(&self.path)
|
||||
.await
|
||||
.and_then(makeraw)
|
||||
.map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?;
|
||||
|
||||
let mut read = serial
|
||||
.try_clone()
|
||||
.await
|
||||
.map_err(|_| binder::StatusCode::UNKNOWN_ERROR)?;
|
||||
let write = serial;
|
||||
|
||||
let mut state = self.state.lock().await;
|
||||
|
||||
if let State::Closed = *state {
|
||||
|
@ -88,14 +81,16 @@ impl IUwbChipAsyncServer for UwbChip {
|
|||
const UWB_HEADER_SIZE: usize = 4;
|
||||
|
||||
let mut buffer = vec![0; UWB_HEADER_SIZE];
|
||||
read.read_exact(&mut buffer[0..UWB_HEADER_SIZE])
|
||||
serial
|
||||
.read_exact(&mut buffer[0..UWB_HEADER_SIZE])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let length = buffer[3] as usize + UWB_HEADER_SIZE;
|
||||
|
||||
buffer.resize(length, 0);
|
||||
read.read_exact(&mut buffer[UWB_HEADER_SIZE..length])
|
||||
serial
|
||||
.read_exact(&mut buffer[UWB_HEADER_SIZE..length])
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
@ -108,7 +103,6 @@ impl IUwbChipAsyncServer for UwbChip {
|
|||
*state = State::Opened {
|
||||
callbacks: callbacks.clone(),
|
||||
tasks,
|
||||
write,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
@ -155,11 +149,10 @@ impl IUwbChipAsyncServer for UwbChip {
|
|||
async fn sendUciMessage(&self, data: &[u8]) -> Result<i32> {
|
||||
log::debug!("sendUciMessage");
|
||||
|
||||
if let State::Opened { write, .. } = &mut *self.state.lock().await {
|
||||
write
|
||||
.write(data)
|
||||
if let State::Opened { .. } = &mut *self.state.lock().await {
|
||||
fs::write(&self.path, data)
|
||||
.await
|
||||
.map(|written| written as i32)
|
||||
.map(|_| data.len() as i32)
|
||||
.map_err(|_| binder::StatusCode::UNKNOWN_ERROR.into())
|
||||
} else {
|
||||
Err(binder::ExceptionCode::ILLEGAL_STATE.into())
|
||||
|
|
Loading…
Reference in a new issue