Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8d669dc1 authored by Yifei Zhang's avatar Yifei Zhang
Browse files

sensor_privacy: use waitForService instead of getService

Test: build & boot
Bug: 284487308
Change-Id: I462fb2f897e0b287c804d2afeac94976446fa66c
parent c9587bf7
Loading
Loading
Loading
Loading
+4 −19
Original line number Diff line number Diff line
@@ -32,27 +32,12 @@ SensorPrivacyManager::SensorPrivacyManager()
sp<hardware::ISensorPrivacyManager> SensorPrivacyManager::getService()
{
    std::lock_guard<Mutex> scoped_lock(mLock);
    int64_t startTime = 0;
    sp<hardware::ISensorPrivacyManager> service = mService;
    while (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
        sp<IBinder> binder = defaultServiceManager()->checkService(String16("sensor_privacy"));
        if (binder == nullptr) {
            // Wait for the sensor privacy service to come back...
            if (startTime == 0) {
                startTime = uptimeMillis();
                ALOGI("Waiting for sensor privacy service");
            } else if ((uptimeMillis() - startTime) > 1000000) {
                ALOGW("Waiting too long for sensor privacy service, giving up");
                service = nullptr;
                break;
            }
            usleep(25000);
        } else {
            service = interface_cast<hardware::ISensorPrivacyManager>(binder);
            mService = service;
        }
    }
    return service;
    if (service == nullptr || !IInterface::asBinder(service)->isBinderAlive()) {
      sp<IBinder> binder = defaultServiceManager()->waitForService(String16("sensor_privacy"));
      mService = interface_cast<hardware::ISensorPrivacyManager>(binder);
    }
    return mService;
}

bool SensorPrivacyManager::supportsSensorToggle(int toggleType, int sensor) {