Loading adb/adb.cpp +4 −6 Original line number Diff line number Diff line Loading @@ -48,9 +48,9 @@ #include "transport.h" #if !ADB_HOST #include <cutils/properties.h> #include <sys/capability.h> #include <sys/mount.h> #include <android-base/properties.h> #endif std::string adb_version() { Loading Loading @@ -200,11 +200,9 @@ std::string get_connection_string() { "ro.product.device", }; for (const auto& prop_name : cnxn_props) { char value[PROPERTY_VALUE_MAX]; property_get(prop_name, value, ""); connection_properties.push_back( android::base::StringPrintf("%s=%s", prop_name, value)); for (const auto& prop : cnxn_props) { std::string value = std::string(prop) + "=" + android::base::GetProperty(prop, ""); connection_properties.push_back(value); } #endif Loading adb/adb_trace.cpp +2 −10 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ #include "adb.h" #if !ADB_HOST #include <cutils/properties.h> #include <android-base/properties.h> #endif #if !ADB_HOST Loading Loading @@ -88,19 +88,11 @@ std::string get_trace_setting_from_env() { return std::string(setting); } #if !ADB_HOST std::string get_trace_setting_from_prop() { char buf[PROPERTY_VALUE_MAX]; property_get("persist.adb.trace_mask", buf, ""); return std::string(buf); } #endif std::string get_trace_setting() { #if ADB_HOST return get_trace_setting_from_env(); #else return get_trace_setting_from_prop(); return android::base::GetProperty("persist.adb.trace_mask", ""); #endif } Loading adb/daemon/main.cpp +12 −22 Original line number Diff line number Diff line Loading @@ -29,11 +29,11 @@ #include <android-base/logging.h> #include <android-base/macros.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <libminijail.h> #include <scoped_minijail.h> #include "cutils/properties.h" #include "debuggerd/client.h" #include "private/android_filesystem_config.h" #include "selinux/android.h" Loading @@ -48,9 +48,7 @@ static const char* root_seclabel = nullptr; static void drop_capabilities_bounding_set_if_needed(struct minijail *j) { #if defined(ALLOW_ADBD_ROOT) char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, ""); if (strcmp(value, "1") == 0) { if (android::base::GetBoolProperty("ro.debuggable", false)) { return; } #endif Loading @@ -59,8 +57,6 @@ static void drop_capabilities_bounding_set_if_needed(struct minijail *j) { static bool should_drop_privileges() { #if defined(ALLOW_ADBD_ROOT) char value[PROPERTY_VALUE_MAX]; // The properties that affect `adb root` and `adb unroot` are ro.secure and // ro.debuggable. In this context the names don't make the expected behavior // particularly obvious. Loading @@ -71,24 +67,19 @@ static bool should_drop_privileges() { // // ro.secure: // Drop privileges by default. Set to 1 on userdebug and user builds. property_get("ro.secure", value, "1"); bool ro_secure = (strcmp(value, "1") == 0); property_get("ro.debuggable", value, ""); bool ro_debuggable = (strcmp(value, "1") == 0); bool ro_secure = android::base::GetBoolProperty("ro.secure", true); bool ro_debuggable = android::base::GetBoolProperty("ro.debuggable", false); // Drop privileges if ro.secure is set... bool drop = ro_secure; property_get("service.adb.root", value, ""); bool adb_root = (strcmp(value, "1") == 0); bool adb_unroot = (strcmp(value, "0") == 0); // ... except "adb root" lets you keep privileges in a debuggable build. std::string prop = android::base::GetProperty("service.adb.root", ""); bool adb_root = (prop == "1"); bool adb_unroot = (prop == "0"); if (ro_debuggable && adb_root) { drop = false; } // ... and "adb unroot" lets you explicitly drop privileges. if (adb_unroot) { drop = true; Loading Loading @@ -159,7 +150,7 @@ int adbd_main(int server_port) { // descriptor will always be open. adbd_cloexec_auth_socket(); if (ALLOW_ADBD_NO_AUTH && property_get_bool("ro.adb.secure", 0) == 0) { if (ALLOW_ADBD_NO_AUTH && !android::base::GetBoolProperty("ro.adb.secure", false)) { auth_required = false; } Loading Loading @@ -187,14 +178,13 @@ int adbd_main(int server_port) { // If one of these properties is set, also listen on that port. // If one of the properties isn't set and we couldn't listen on usb, listen // on the default port. char prop_port[PROPERTY_VALUE_MAX]; property_get("service.adb.tcp.port", prop_port, ""); if (prop_port[0] == '\0') { property_get("persist.adb.tcp.port", prop_port, ""); std::string prop_port = android::base::GetProperty("service.adb.tcp.port", ""); if (prop_port.empty()) { prop_port = android::base::GetProperty("persist.adb.tcp.port", ""); } int port; if (sscanf(prop_port, "%d", &port) == 1 && port > 0) { if (sscanf(prop_port.c_str(), "%d", &port) == 1 && port > 0) { D("using port=%d", port); // Listen on TCP port specified by service.adb.tcp.port property. local_init(port); Loading adb/remount_service.cpp +6 −14 Original line number Diff line number Diff line Loading @@ -29,10 +29,11 @@ #include <string> #include <android-base/properties.h> #include "adb.h" #include "adb_io.h" #include "adb_utils.h" #include "cutils/properties.h" #include "fs_mgr.h" // Returns the device used to mount a directory in /proc/mounts. Loading @@ -53,10 +54,7 @@ static std::string find_proc_mount(const char* dir) { // Returns the device used to mount a directory in the fstab. static std::string find_fstab_mount(const char* dir) { char propbuf[PROPERTY_VALUE_MAX]; property_get("ro.hardware", propbuf, ""); std::string fstab_filename = std::string("/fstab.") + propbuf; std::string fstab_filename = "/fstab." + android::base::GetProperty("ro.hardware", ""); struct fstab* fstab = fs_mgr_read_fstab(fstab_filename.c_str()); struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, dir); std::string dev = rec ? std::string(rec->blk_device) : ""; Loading Loading @@ -113,12 +111,8 @@ void remount_service(int fd, void* cookie) { return; } char prop_buf[PROPERTY_VALUE_MAX]; property_get("partition.system.verified", prop_buf, ""); bool system_verified = (strlen(prop_buf) > 0); property_get("partition.vendor.verified", prop_buf, ""); bool vendor_verified = (strlen(prop_buf) > 0); bool system_verified = !(android::base::GetProperty("partition.system.verified", "").empty()); bool vendor_verified = !(android::base::GetProperty("partition.vendor.verified", "").empty()); if (system_verified || vendor_verified) { // Allow remount but warn of likely bad effects Loading @@ -136,9 +130,7 @@ void remount_service(int fd, void* cookie) { } bool success = true; property_get("ro.build.system_root_image", prop_buf, ""); bool system_root = !strcmp(prop_buf, "true"); if (system_root) { if (android::base::GetBoolProperty("ro.build.system_root_image", false)) { success &= remount_partition(fd, "/"); } else { success &= remount_partition(fd, "/system"); Loading adb/services.cpp +9 −20 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ #if !ADB_HOST #include "cutils/android_reboot.h" #include "cutils/properties.h" #include <android-base/properties.h> #endif #include "adb.h" Loading Loading @@ -73,15 +73,13 @@ void restart_root_service(int fd, void *cookie) { WriteFdExactly(fd, "adbd is already running as root\n"); adb_close(fd); } else { char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, ""); if (strcmp(value, "1") != 0) { if (!android::base::GetBoolProperty("ro.debuggable", false)) { WriteFdExactly(fd, "adbd cannot run as root in production builds\n"); adb_close(fd); return; } property_set("service.adb.root", "1"); android::base::SetProperty("service.adb.root", "1"); WriteFdExactly(fd, "restarting adbd as root\n"); adb_close(fd); } Loading @@ -92,7 +90,7 @@ void restart_unroot_service(int fd, void *cookie) { WriteFdExactly(fd, "adbd not running as root\n"); adb_close(fd); } else { property_set("service.adb.root", "0"); android::base::SetProperty("service.adb.root", "0"); WriteFdExactly(fd, "restarting adbd as non root\n"); adb_close(fd); } Loading @@ -106,15 +104,13 @@ void restart_tcp_service(int fd, void *cookie) { return; } char value[PROPERTY_VALUE_MAX]; snprintf(value, sizeof(value), "%d", port); property_set("service.adb.tcp.port", value); android::base::SetProperty("service.adb.tcp.port", android::base::StringPrintf("%d", port)); WriteFdFmt(fd, "restarting in TCP mode port: %d\n", port); adb_close(fd); } void restart_usb_service(int fd, void *cookie) { property_set("service.adb.tcp.port", "0"); android::base::SetProperty("service.adb.tcp.port", "0"); WriteFdExactly(fd, "restarting in USB mode\n"); adb_close(fd); } Loading Loading @@ -155,16 +151,9 @@ static bool reboot_service_impl(int fd, const char* arg) { sync(); char property_val[PROPERTY_VALUE_MAX]; int ret = snprintf(property_val, sizeof(property_val), "reboot,%s", reboot_arg); if (ret >= static_cast<int>(sizeof(property_val))) { WriteFdFmt(fd, "reboot string too long: %d\n", ret); return false; } ret = property_set(ANDROID_RB_PROPERTY, property_val); if (ret < 0) { WriteFdFmt(fd, "reboot failed: %d\n", ret); std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg); if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) { WriteFdFmt(fd, "reboot (%s) failed\n", reboot_string.c_str()); return false; } Loading Loading
adb/adb.cpp +4 −6 Original line number Diff line number Diff line Loading @@ -48,9 +48,9 @@ #include "transport.h" #if !ADB_HOST #include <cutils/properties.h> #include <sys/capability.h> #include <sys/mount.h> #include <android-base/properties.h> #endif std::string adb_version() { Loading Loading @@ -200,11 +200,9 @@ std::string get_connection_string() { "ro.product.device", }; for (const auto& prop_name : cnxn_props) { char value[PROPERTY_VALUE_MAX]; property_get(prop_name, value, ""); connection_properties.push_back( android::base::StringPrintf("%s=%s", prop_name, value)); for (const auto& prop : cnxn_props) { std::string value = std::string(prop) + "=" + android::base::GetProperty(prop, ""); connection_properties.push_back(value); } #endif Loading
adb/adb_trace.cpp +2 −10 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ #include "adb.h" #if !ADB_HOST #include <cutils/properties.h> #include <android-base/properties.h> #endif #if !ADB_HOST Loading Loading @@ -88,19 +88,11 @@ std::string get_trace_setting_from_env() { return std::string(setting); } #if !ADB_HOST std::string get_trace_setting_from_prop() { char buf[PROPERTY_VALUE_MAX]; property_get("persist.adb.trace_mask", buf, ""); return std::string(buf); } #endif std::string get_trace_setting() { #if ADB_HOST return get_trace_setting_from_env(); #else return get_trace_setting_from_prop(); return android::base::GetProperty("persist.adb.trace_mask", ""); #endif } Loading
adb/daemon/main.cpp +12 −22 Original line number Diff line number Diff line Loading @@ -29,11 +29,11 @@ #include <android-base/logging.h> #include <android-base/macros.h> #include <android-base/properties.h> #include <android-base/stringprintf.h> #include <libminijail.h> #include <scoped_minijail.h> #include "cutils/properties.h" #include "debuggerd/client.h" #include "private/android_filesystem_config.h" #include "selinux/android.h" Loading @@ -48,9 +48,7 @@ static const char* root_seclabel = nullptr; static void drop_capabilities_bounding_set_if_needed(struct minijail *j) { #if defined(ALLOW_ADBD_ROOT) char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, ""); if (strcmp(value, "1") == 0) { if (android::base::GetBoolProperty("ro.debuggable", false)) { return; } #endif Loading @@ -59,8 +57,6 @@ static void drop_capabilities_bounding_set_if_needed(struct minijail *j) { static bool should_drop_privileges() { #if defined(ALLOW_ADBD_ROOT) char value[PROPERTY_VALUE_MAX]; // The properties that affect `adb root` and `adb unroot` are ro.secure and // ro.debuggable. In this context the names don't make the expected behavior // particularly obvious. Loading @@ -71,24 +67,19 @@ static bool should_drop_privileges() { // // ro.secure: // Drop privileges by default. Set to 1 on userdebug and user builds. property_get("ro.secure", value, "1"); bool ro_secure = (strcmp(value, "1") == 0); property_get("ro.debuggable", value, ""); bool ro_debuggable = (strcmp(value, "1") == 0); bool ro_secure = android::base::GetBoolProperty("ro.secure", true); bool ro_debuggable = android::base::GetBoolProperty("ro.debuggable", false); // Drop privileges if ro.secure is set... bool drop = ro_secure; property_get("service.adb.root", value, ""); bool adb_root = (strcmp(value, "1") == 0); bool adb_unroot = (strcmp(value, "0") == 0); // ... except "adb root" lets you keep privileges in a debuggable build. std::string prop = android::base::GetProperty("service.adb.root", ""); bool adb_root = (prop == "1"); bool adb_unroot = (prop == "0"); if (ro_debuggable && adb_root) { drop = false; } // ... and "adb unroot" lets you explicitly drop privileges. if (adb_unroot) { drop = true; Loading Loading @@ -159,7 +150,7 @@ int adbd_main(int server_port) { // descriptor will always be open. adbd_cloexec_auth_socket(); if (ALLOW_ADBD_NO_AUTH && property_get_bool("ro.adb.secure", 0) == 0) { if (ALLOW_ADBD_NO_AUTH && !android::base::GetBoolProperty("ro.adb.secure", false)) { auth_required = false; } Loading Loading @@ -187,14 +178,13 @@ int adbd_main(int server_port) { // If one of these properties is set, also listen on that port. // If one of the properties isn't set and we couldn't listen on usb, listen // on the default port. char prop_port[PROPERTY_VALUE_MAX]; property_get("service.adb.tcp.port", prop_port, ""); if (prop_port[0] == '\0') { property_get("persist.adb.tcp.port", prop_port, ""); std::string prop_port = android::base::GetProperty("service.adb.tcp.port", ""); if (prop_port.empty()) { prop_port = android::base::GetProperty("persist.adb.tcp.port", ""); } int port; if (sscanf(prop_port, "%d", &port) == 1 && port > 0) { if (sscanf(prop_port.c_str(), "%d", &port) == 1 && port > 0) { D("using port=%d", port); // Listen on TCP port specified by service.adb.tcp.port property. local_init(port); Loading
adb/remount_service.cpp +6 −14 Original line number Diff line number Diff line Loading @@ -29,10 +29,11 @@ #include <string> #include <android-base/properties.h> #include "adb.h" #include "adb_io.h" #include "adb_utils.h" #include "cutils/properties.h" #include "fs_mgr.h" // Returns the device used to mount a directory in /proc/mounts. Loading @@ -53,10 +54,7 @@ static std::string find_proc_mount(const char* dir) { // Returns the device used to mount a directory in the fstab. static std::string find_fstab_mount(const char* dir) { char propbuf[PROPERTY_VALUE_MAX]; property_get("ro.hardware", propbuf, ""); std::string fstab_filename = std::string("/fstab.") + propbuf; std::string fstab_filename = "/fstab." + android::base::GetProperty("ro.hardware", ""); struct fstab* fstab = fs_mgr_read_fstab(fstab_filename.c_str()); struct fstab_rec* rec = fs_mgr_get_entry_for_mount_point(fstab, dir); std::string dev = rec ? std::string(rec->blk_device) : ""; Loading Loading @@ -113,12 +111,8 @@ void remount_service(int fd, void* cookie) { return; } char prop_buf[PROPERTY_VALUE_MAX]; property_get("partition.system.verified", prop_buf, ""); bool system_verified = (strlen(prop_buf) > 0); property_get("partition.vendor.verified", prop_buf, ""); bool vendor_verified = (strlen(prop_buf) > 0); bool system_verified = !(android::base::GetProperty("partition.system.verified", "").empty()); bool vendor_verified = !(android::base::GetProperty("partition.vendor.verified", "").empty()); if (system_verified || vendor_verified) { // Allow remount but warn of likely bad effects Loading @@ -136,9 +130,7 @@ void remount_service(int fd, void* cookie) { } bool success = true; property_get("ro.build.system_root_image", prop_buf, ""); bool system_root = !strcmp(prop_buf, "true"); if (system_root) { if (android::base::GetBoolProperty("ro.build.system_root_image", false)) { success &= remount_partition(fd, "/"); } else { success &= remount_partition(fd, "/system"); Loading
adb/services.cpp +9 −20 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ #if !ADB_HOST #include "cutils/android_reboot.h" #include "cutils/properties.h" #include <android-base/properties.h> #endif #include "adb.h" Loading Loading @@ -73,15 +73,13 @@ void restart_root_service(int fd, void *cookie) { WriteFdExactly(fd, "adbd is already running as root\n"); adb_close(fd); } else { char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, ""); if (strcmp(value, "1") != 0) { if (!android::base::GetBoolProperty("ro.debuggable", false)) { WriteFdExactly(fd, "adbd cannot run as root in production builds\n"); adb_close(fd); return; } property_set("service.adb.root", "1"); android::base::SetProperty("service.adb.root", "1"); WriteFdExactly(fd, "restarting adbd as root\n"); adb_close(fd); } Loading @@ -92,7 +90,7 @@ void restart_unroot_service(int fd, void *cookie) { WriteFdExactly(fd, "adbd not running as root\n"); adb_close(fd); } else { property_set("service.adb.root", "0"); android::base::SetProperty("service.adb.root", "0"); WriteFdExactly(fd, "restarting adbd as non root\n"); adb_close(fd); } Loading @@ -106,15 +104,13 @@ void restart_tcp_service(int fd, void *cookie) { return; } char value[PROPERTY_VALUE_MAX]; snprintf(value, sizeof(value), "%d", port); property_set("service.adb.tcp.port", value); android::base::SetProperty("service.adb.tcp.port", android::base::StringPrintf("%d", port)); WriteFdFmt(fd, "restarting in TCP mode port: %d\n", port); adb_close(fd); } void restart_usb_service(int fd, void *cookie) { property_set("service.adb.tcp.port", "0"); android::base::SetProperty("service.adb.tcp.port", "0"); WriteFdExactly(fd, "restarting in USB mode\n"); adb_close(fd); } Loading Loading @@ -155,16 +151,9 @@ static bool reboot_service_impl(int fd, const char* arg) { sync(); char property_val[PROPERTY_VALUE_MAX]; int ret = snprintf(property_val, sizeof(property_val), "reboot,%s", reboot_arg); if (ret >= static_cast<int>(sizeof(property_val))) { WriteFdFmt(fd, "reboot string too long: %d\n", ret); return false; } ret = property_set(ANDROID_RB_PROPERTY, property_val); if (ret < 0) { WriteFdFmt(fd, "reboot failed: %d\n", ret); std::string reboot_string = android::base::StringPrintf("reboot,%s", reboot_arg); if (!android::base::SetProperty(ANDROID_RB_PROPERTY, reboot_string)) { WriteFdFmt(fd, "reboot (%s) failed\n", reboot_string.c_str()); return false; } Loading