Merge "init: cleanup some string usage"
diff --git a/init/action.cpp b/init/action.cpp
index 21abe02..206100e 100644
--- a/init/action.cpp
+++ b/init/action.cpp
@@ -18,13 +18,11 @@
 
 #include <android-base/logging.h>
 #include <android-base/properties.h>
-#include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 
 #include "util.h"
 
 using android::base::Join;
-using android::base::StringPrintf;
 
 Command::Command(BuiltinFunction f, const std::vector<std::string>& args, int line)
     : func_(f), args_(args), line_(line) {}
@@ -98,10 +96,10 @@
         android::base::GetMinimumLogSeverity() <= android::base::DEBUG) {
         std::string trigger_name = BuildTriggersString();
         std::string cmd_str = command.BuildCommandString();
-        std::string source = StringPrintf(" (%s:%d)", filename_.c_str(), command.line());
 
-        LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << source
-                  << " returned " << result << " took " << duration_ms << "ms.";
+        LOG(INFO) << "Command '" << cmd_str << "' action=" << trigger_name << " (" << filename_
+                  << ":" << command.line() << ") returned " << result << " took " << duration_ms
+                  << "ms.";
     }
 }
 
diff --git a/init/builtins.cpp b/init/builtins.cpp
index 1eacb36..c78bec7 100644
--- a/init/builtins.cpp
+++ b/init/builtins.cpp
@@ -43,7 +43,6 @@
 #include <android-base/logging.h>
 #include <android-base/parseint.h>
 #include <android-base/properties.h>
-#include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 #include <bootloader_message/bootloader_message.h>
 #include <cutils/android_reboot.h>
@@ -535,11 +534,10 @@
         }
     }
 
-    std::string prop_name = android::base::StringPrintf("ro.boottime.init.mount_all.%s",
-                                                        prop_post_fix);
+    std::string prop_name = "ro.boottime.init.mount_all."s + prop_post_fix;
     Timer t;
     int ret =  mount_fstab(fstabfile, mount_mode);
-    property_set(prop_name.c_str(), std::to_string(t.duration_ms()).c_str());
+    property_set(prop_name, std::to_string(t.duration_ms()));
 
     if (import_rc) {
         /* Paths of .rc files are specified at the 2nd argument and beyond */
@@ -567,9 +565,7 @@
 }
 
 static int do_setprop(const std::vector<std::string>& args) {
-    const char* name = args[1].c_str();
-    const char* value = args[2].c_str();
-    property_set(name, value);
+    property_set(args[1], args[2]);
     return 0;
 }
 
@@ -652,8 +648,7 @@
 
 static void verity_update_property(fstab_rec *fstab, const char *mount_point,
                                    int mode, int status) {
-    property_set(android::base::StringPrintf("partition.%s.verified", mount_point).c_str(),
-                 android::base::StringPrintf("%d", mode).c_str());
+    property_set("partition."s + mount_point + ".verified", std::to_string(mode));
 }
 
 static int do_verity_update_state(const std::vector<std::string>& args) {
diff --git a/init/descriptors.cpp b/init/descriptors.cpp
index 6f729a3..ed65a05 100644
--- a/init/descriptors.cpp
+++ b/init/descriptors.cpp
@@ -58,7 +58,7 @@
   std::for_each(publishedName.begin(), publishedName.end(),
                 [] (char& c) { c = isalnum(c) ? c : '_'; });
 
-  std::string val = android::base::StringPrintf("%d", fd);
+  std::string val = std::to_string(fd);
   add_environment(publishedName.c_str(), val.c_str());
 
   // make sure we don't close on exec
@@ -74,7 +74,8 @@
 }
 
 void SocketInfo::Clean() const {
-  unlink(android::base::StringPrintf(ANDROID_SOCKET_DIR "/%s", name().c_str()).c_str());
+    std::string path = android::base::StringPrintf("%s/%s", ANDROID_SOCKET_DIR, name().c_str());
+    unlink(path.c_str());
 }
 
 int SocketInfo::Create(const std::string& context) const {
diff --git a/init/init.cpp b/init/init.cpp
index 999fada..d6e9130 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -42,7 +42,6 @@
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
-#include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 #include <android-base/unique_fd.h>
 #include <keyutils.h>
@@ -71,9 +70,10 @@
 #include "util.h"
 #include "watchdogd.h"
 
+using namespace std::string_literals;
+
 using android::base::boot_clock;
 using android::base::GetProperty;
-using android::base::StringPrintf;
 
 struct selabel_handle *sehandle;
 struct selabel_handle *sehandle_prop;
@@ -219,7 +219,7 @@
         panic();
     }
 
-    property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()).c_str());
+    property_set("ro.boottime.init.cold_boot_wait", std::to_string(t.duration_ms()));
     return 0;
 }
 
@@ -449,14 +449,14 @@
 
     if (for_emulator) {
         // In the emulator, export any kernel option with the "ro.kernel." prefix.
-        property_set(StringPrintf("ro.kernel.%s", key.c_str()).c_str(), value.c_str());
+        property_set("ro.kernel." + key, value);
         return;
     }
 
     if (key == "qemu") {
         strlcpy(qemu, value.c_str(), sizeof(qemu));
     } else if (android::base::StartsWith(key, "androidboot.")) {
-        property_set(StringPrintf("ro.boot.%s", key.c_str() + 12).c_str(), value.c_str());
+        property_set("ro.boot." + key.substr(12), value);
     }
 }
 
