diff options
author | 2024-05-21 15:06:29 -0700 | |
---|---|---|
committer | 2024-06-27 12:04:32 -0700 | |
commit | 1d46f58320055b7aad551b92827bf3405258f25e (patch) | |
tree | c32caea58d088c49f3a1a51d8b880717fb9694d1 /libs/binder/IServiceManager.cpp | |
parent | 5e1cbe06681051d7e121364b36469acbdb24fdbe (diff) |
Migrate from libutils SystemClock.h to std::chrono
Bug: 341997808
Test: mma
Change-Id: Ib4d60eeaaac73566cc79d473f6551e9abd20e69a
Diffstat (limited to 'libs/binder/IServiceManager.cpp')
-rw-r--r-- | libs/binder/IServiceManager.cpp | 31 |
1 files changed, 17 insertions, 14 deletions
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index 5844c85d21..50d00ae2f2 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -21,6 +21,7 @@ #include <inttypes.h> #include <unistd.h> +#include <chrono> #include <condition_variable> #include <android-base/properties.h> @@ -30,7 +31,6 @@ #include <binder/Parcel.h> #include <utils/Log.h> #include <utils/String8.h> -#include <utils/SystemClock.h> #ifndef __ANDROID_VNDK__ #include <binder/IPermissionController.h> @@ -48,9 +48,12 @@ #endif #include "Static.h" +#include "Utils.h" namespace android { +using namespace std::chrono_literals; + using AidlRegistrationCallback = IServiceManager::LocalRegistrationCallback; using AidlServiceManager = android::os::IServiceManager; @@ -194,16 +197,16 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid, bool logP pc = gPermissionController; gPermissionControllerLock.unlock(); - int64_t startTime = 0; + auto startTime = std::chrono::steady_clock::now().min(); while (true) { if (pc != nullptr) { bool res = pc->checkPermission(permission, pid, uid); if (res) { - if (startTime != 0) { - ALOGI("Check passed after %d seconds for %s from uid=%d pid=%d", - (int)((uptimeMillis() - startTime) / 1000), String8(permission).c_str(), - uid, pid); + if (startTime != startTime.min()) { + const auto waitTime = std::chrono::steady_clock::now() - startTime; + ALOGI("Check passed after %" PRIu64 "ms for %s from uid=%d pid=%d", + to_ms(waitTime), String8(permission).c_str(), uid, pid); } return res; } @@ -229,8 +232,8 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid, bool logP sp<IBinder> binder = defaultServiceManager()->checkService(_permission); if (binder == nullptr) { // Wait for the permission controller to come back... - if (startTime == 0) { - startTime = uptimeMillis(); + if (startTime == startTime.min()) { + startTime = std::chrono::steady_clock::now(); ALOGI("Waiting to check permission %s from uid=%d pid=%d", String8(permission).c_str(), uid, pid); } @@ -287,8 +290,8 @@ sp<IBinder> ServiceManagerShim::getService(const String16& name) const const bool isVendorService = strcmp(ProcessState::self()->getDriverName().c_str(), "/dev/vndbinder") == 0; - constexpr int64_t timeout = 5000; - int64_t startTime = uptimeMillis(); + constexpr auto timeout = 5s; + const auto startTime = std::chrono::steady_clock::now(); // Vendor code can't access system properties if (!gSystemBootCompleted && !isVendorService) { #ifdef __ANDROID__ @@ -306,15 +309,16 @@ sp<IBinder> ServiceManagerShim::getService(const String16& name) const ProcessState::self()->getDriverName().c_str()); int n = 0; - while (uptimeMillis() - startTime < timeout) { + while (std::chrono::steady_clock::now() - startTime < timeout) { n++; usleep(1000*sleepTime); sp<IBinder> svc = checkService(name); if (svc != nullptr) { - ALOGI("Waiting for service '%s' on '%s' successful after waiting %" PRIi64 "ms", + const auto waitTime = std::chrono::steady_clock::now() - startTime; + ALOGI("Waiting for service '%s' on '%s' successful after waiting %" PRIu64 "ms", String8(name).c_str(), ProcessState::self()->getDriverName().c_str(), - uptimeMillis() - startTime); + to_ms(waitTime)); return svc; } } @@ -416,7 +420,6 @@ sp<IBinder> ServiceManagerShim::waitForService(const String16& name16) // that another thread serves the callback, and we never get a // command, so we hang indefinitely. std::unique_lock<std::mutex> lock(waiter->mMutex); - using std::literals::chrono_literals::operator""s; waiter->mCv.wait_for(lock, 1s, [&] { return waiter->mBinder != nullptr; }); |