fastboot: Allow fastboot to asynchronously differentiate between fastboot and fastbootd.

It's not possible to programmatically determine which fastboot mode a
device is in, without sending a getvar:is-userspace query. Unfortunately
this is not possible asynchronously, and may interrupt other queries
being processed.

This patch changes fastbootd's USB interface name to "fastbootd". Note
that tools use the protocol number/class and not this string, so it
should be safe to extend. When using "fastboot devices", the interface
name is now listed if set. Note that currently only the Linux version of
the fastboot tool is capable of reading the interface name.

Bug: 156966319
Test: fastboot devices on Linux
Change-Id: I57ccf2bec1dda573fe3ac628a646624b76f45905
This commit is contained in:
David Anderson 2020-05-28 04:39:37 +00:00
parent 2e66043394
commit 4e058cac0d
6 changed files with 20 additions and 3 deletions

View file

@ -146,7 +146,7 @@ static struct SsFuncDesc ss_descriptors = {
},
};
#define STR_INTERFACE_ "fastboot"
#define STR_INTERFACE_ "fastbootd"
static const struct {
struct usb_functionfs_strings_head header;

View file

@ -258,6 +258,10 @@ static int match_fastboot(usb_ifc_info* info) {
static int list_devices_callback(usb_ifc_info* info) {
if (match_fastboot_with_serial(info, nullptr) == 0) {
std::string serial = info->serial_number;
std::string interface = info->interface;
if (interface.empty()) {
interface = "fastboot";
}
if (!info->writable) {
serial = UsbNoPermissionsShortHelpText();
}
@ -266,9 +270,9 @@ static int list_devices_callback(usb_ifc_info* info) {
}
// output compatible with "adb devices"
if (!g_long_listing) {
printf("%s\tfastboot", serial.c_str());
printf("%s\t%s", serial.c_str(), interface.c_str());
} else {
printf("%-22s fastboot", serial.c_str());
printf("%-22s %s", serial.c_str(), interface.c_str());
if (strlen(info->device_path) > 0) printf(" %s", info->device_path);
}
putchar('\n');

View file

@ -50,6 +50,8 @@ struct usb_ifc_info {
char serial_number[256];
char device_path[256];
char interface[256];
};
class UsbTransport : public Transport {

View file

@ -43,6 +43,8 @@
#include <linux/version.h>
#include <linux/usb/ch9.h>
#include <android-base/file.h>
#include <android-base/stringprintf.h>
#include <chrono>
#include <memory>
#include <thread>
@ -263,6 +265,13 @@ static int filter_usb_device(char* sysfs_name,
info.has_bulk_in = (in != -1);
info.has_bulk_out = (out != -1);
std::string interface;
auto path = android::base::StringPrintf("/sys/bus/usb/devices/%s/%s:1.%d/interface",
sysfs_name, sysfs_name, ifc->bInterfaceNumber);
if (android::base::ReadFileToString(path, &interface)) {
snprintf(info.interface, sizeof(info.interface), "%s", interface.c_str());
}
if(callback(&info) == 0) {
*ept_in_id = in;
*ept_out_id = out;

View file

@ -368,6 +368,7 @@ static int try_device(io_service_t device, usb_handle *handle) {
// device has no serial number
handle->info.serial_number[0] = 0;
}
handle->info.interface[0] = 0;
handle->info.writable = 1;
if (try_interfaces(dev, handle)) {

View file

@ -319,6 +319,7 @@ int recognized_device(usb_handle* handle, ifc_match_func callback) {
&serial_number_len, true)) {
info.serial_number[0] = 0;
}
info.interface[0] = 0;
info.device_path[0] = 0;