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

Commit da519ab2 authored by Jyoti Bhayana's avatar Jyoti Bhayana
Browse files

Enable certain safety and time critical automotive use cases.

If processinfo service is not available and the client is automotive
privileged client used for safety critical uses cases such as
rear-view and surround-view which needs to be available before
android boot completes,then use the hardcoded values for the process
state and priority score.

Bug: 231557017
Test: Test using a simple camera2 ndk program which opens the camera and
capture a still image before android boot completes using uid
AID_AUTOMOTIVE_EVS.

Change-Id: I46bf93423f9a5704e74b467fbe8692dbfe9a5ce5
parent 3128fda9
Loading
Loading
Loading
Loading
+51 −36
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ namespace {
    const char* kActivityServiceName = "activity";
    const char* kSensorPrivacyServiceName = "sensor_privacy";
    const char* kAppopsServiceName = "appops";
    const char* kProcessInfoServiceName = "processinfo";
}; // namespace anonymous

namespace android {
@@ -1589,6 +1590,30 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien
            }
        }

        // Get state for the given cameraId
        auto state = getCameraState(cameraId);
        if (state == nullptr) {
            ALOGE("CameraService::connect X (PID %d) rejected (no camera device with ID %s)",
                clientPid, cameraId.string());
            // Should never get here because validateConnectLocked should have errored out
            return BAD_VALUE;
        }

        sp<IServiceManager> sm = defaultServiceManager();
        sp<IBinder> binder = sm->checkService(String16(kProcessInfoServiceName));
        if (!binder && isAutomotivePrivilegedClient(CameraThreadState::getCallingUid())) {
            // If processinfo service is not available and the client is automotive privileged
            // client used for safety critical uses cases such as rear-view and surround-view which
            // needs to be available before android boot completes, then use the hardcoded values
            // for the process state and priority score. As this scenario is before android system
            // services are up and client is native client, hence using NATIVE_ADJ as the priority
            // score and state as PROCESS_STATE_BOUND_TOP as such automotive apps need to be
            // visible on the top.
            clientDescriptor = CameraClientManager::makeClientDescriptor(cameraId,
                    sp<BasicClient>{nullptr}, static_cast<int32_t>(state->getCost()),
                    state->getConflicting(), resource_policy::NATIVE_ADJ, clientPid,
                    ActivityManager::PROCESS_STATE_BOUND_TOP, oomScoreOffset, systemNativeClient);
        } else {
            // Get current active client PIDs
            std::vector<int> ownerPids(mActiveClientManager.getAllOwners());
            ownerPids.push_back(clientPid);
@@ -1597,12 +1622,10 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien
            std::vector<int> states(ownerPids.size());

            // Get priority scores of all active PIDs
        status_t err = ProcessInfoService::getProcessStatesScoresFromPids(
                ownerPids.size(), &ownerPids[0], /*out*/&states[0],
                /*out*/&priorityScores[0]);
            status_t err = ProcessInfoService::getProcessStatesScoresFromPids(ownerPids.size(),
                    &ownerPids[0], /*out*/&states[0], /*out*/&priorityScores[0]);
            if (err != OK) {
            ALOGE("%s: Priority score query failed: %d",
                  __FUNCTION__, err);
                ALOGE("%s: Priority score query failed: %d", __FUNCTION__, err);
                return err;
            }

@@ -1616,15 +1639,6 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien
            }
            mActiveClientManager.updatePriorities(pidToPriorityMap);

        // Get state for the given cameraId
        auto state = getCameraState(cameraId);
        if (state == nullptr) {
            ALOGE("CameraService::connect X (PID %d) rejected (no camera device with ID %s)",
                clientPid, cameraId.string());
            // Should never get here because validateConnectLocked should have errored out
            return BAD_VALUE;
        }

            int32_t actualScore = priorityScores[priorityScores.size() - 1];
            int32_t actualState = states[states.size() - 1];

@@ -1635,6 +1649,7 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien
                    sp<BasicClient>{nullptr}, static_cast<int32_t>(state->getCost()),
                    state->getConflicting(), actualScore, clientPid, actualState,
                    oomScoreOffset, systemNativeClient);
        }

        resource_policy::ClientPriority clientPriority = clientDescriptor->getPriority();