@@ -487,7 +487,7 @@
     };
     for (size_t i = 0; i < arraysize(prop_map); i++) {
         std::string value = GetProperty(prop_map[i].src_prop, "");
-        property_set(prop_map[i].dst_prop, (!value.empty()) ? value.c_str() : prop_map[i].default_value);
+        property_set(prop_map[i].dst_prop, (!value.empty()) ? value : prop_map[i].default_value);
     }
 }
 
@@ -511,8 +511,7 @@
         android::base::ReadFileToString(file_name, &dt_file);
         std::replace(dt_file.begin(), dt_file.end(), ',', '.');
 
-        std::string property_name = StringPrintf("ro.boot.%s", dp->d_name);
-        property_set(property_name.c_str(), dt_file.c_str());
+        property_set("ro.boot."s + dp->d_name, dt_file);
     }
 }
 
@@ -1002,7 +1001,7 @@
 
         static constexpr uint32_t kNanosecondsPerMillisecond = 1e6;
         uint64_t start_ms = start_time.time_since_epoch().count() / kNanosecondsPerMillisecond;
-        setenv("INIT_STARTED_AT", StringPrintf("%" PRIu64, start_ms).c_str(), 1);
+        setenv("INIT_STARTED_AT", std::to_string(start_ms).c_str(), 1);
 
         char* path = argv[0];
         char* args[] = { path, nullptr };
diff --git a/init/property_service.cpp b/init/property_service.cpp
index b43da4e..31e6e48 100644
--- a/init/property_service.cpp
+++ b/init/property_service.cpp
@@ -45,7 +45,6 @@
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/properties.h>
-#include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 #include <bootimg.h>
 #include <fs_mgr.h>
@@ -56,8 +55,6 @@
 #include "init.h"
 #include "util.h"
 
-using android::base::StringPrintf;
-
 #define PERSISTENT_PROPERTY_DIR  "/data/property"
 #define RECOVERY_MOUNT_POINT "/recovery"
 
@@ -714,7 +711,7 @@
     boot_img_hdr hdr;
     if (android::base::ReadFully(fd, &hdr, sizeof(hdr))) {
         std::string hex = bytes_to_hex(reinterpret_cast<uint8_t*>(hdr.id), sizeof(hdr.id));
-        property_set("ro.recovery_id", hex.c_str());
+        property_set("ro.recovery_id", hex);
     } else {
         PLOG(ERROR) << "error reading /recovery";
     }
diff --git a/init/service.cpp b/init/service.cpp
index b73ddfb..d8c6875 100644
--- a/init/service.cpp
+++ b/init/service.cpp
@@ -198,13 +198,12 @@
         return;
     }
 
-    std::string prop_name = StringPrintf("init.svc.%s", name_.c_str());
-    property_set(prop_name.c_str(), new_state.c_str());
+    std::string prop_name = "init.svc." + name_;
+    property_set(prop_name, new_state);
 
     if (new_state == "running") {
         uint64_t start_ns = time_started_.time_since_epoch().count();
-        property_set(StringPrintf("ro.boottime.%s", name_.c_str()).c_str(),
-                     StringPrintf("%" PRIu64, start_ns).c_str());
+        property_set("ro.boottime." + name_, std::to_string(start_ns));
     }
 }
 
@@ -716,7 +715,7 @@
                     StringPrintf("/dev/cpuset%stasks", default_cpuset.c_str()));
             }
         }
-        std::string pid_str = StringPrintf("%d", getpid());
+        std::string pid_str = std::to_string(getpid());
         for (const auto& file : writepid_files_) {
             if (!WriteStringToFile(pid_str, file)) {
                 PLOG(ERROR) << "couldn't write " << pid_str << " to " << file;
@@ -757,7 +756,7 @@
     }
 
     if (oom_score_adjust_ != -1000) {
-        std::string oom_str = StringPrintf("%d", oom_score_adjust_);
+        std::string oom_str = std::to_string(oom_score_adjust_);
         std::string oom_file = StringPrintf("/proc/%d/oom_score_adj", pid);
         if (!WriteStringToFile(oom_str, oom_file)) {
             PLOG(ERROR) << "couldn't write oom_score_adj: " << strerror(errno);
@@ -776,9 +775,9 @@
     }
 
     if ((flags_ & SVC_EXEC) != 0) {
-        LOG(INFO) << android::base::StringPrintf(
-            "SVC_EXEC pid %d (uid %d gid %d+%zu context %s) started; waiting...", pid_, uid_, gid_,
-            supp_gids_.size(), !seclabel_.empty() ? seclabel_.c_str() : "default");
+        LOG(INFO) << "SVC_EXEC pid " << pid_ << " (uid " << uid_ << " gid " << gid_ << "+"
+                  << supp_gids_.size() << " context "
+                  << (!seclabel_.empty() ? seclabel_ : "default") << ") started; waiting...";
     }
 
     NotifyStateChange("running");
diff --git a/init/signal_handler.cpp b/init/signal_handler.cpp
index 4d56d84..183837b 100644
--- a/init/signal_handler.cpp
+++ b/init/signal_handler.cpp
@@ -21,7 +21,6 @@
 #include <unistd.h>
 
 #include <android-base/logging.h>
-#include <android-base/stringprintf.h>
 
 #include "init.h"
 #include "service.h"
diff --git a/init/ueventd.cpp b/init/ueventd.cpp
index 4982b77..2fd8058 100644
--- a/init/ueventd.cpp
+++ b/init/ueventd.cpp
@@ -29,7 +29,6 @@
 
 #include <android-base/logging.h>
 #include <android-base/properties.h>
-#include <android-base/stringprintf.h>
 #include <selinux/android.h>
 #include <selinux/selinux.h>