Convert gsid to use the dynamic AIDL service infrastructure
Replace the original on demand start mechanism with the new dynamic
AIDL service infrastructure to resolve a possible race condition.
Bug: 149130673
Test: gsi_tool status
Merged-In: I141475b56191eb82efe222bf7522350fc66a7dac
Change-Id: I141475b56191eb82efe222bf7522350fc66a7dac
diff --git a/libgsid.cpp b/libgsid.cpp
index cfddb60..b42833c 100644
--- a/libgsid.cpp
+++ b/libgsid.cpp
@@ -17,54 +17,23 @@
#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android/gsi/IGsiService.h>
-#include <android/gsi/IGsid.h>
#include <binder/IServiceManager.h>
#include <libgsi/libgsi.h>
namespace android {
namespace gsi {
-using namespace std::chrono_literals;
using android::sp;
-static sp<IGsid> GetGsid() {
- if (android::base::GetProperty("init.svc.gsid", "") != "running") {
- if (!android::base::SetProperty("ctl.start", "gsid") ||
- !android::base::WaitForProperty("init.svc.gsid", "running", 5s)) {
- LOG(ERROR) << "Unable to start gsid";
- return nullptr;
- }
- }
-
- static const int kSleepTimeMs = 50;
- static const int kTotalWaitTimeMs = 3000;
- for (int i = 0; i < kTotalWaitTimeMs / kSleepTimeMs; i++) {
- auto sm = android::defaultServiceManager();
- auto name = android::String16(kGsiServiceName);
- android::sp<android::IBinder> res = sm->checkService(name);
- if (res) {
- return android::interface_cast<IGsid>(res);
- }
- usleep(kSleepTimeMs * 1000);
- }
-
- LOG(ERROR) << "Timed out trying to start gsid";
- return nullptr;
-}
-
sp<IGsiService> GetGsiService() {
- auto gsid = GetGsid();
- if (!gsid) {
- return nullptr;
+ auto sm = android::defaultServiceManager();
+ auto name = android::String16(kGsiServiceName);
+ android::sp<android::IBinder> res = sm->waitForService(name);
+ if (res) {
+ return android::interface_cast<IGsiService>(res);
}
-
- sp<IGsiService> service;
- auto status = gsid->getClient(&service);
- if (!status.isOk() || !service) {
- LOG(ERROR) << "Error acquiring IGsid: " << status.exceptionMessage().string();
- return nullptr;
- }
- return service;
+ LOG(ERROR) << "Unable to GetGsiService";
+ return nullptr;
}
} // namespace gsi