Replace base string utils with android::base ones

Test: th
Change-Id: I62c1dfb24ec1dae3cdc5e0a0a93ea2b48e9967e5
diff --git a/common/file_fetcher.cc b/common/file_fetcher.cc
index dd994ab..cb8e89a 100644
--- a/common/file_fetcher.cc
+++ b/common/file_fetcher.cc
@@ -23,12 +23,10 @@
 #include <base/format_macros.h>
 #include <base/location.h>
 #include <base/logging.h>
-#include <base/strings/string_util.h>
 #include <android-base/stringprintf.h>
 #include <brillo/streams/file_stream.h>
 
-#include "update_engine/common/hardware_interface.h"
-#include "update_engine/common/platform_constants.h"
+#include "update_engine/common/utils.h"
 
 using std::string;
 
@@ -43,9 +41,8 @@
 // static
 bool FileFetcher::SupportedUrl(const string& url) {
   // Note that we require the file path to start with a "/".
-  return (
-      base::StartsWith(url, "file:///", base::CompareCase::INSENSITIVE_ASCII) ||
-      base::StartsWith(url, "fd://", base::CompareCase::INSENSITIVE_ASCII));
+  return (android::base::StartsWith(ToLower(url), "file:///") ||
+          android::base::StartsWith(ToLower(url), "fd://"));
 }
 
 FileFetcher::~FileFetcher() {
@@ -70,7 +67,7 @@
 
   string file_path;
 
-  if (base::StartsWith(url, "fd://", base::CompareCase::INSENSITIVE_ASCII)) {
+  if (android::base::StartsWith(ToLower(url), "fd://")) {
     int fd = std::stoi(url.substr(strlen("fd://")));
     file_path = url;
     stream_ = brillo::FileStream::FromFileDescriptor(fd, false, nullptr);
diff --git a/common/http_fetcher_unittest.cc b/common/http_fetcher_unittest.cc
index 49d0ebf..7821f4c 100644
--- a/common/http_fetcher_unittest.cc
+++ b/common/http_fetcher_unittest.cc
@@ -35,7 +35,7 @@
 #endif  // BASE_VER < 780000
 #include <base/stl_util.h>
 #include <base/strings/string_number_conversions.h>
-#include <base/strings/string_util.h>
+#include <android-base/stringprintf.h>
 #if BASE_VER >= 780000  // CrOS
 #include <base/task/single_thread_task_executor.h>
 #endif  // BASE_VER >= 780000
diff --git a/common/mock_http_fetcher.cc b/common/mock_http_fetcher.cc
index 1b3cd7d..668d249 100644
--- a/common/mock_http_fetcher.cc
+++ b/common/mock_http_fetcher.cc
@@ -20,11 +20,12 @@
 
 #include <base/bind.h>
 #include <base/logging.h>
-#include <base/strings/string_util.h>
 #include <base/time/time.h>
 #include <brillo/message_loops/message_loop.h>
 #include <gtest/gtest.h>
 
+#include "update_engine/common/utils.h"
+
 // This is a mock implementation of HttpFetcher which is useful for testing.
 
 using brillo::MessageLoop;
@@ -107,11 +108,11 @@
 
 void MockHttpFetcher::SetHeader(const std::string& header_name,
                                 const std::string& header_value) {
-  extra_headers_[base::ToLowerASCII(header_name)] = header_value;
+  extra_headers_[ToLower(header_name)] = header_value;
 }
 
 std::string MockHttpFetcher::GetHeader(const std::string& header_name) const {
-  const auto it = extra_headers_.find(base::ToLowerASCII(header_name));
+  const auto it = extra_headers_.find(ToLower(header_name));
   if (it == extra_headers_.end())
     return "";
   return it->second;
diff --git a/common/prefs.cc b/common/prefs.cc
index a65ce51..3d69238 100644
--- a/common/prefs.cc
+++ b/common/prefs.cc
@@ -26,8 +26,8 @@
 #include <base/files/file_util.h>
 #include <base/logging.h>
 #include <base/strings/string_split.h>
-#include <base/strings/string_util.h>
 
+#include "android-base/strings.h"
 #include "update_engine/common/utils.h"
 
 using std::string;
@@ -73,7 +73,7 @@
   string str_value;
   if (!GetString(key, &str_value))
     return false;
-  base::TrimWhitespaceASCII(str_value, base::TRIM_ALL, &str_value);
+  str_value = android::base::Trim(str_value);
   if (str_value.empty()) {
     LOG(ERROR) << "When reading pref " << key
                << ", got an empty value after trim";
@@ -95,7 +95,7 @@
   string str_value;
   if (!GetString(key, &str_value))
     return false;
-  base::TrimWhitespaceASCII(str_value, base::TRIM_ALL, &str_value);
+  str_value = android::base::Trim(str_value);
   if (str_value == "false") {
     *value = false;
     return true;
@@ -163,7 +163,7 @@
 }
 
 string PrefsInterface::CreateSubKey(const vector<string>& ns_and_key) {
-  return base::JoinString(ns_and_key, string(1, kKeySeparator));
+  return android::base::Join(ns_and_key, string(1, kKeySeparator));
 }
 
 // Prefs
@@ -326,7 +326,7 @@
   // Allows only non-empty keys containing [A-Za-z0-9_-/].
   TEST_AND_RETURN_FALSE(!key.empty());
   for (char c : key)
-    TEST_AND_RETURN_FALSE(base::IsAsciiAlpha(c) || base::IsAsciiDigit(c) ||
+    TEST_AND_RETURN_FALSE(isalpha(c) || isdigit(c) ||
                           c == '_' || c == '-' || c == kKeySeparator);
   if (std::filesystem::exists(GetTemporaryDir())) {
     *filename =
diff --git a/common/prefs_unittest.cc b/common/prefs_unittest.cc
index 3cb04c7..f0d620f 100644
--- a/common/prefs_unittest.cc
+++ b/common/prefs_unittest.cc
@@ -25,7 +25,6 @@
 #include <base/files/file_util.h>
 #include <base/files/scoped_temp_dir.h>
 #include <android-base/macros.h>
-#include <base/strings/string_util.h>
 #include <android-base/stringprintf.h>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
diff --git a/common/subprocess.cc b/common/subprocess.cc
index 44734dc..dfc1c5c 100644
--- a/common/subprocess.cc
+++ b/common/subprocess.cc
@@ -30,7 +30,6 @@
 #include <base/bind.h>
 #include <base/logging.h>
 #include <base/posix/eintr_wrapper.h>
-#include <base/strings/string_util.h>
 #include <android-base/stringprintf.h>
 #include <brillo/secure_blob.h>
 
@@ -99,7 +98,7 @@
   proc->RedirectUsingPipe(STDOUT_FILENO, false);
   proc->SetPreExecCallback(base::Bind(&SetupChild, env, flags));
 
-  LOG(INFO) << "Running \"" << base::JoinString(cmd, " ") << "\"";
+  LOG(INFO) << "Running \"" << android::base::Join(cmd, " ") << "\"";
   return proc->Start();
 }
 
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 2328693..2a8be94 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -31,7 +31,6 @@
 #if BASE_VER < 780000  // Android
 #include <base/message_loop/message_loop.h>
 #endif  // BASE_VER < 780000
-#include <base/strings/string_util.h>
 #include <android-base/stringprintf.h>
 #if BASE_VER >= 780000  // Chrome OS
 #include <base/task/single_thread_task_executor.h>
diff --git a/common/utils.cc b/common/utils.cc
index 180c7b4..bd33eca 100644
--- a/common/utils.cc
+++ b/common/utils.cc
@@ -52,7 +52,7 @@
 #include <base/rand_util.h>
 #include <base/strings/string_number_conversions.h>
 #include <base/strings/string_split.h>
-#include <base/strings/string_util.h>
+#include <android-base/stringprintf.h>
 #include <brillo/data_encoding.h>
 
 #include "update_engine/common/constants.h"
@@ -370,7 +370,7 @@
 }
 
 off_t FileSize(int fd) {
-  struct stat stbuf{};
+  struct stat stbuf {};
   int rc = fstat(fd, &stbuf);
   CHECK_EQ(rc, 0);
   if (rc < 0) {
@@ -587,17 +587,17 @@
 }
 
 bool FileExists(const char* path) {
-  struct stat stbuf{};
+  struct stat stbuf {};
   return 0 == lstat(path, &stbuf);
 }
 
 bool IsSymlink(const char* path) {
-  struct stat stbuf{};
+  struct stat stbuf {};
   return lstat(path, &stbuf) == 0 && S_ISLNK(stbuf.st_mode) != 0;
 }
 
 bool IsRegFile(const char* path) {
-  struct stat stbuf{};
+  struct stat stbuf {};
   return lstat(path, &stbuf) == 0 && S_ISREG(stbuf.st_mode) != 0;
 }
 
@@ -752,7 +752,8 @@
 }
 
 bool IsMountpoint(const std::string& mountpoint) {
-  struct stat stdir{}, stparent{};
+  struct stat stdir {
+  }, stparent{};
 
   // Check whether the passed mountpoint is a directory and the /.. is in the
   // same device or not. If mountpoint/.. is in a different device it means that
@@ -1196,7 +1197,7 @@
 }
 
 string GetTimeAsString(time_t utime) {
-  struct tm tm{};
+  struct tm tm {};
   CHECK_EQ(localtime_r(&utime, &tm), &tm);
   char str[16];
   CHECK_EQ(strftime(str, sizeof(str), "%Y%m%d-%H%M%S", &tm), 15u);
diff --git a/common/utils.h b/common/utils.h
index 1d8de85..52665d3 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -562,6 +562,15 @@
 
 bool GetTempName(const std::string& path, base::FilePath* template_path);
 
+template <typename String>
+std::string ToLower(const String& str) {
+  auto copy = std::string(str);
+  std::transform(str.begin(), str.end(), copy.begin(), [](unsigned char c) {
+    return std::tolower(c);
+  });
+  return copy;
+}
+
 }  // namespace chromeos_update_engine
 
 #define TEST_AND_RETURN_FALSE_ERRNO(_x)                             \