-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The 1st example crashes when permission request is accepted: ActivityManager: freezing 4327 com.example.android_usb_cdc_test
#5
Comments
Thank you for opening the issue. The exception message itself can't tell anything but an existing problem which occurs even if the permission request is accepted and the device can be opened. Starting from Android API Level 29,
Please post your test program here. Tell me if you have called |
Okay, now that I deleted another app I had on device that was taking USB_ATTACHED intents it seems to get the permission popup.
use android_activity::{AndroidApp, MainEvent, PollEvent};
use android_usbser::usb;
use log::{info, warn};
use std::time::Duration;
#[no_mangle]
fn android_main(app: AndroidApp) {
android_logger::init_once(
android_logger::Config::default()
.with_max_level(log::LevelFilter::Info)
.with_tag("android_usb_cdc_test"),
);
let mut startup_dev = usb::check_attached_intent().ok();
let mut watcher = usb::watch_devices().unwrap();
let mut perm_req: Option<usb::PermissionRequest> = None;
let mut on_destroy = false;
loop {
info!("Polling events...");
app.poll_events(
Some(Duration::from_secs(1)), // timeout
|event| match event {
PollEvent::Main(MainEvent::Start) => {
info!("Main Start.");
}
PollEvent::Main(MainEvent::Resume { loader: _, .. }) => {
info!("Main Resume.");
}
PollEvent::Main(MainEvent::Pause) => {
info!("Main Pause.");
}
PollEvent::Main(MainEvent::Stop) => {
info!("Main Stop.");
}
PollEvent::Main(MainEvent::Destroy) => {
info!("Main Destroy.");
on_destroy = true;
}
_ => (),
},
);
if on_destroy {
return;
}
let dev_info = if let Some(dev) = startup_dev.take() {
info!("Got device from startup intent.");
if !dev.has_permission().unwrap() {
warn!("Unexpected: no permission.");
continue;
}
dev
} else if let Some(req) = perm_req.as_ref() {
if !req.responsed() {
continue;
}
let req = perm_req.take().expect("Unexpected: permission request is None.");
let dev = req.device_info().clone();
// `responsed()` returned true, so unwrap here.
if !req.take_response().expect("Unexpected: response is None.") {
// boolean response
info!("Permission denied.");
continue;
}
dev
} else {
match watcher.take_next() {
None => continue,
Some(usb::HotplugEvent::Connected(dev)) => {
info!("🟢 Device connected ({}).", dev.path_name());
match dev.has_permission() {
Ok(true) => {
info!("Permission granted! Device is ready to use.");
info!("{:?}", dev);
dev
},
Ok(false) => {
perm_req = dev.request_permission().expect("Unexpected: failed to request permission.");
if perm_req.is_some() {
info!("Performing permission request...");
}
continue;
}
Err(e) => {
warn!("Unexpected: failed to check permission: {:?}", e);
continue;
}
}
}
Some(usb::HotplugEvent::Disconnected(dev)) => {
info!("🔴 Device disconnected ({}).", dev.path_name());
continue;
}
}
};
let Ok(conn) = dev_info.open_device() else {
warn!("Unexpected: failed to open the device.");
continue;
};
info!("Opened, printing USB configurations:");
for conf in conn.configurations() {
info!("{:#?}", conf);
}
std::thread::sleep(Duration::from_secs(1));
info!("Closing the device.");
}
}
|
Ok maybe its the build I'm using... if you're curious its for using Pixel Tablet as an Android Automotive dev device. Here is a full logcat (only slightly redacted non-relevant items) for a few seconds leading up (when I plug in and hit Ok to permission): The app I mentioned taking precedence is
|
Sorry, the CP21xx serial adapter isn't supported yet. Actually, I'm looking for new maintainers who are willing to support non-CDC serial devices (probably according to https://github.com/mik3y/usb-serial-for-android). The ownership of this repository may be transferred as well. With the problem of the USB host API helper for For now, I don't know if your test application crashed before it's freezed (or during unfreezing?); my experience in Android development is really limited, especially with those newest Android versions in which application freezer has been introduced and changed. Self-note: I've found |
Ok I was able to get "full control" on my build.. but yes I see I overlooked the class of USB you support. I'd like to help add serial devices if I can - just new to this area of Android as well. The best solution I've found is https://github.com/kai-morich/SimpleUsbTerminal (java - based on mk3y's you mentioned). But the flow should be same as you have now up until last steps where I'm crashing right? |
Yes, it's a problem of the Android USB host API helper for I may have a new phone (with Android 13 or above) in the future, but you can help locate this problem if you are able to test it now (see my last comment). |
ActivityManager: freezing 4327 com.example.android_usb_cdc_test
I've fixed a bug and released a new version of my crate; it now works under a fresh Android 13 environment. Please report if any other problem occurs. |
Sorry, I will close this issue if you can't reproduce it with the new version 0.2.2. |
Let me test I have a device I can use now |
@wuwbobo2021 which peripheral device do you usually test with? |
I've tested it with an STM32F103 VCP device, based on Some other firmwares can be found for Arduino devices. I'm planning to add support for FT232 and Prolific adapters, but not soon. Please close this issue and open another issue "Add support for xxx serial adapter(s)" if the problem described here has been solved. |
Really, really cool repo! But can't seem to get it to actually connect to device because of a SecurityException.
I am using this as my Cargo.toml to run it
Tired several Android SDK versions between 29-35. I also tried to use your PR branch on
cargo-apk
library (rust-mobile/cargo-apk#67), and tried with and withoutvalue = "true"
.The text was updated successfully, but these errors were encountered: