summaryrefslogtreecommitdiffstats
path: root/adb_install.cpp
diff options
context:
space:
mode:
authorHridya Valsaraju <hridya@google.com>2018-08-31 20:57:51 +0200
committerHridya Valsaraju <hridya@google.com>2018-09-08 00:02:43 +0200
commite4ef453914235d1ac3bea1c1a27975ee1ea7da73 (patch)
treef421eef0a20c95c43cf006e1607fd8e75947ab8a /adb_install.cpp
parentMerge "support mounting f2fs in recovery mode" (diff)
downloadandroid_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar.gz
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar.bz2
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar.lz
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar.xz
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.tar.zst
android_bootable_recovery-e4ef453914235d1ac3bea1c1a27975ee1ea7da73.zip
Diffstat (limited to 'adb_install.cpp')
-rw-r--r--adb_install.cpp64
1 files changed, 23 insertions, 41 deletions
diff --git a/adb_install.cpp b/adb_install.cpp
index 97dff221d..438da9fc3 100644
--- a/adb_install.cpp
+++ b/adb_install.cpp
@@ -26,55 +26,23 @@
#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"
#include "install.h"
#include "ui.h"
-static void set_usb_driver(bool enabled) {
- // USB configfs doesn't use /s/c/a/a/enable.
- if (android::base::GetBoolProperty("sys.usb.configfs", false)) {
- return;
- }
-
- 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;
- }
- // 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";
- }
-}
-
-static void stop_adbd() {
- ui->Print("Stopping adbd...\n");
- android::base::SetProperty("ctl.stop", "adbd");
- set_usb_driver(false);
-}
-
-static void maybe_restart_adbd() {
- if (is_ro_debuggable()) {
- ui->Print("Restarting adbd...\n");
- set_usb_driver(true);
- android::base::SetProperty("ctl.start", "adbd");
- }
-}
-
int apply_from_adb(bool* wipe_cache) {
modified_flash = true;
-
- stop_adbd();
- set_usb_driver(true);
+ // Save the usb state to restore after the sideload operation.
+ std::string usb_state = android::base::GetProperty("sys.usb.state", "none");
+ // Clean up state and stop adbd.
+ if (usb_state != "none" && !SetUsbConfig("none")) {
+ LOG(ERROR) << "Failed to clear USB config";
+ return INSTALL_ERROR;
+ }
ui->Print(
"\n\nNow send the package you want to apply\n"
@@ -86,6 +54,11 @@ int apply_from_adb(bool* wipe_cache) {
_exit(EXIT_FAILURE);
}
+ if (!SetUsbConfig("sideload")) {
+ LOG(ERROR) << "Failed to set usb config to sideload";
+ return INSTALL_ERROR;
+ }
+
// How long (in seconds) we wait for the host to start sending us a package, before timing out.
static constexpr int ADB_INSTALL_TIMEOUT = 300;
@@ -136,8 +109,17 @@ int apply_from_adb(bool* wipe_cache) {
}
}
- set_usb_driver(false);
- maybe_restart_adbd();
+ // Clean up before switching to the older state, for example setting the state
+ // to none sets sys/class/android_usb/android0/enable to 0.
+ if (!SetUsbConfig("none")) {
+ LOG(ERROR) << "Failed to clear USB config";
+ }
+
+ if (usb_state != "none") {
+ if (!SetUsbConfig(usb_state)) {
+ LOG(ERROR) << "Failed to set USB config to " << usb_state;
+ }
+ }
return result;
}