adb_client icon indicating copy to clipboard operation
adb_client copied to clipboard

Hi, i need help with adb_client ,thanks

Open xs23933 opened this issue 3 years ago • 5 comments

let connexion = AdbTcpConnexion::new();
        let callback = |device:adb_client::Device| {
            println!("{}", device);
            Ok(())
        };
        println!("Live list of devices attached");
        connexion.track_devices(callback)?;

system Env:

System: Macos 12.3.1
rust version: 1.59.0
Android Debug Bridge version 1.0.41

impl TryFrom<Vec<u8>> for Device {
    type Error = RustADBError;

    // TODO: Prevent regex compilation every call to try_from()
    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
        // Optional final '\n' is used to match TrackDevices inputs
        let parse_regex = Regex::new("^(\\w+)\t(\\w+)\n?$")?;

        let groups = match parse_regex.captures(&value).unwrap() // <----------- device.rs:29:51
        Ok(Device {
            identifier: String::from_utf8(
                groups
                    .get(1)
                    .ok_or(RustADBError::RegexParsingError)?
                    .as_bytes()
                    .to_vec(),
            )?,
            state: DeviceState::from_str(&String::from_utf8(
                groups
                    .get(2)
                    .ok_or(RustADBError::RegexParsingError)?
                    .as_bytes()
                    .to_vec(),
            )?)?,
        })
    }
}

error output:

Live list of devices attached
thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /Users/x/.cargo/registry/src/rsproxy.cn-8f6827c7555bfaf8/adb_client-0.2.0/src/models/device.rs:29:51
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

xs23933 avatar May 01 '22 01:05 xs23933

regex change to

        // match space or \t
        let parse_regex = Regex::new("^(\\w+)[ \t]+(\\w+)\n?$")?;

xs23933 avatar May 01 '22 02:05 xs23933

Can you provide me the output of your adb devices command ?

cocool97 avatar May 01 '22 07:05 cocool97

I met same problem, my output is something like this: 12345678 device product:123 model:123 device:123 transport_id:1

JinkeJ avatar Oct 08 '24 02:10 JinkeJ

I met same problem, my output is something like this: 12345678 device product:123 model:123 device:123 transport_id:1

replace:

            usb: String::from_utf8(
                groups
                    .name("usb1")
                    .or_else(|| groups.name("usb2"))
                    .ok_or(RustADBError::RegexParsingError)?
                    .as_bytes()
                    .to_vec(),
            )?,

with

            usb: match groups.name("usb1") {
                None => match groups.name("usb2") {
                    None => "Unk".to_string(),
                    Some(usb) => String::from_utf8(usb.as_bytes().to_vec())?,
                },
                Some(usb) => String::from_utf8(usb.as_bytes().to_vec())?,
            },

JinkeJ avatar Oct 08 '24 03:10 JinkeJ

Ok thanks for the report, I re-open. Feel free to open a PR for submitting this fix 😉

cocool97 avatar Oct 08 '24 07:10 cocool97

Fix in #37 !

cocool97 avatar Oct 12 '24 11:10 cocool97