Don't write to /sys/class/android_usb/android0/enable with configfs.
USB configfs doesn't use /s/c/a/a/enable. Trying to set that gives confusing message on screen when sideloading. Bug: 37713851 Test: adb sideload on device using with configfs. Test: adb sideload on marlin. Change-Id: Ifa55f90c2a5fe6bf9e7cee95882de9f6de686d73
This commit is contained in:
parent
d7446c8eed
commit
0167d4c382
1 changed files with 16 additions and 7 deletions
|
@ -26,7 +26,10 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#include <android-base/file.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
|
#include <android-base/unique_fd.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "fuse_sideload.h"
|
#include "fuse_sideload.h"
|
||||||
|
@ -34,16 +37,22 @@
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
static void set_usb_driver(bool enabled) {
|
static void set_usb_driver(bool enabled) {
|
||||||
int fd = open("/sys/class/android_usb/android0/enable", O_WRONLY);
|
// USB configfs doesn't use /s/c/a/a/enable.
|
||||||
if (fd < 0) {
|
if (android::base::GetBoolProperty("sys.usb.configfs", false)) {
|
||||||
ui->Print("failed to open driver control: %s\n", strerror(errno));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (TEMP_FAILURE_RETRY(write(fd, enabled ? "1" : "0", 1)) == -1) {
|
|
||||||
ui->Print("failed to set driver control: %s\n", strerror(errno));
|
static constexpr const char* USB_DRIVER_CONTROL = "/sys/class/android_usb/android0/enable";
|
||||||
|
android::base::unique_fd fd(open(USB_DRIVER_CONTROL, O_WRONLY));
|
||||||
|
if (fd == -1) {
|
||||||
|
PLOG(ERROR) << "Failed to open driver control";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (close(fd) < 0) {
|
// Not using android::base::WriteStringToFile since that will open with O_CREAT and give EPERM
|
||||||
ui->Print("failed to close driver control: %s\n", strerror(errno));
|
// when USB_DRIVER_CONTROL doesn't exist. When it gives EPERM, we don't know whether that's due
|
||||||
|
// to non-existent USB_DRIVER_CONTROL or indeed a permission issue.
|
||||||
|
if (!android::base::WriteStringToFd(enabled ? "1" : "0", fd)) {
|
||||||
|
PLOG(ERROR) << "Failed to set driver control";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue