Move to modern utility methods from android::base.

Moves away from crufty char* operations to std::string utility
methods, including android::base methods for splitting/parsing.

Rewrite of how Process handles scanning procfs for filesystem
references; now uses fts(3) for more sane traversal.

Replace sscanf() with new FindValue() method, also has unit tests.

Remove some unused methods.  Switch almost everyone over to using
modern logging library.

Test: cts-tradefed run commandAndExit cts-dev -m CtsOsTestCases -t android.os.storage.cts.StorageManagerTest
Test: cts-tradefed run commandAndExit cts-dev --abi armeabi-v7a -m CtsAppSecurityHostTestCases -t android.appsecurity.cts.AdoptableHostTest
Bug: 67041047
Change-Id: I70dc512f21459d1e25b187f24289002b2c7bc7af
diff --git a/model/Disk.cpp b/model/Disk.cpp
index 5b0c981..291c2e1 100644
--- a/model/Disk.cpp
+++ b/model/Disk.cpp
@@ -26,6 +26,8 @@
 #include <android-base/logging.h>
 #include <android-base/properties.h>
 #include <android-base/stringprintf.h>
+#include <android-base/strings.h>
+#include <android-base/parseint.h>
 #include <diskconfig/diskconfig.h>
 #include <ext4_utils/ext4_crypt.h>
 
@@ -263,7 +265,11 @@
             PLOG(WARNING) << "Failed to read manufacturer from " << path;
             return -errno;
         }
-        uint64_t manfid = strtoll(tmp.c_str(), nullptr, 16);
+        int64_t manfid;
+        if (!android::base::ParseInt(tmp, &manfid)) {
+            PLOG(WARNING) << "Failed to parse manufacturer " << tmp;
+            return -EINVAL;
+        }
         // Our goal here is to give the user a meaningful label, ideally
         // matching whatever is silk-screened on the card.  To reduce
         // user confusion, this list doesn't contain white-label manfid.
@@ -295,7 +301,7 @@
 }
 
 status_t Disk::readPartitions() {
-    int8_t maxMinors = getMaxMinors();
+    int maxMinors = getMaxMinors();
     if (maxMinors < 0) {
         return -ENOTSUP;
     }
@@ -324,31 +330,40 @@
     Table table = Table::kUnknown;
     bool foundParts = false;
     for (const auto& line : output) {
-        char* cline = (char*) line.c_str();
-        char* token = strtok(cline, kSgdiskToken);
-        if (token == nullptr) continue;
+        auto split = android::base::Split(line, kSgdiskToken);
+        auto it = split.begin();
+        if (it == split.end()) continue;
 
-        if (!strcmp(token, "DISK")) {
-            const char* type = strtok(nullptr, kSgdiskToken);
-            if (!strcmp(type, "mbr")) {
+        if (*it == "DISK") {
+            if (++it == split.end()) continue;
+            if (*it == "mbr") {
                 table = Table::kMbr;
-            } else if (!strcmp(type, "gpt")) {
+            } else if (*it == "gpt") {
                 table = Table::kGpt;
+            } else {
+                LOG(WARNING) << "Invalid partition table " << *it;
+                continue;
             }
-        } else if (!strcmp(token, "PART")) {
+        } else if (*it == "PART") {
             foundParts = true;
-            int i = strtol(strtok(nullptr, kSgdiskToken), nullptr, 10);
-            if (i <= 0 || i > maxMinors) {
-                LOG(WARNING) << mId << " is ignoring partition " << i
-                        << " beyond max supported devices";
+
+            if (++it == split.end()) continue;
+            int i = 0;
+            if (!android::base::ParseInt(*it, &i, 1, maxMinors)) {
+                LOG(WARNING) << "Invalid partition number " << *it;
                 continue;
             }
             dev_t partDevice = makedev(major(mDevice), minor(mDevice) + i);
 
             if (table == Table::kMbr) {
-                const char* type = strtok(nullptr, kSgdiskToken);
+                if (++it == split.end()) continue;
+                int type = 0;
+                if (!android::base::ParseInt("0x" + *it, &type)) {
+                    LOG(WARNING) << "Invalid partition type " << *it;
+                    continue;
+                }
 
-                switch (strtol(type, nullptr, 16)) {
+                switch (type) {
                 case 0x06: // FAT16
                 case 0x0b: // W95 FAT32 (LBA)
                 case 0x0c: // W95 FAT32 (LBA)
@@ -357,12 +372,14 @@
                     break;
                 }
             } else if (table == Table::kGpt) {
-                const char* typeGuid = strtok(nullptr, kSgdiskToken);
-                const char* partGuid = strtok(nullptr, kSgdiskToken);
+                if (++it == split.end()) continue;
+                auto typeGuid = *it;
+                if (++it == split.end()) continue;
+                auto partGuid = *it;
 
-                if (!strcasecmp(typeGuid, kGptBasicData)) {
+                if (android::base::EqualsIgnoreCase(typeGuid, kGptBasicData)) {
                     createPublicVolume(partDevice);
-                } else if (!strcasecmp(typeGuid, kGptAndroidExpand)) {
+                } else if (android::base::EqualsIgnoreCase(typeGuid, kGptAndroidExpand)) {
                     createPrivateVolume(partDevice, partGuid);
                 }
             }
@@ -375,7 +392,7 @@
 
         std::string fsType;
         std::string unused;
-        if (ReadMetadataUntrusted(mDevPath, fsType, unused, unused) == OK) {
+        if (ReadMetadataUntrusted(mDevPath, &fsType, &unused, &unused) == OK) {
             createPublicVolume(mDevice);
         } else {
             LOG(WARNING) << mId << " failed to identify, giving up";
diff --git a/model/PrivateVolume.cpp b/model/PrivateVolume.cpp
index 3152313..48d041b 100644
--- a/model/PrivateVolume.cpp
+++ b/model/PrivateVolume.cpp
@@ -53,7 +53,7 @@
 }
 
 status_t PrivateVolume::readMetadata() {
-    status_t res = ReadMetadata(mDmDevPath, mFsType, mFsUuid, mFsLabel);
+    status_t res = ReadMetadata(mDmDevPath, &mFsType, &mFsUuid, &mFsLabel);
 
     auto listener = getListener();
     if (listener) listener->onVolumeMetadataChanged(getId(), mFsType, mFsUuid, mFsLabel);
diff --git a/model/PublicVolume.cpp b/model/PublicVolume.cpp
index f80f59e..98c897f 100644
--- a/model/PublicVolume.cpp
+++ b/model/PublicVolume.cpp
@@ -52,7 +52,7 @@
 }
 
 status_t PublicVolume::readMetadata() {
-    status_t res = ReadMetadataUntrusted(mDevPath, mFsType, mFsUuid, mFsLabel);
+    status_t res = ReadMetadataUntrusted(mDevPath, &mFsType, &mFsUuid, &mFsLabel);
 
     auto listener = getListener();
     if (listener) listener->onVolumeMetadataChanged(getId(), mFsType, mFsUuid, mFsLabel);