summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-05-12 03:59:40 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-05-12 03:59:40 +0200
commit33154a67359efa3dab0c2b159b15f4370de7edf9 (patch)
treedd4ea31bb5246577fb5f9c728fc01d3f876fac85
parentMerge "recovery: Skip "/" in setup_install_mounts()." am: d7446c8eed am: b0626221a1 am: 8c7c38ca7f (diff)
parentMerge "Don't write to /sys/class/android_usb/android0/enable with configfs." am: 7cb1b79673 am: 7ca2e734fc (diff)
downloadandroid_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar.gz
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar.bz2
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar.lz
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar.xz
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.tar.zst
android_bootable_recovery-33154a67359efa3dab0c2b159b15f4370de7edf9.zip
Diffstat (limited to '')
-rw-r--r--adb_install.cpp23
1 files changed, 16 insertions, 7 deletions
diff --git a/adb_install.cpp b/adb_install.cpp
index e7d7758f9..ac0130651 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -26,7 +26,10 @@
#include <sys/wait.h>
#include <unistd.h>
+#include <android-base/file.h>
+#include <android-base/logging.h>
#include <android-base/properties.h>
+#include <android-base/unique_fd.h>
#include "common.h"
#include "fuse_sideload.h"
@@ -34,16 +37,22 @@
#include "ui.h"
static void set_usb_driver(bool enabled) {
- int fd = open("/sys/class/android_usb/android0/enable", O_WRONLY);
- if (fd < 0) {
- ui->Print("failed to open driver control: %s\n", strerror(errno));
+ // USB configfs doesn't use /s/c/a/a/enable.
+ if (android::base::GetBoolProperty("sys.usb.configfs", false)) {
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) {
- ui->Print("failed to close driver control: %s\n", strerror(errno));
+ // Not using android::base::WriteStringToFile since that will open with O_CREAT and give EPERM
+ // 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";
}
}