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

Commit e234bf30 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10783763 from ee345caa to udc-qpr1-release

Change-Id: I373de06429cd0f187d75296b67f9ed9ee042a564
parents 4ca409a4 ee345caa
Loading
Loading
Loading
Loading
+9 −0
Original line number Original line Diff line number Diff line
@@ -1044,6 +1044,15 @@ void CCodecBufferChannel::trackReleasedFrame(const IGraphicBufferProducer::Queue
    if (desiredRenderTimeNs < nowNs) {
    if (desiredRenderTimeNs < nowNs) {
        desiredRenderTimeNs = nowNs;
        desiredRenderTimeNs = nowNs;
    }
    }

    // If the render time is more than a second from now, then pretend the frame is supposed to be
    // rendered immediately, because that's what SurfaceFlinger heuristics will do. This is a tight
    // coupling, but is really the only way to optimize away unnecessary present fence checks in
    // processRenderedFrames.
    if (desiredRenderTimeNs > nowNs + 1*1000*1000*1000LL) {
        desiredRenderTimeNs = nowNs;
    }

    // We've just queued a frame to the surface, so keep track of it and later check to see if it is
    // We've just queued a frame to the surface, so keep track of it and later check to see if it is
    // actually rendered.
    // actually rendered.
    TrackedFrame frame;
    TrackedFrame frame;
+9 −0
Original line number Original line Diff line number Diff line
@@ -1592,6 +1592,15 @@ void ACodec::trackReleasedFrame(int64_t frameId, int64_t mediaTimeUs, int64_t de
    if (desiredRenderTimeNs < nowNs) {
    if (desiredRenderTimeNs < nowNs) {
        desiredRenderTimeNs = nowNs;
        desiredRenderTimeNs = nowNs;
    }
    }

    // If the render time is more than a second from now, then pretend the frame is supposed to be
    // rendered immediately, because that's what SurfaceFlinger heuristics will do. This is a tight
    // coupling, but is really the only way to optimize away unnecessary present fence checks in
    // processRenderedFrames.
    if (desiredRenderTimeNs > nowNs + 1*1000*1000*1000LL) {
        desiredRenderTimeNs = nowNs;
    }

    // We've just queued a frame to the surface, so keep track of it and later check to see if it is
    // We've just queued a frame to the surface, so keep track of it and later check to see if it is
    // actually rendered.
    // actually rendered.
    TrackedFrame frame;
    TrackedFrame frame;
+62 −40
Original line number Original line Diff line number Diff line
@@ -817,10 +817,9 @@ void CameraService::remapCameraIds(const TCameraIdRemapping& cameraIdRemapping)
    std::unique_ptr<AutoConditionLock> serviceLockWrapper =
    std::unique_ptr<AutoConditionLock> serviceLockWrapper =
            AutoConditionLock::waitAndAcquire(mServiceLockWrapper);
            AutoConditionLock::waitAndAcquire(mServiceLockWrapper);


    Mutex::Autolock lock(mCameraIdRemappingLock);
    // Collect all existing clients for camera Ids that are being
    // This will disconnect all existing clients for camera Ids that are being
    // remapped in the new cameraIdRemapping, but only if they were being used by a
    // remapped in cameraIdRemapping, but only if they were being used by an
    // targeted packageName.
    // affected packageName.
    std::vector<sp<BasicClient>> clientsToDisconnect;
    std::vector<sp<BasicClient>> clientsToDisconnect;
    std::vector<String8> cameraIdsToUpdate;
    std::vector<String8> cameraIdsToUpdate;
    for (const auto& [packageName, injectionMap] : cameraIdRemapping) {
    for (const auto& [packageName, injectionMap] : cameraIdRemapping) {
@@ -831,7 +830,8 @@ void CameraService::remapCameraIds(const TCameraIdRemapping& cameraIdRemapping)
            if (clientDescriptor != nullptr) {
            if (clientDescriptor != nullptr) {
                sp<BasicClient> clientSp = clientDescriptor->getValue();
                sp<BasicClient> clientSp = clientDescriptor->getValue();
                if (clientSp->getPackageName() == packageName) {
                if (clientSp->getPackageName() == packageName) {
                    // This camera ID is being used by the affected packageName.
                    // This camera is being used by a targeted packageName and
                    // being remapped to a new camera Id. We should disconnect it.
                    clientsToDisconnect.push_back(clientSp);
                    clientsToDisconnect.push_back(clientSp);
                    cameraIdsToUpdate.push_back(id0);
                    cameraIdsToUpdate.push_back(id0);
                }
                }
@@ -839,25 +839,40 @@ void CameraService::remapCameraIds(const TCameraIdRemapping& cameraIdRemapping)
        }
        }
    }
    }


    // Update mCameraIdRemapping.
    for (auto& clientSp : clientsToDisconnect) {
    mCameraIdRemapping.clear();
        // We send up ERROR_CAMERA_DEVICE so that the app attempts to reconnect
    mCameraIdRemapping.insert(cameraIdRemapping.begin(), cameraIdRemapping.end());
        // automatically. Note that this itself can cause clientSp->disconnect() based on the
        // app's response.
        clientSp->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
                CaptureResultExtras{});
    }


    // Do not hold mServiceLock while disconnecting clients, but retain the condition
    // Do not hold mServiceLock while disconnecting clients, but retain the condition
    // blocking other clients from connecting in mServiceLockWrapper if held.
    // blocking other clients from connecting in mServiceLockWrapper if held.
    mServiceLock.unlock();
    mServiceLock.unlock();


    // Clear calling identity for disconnect() PID checks.
    int64_t token = CameraThreadState::clearCallingIdentity();

    // Disconnect clients.
    // Disconnect clients.
    for (auto& clientSp : clientsToDisconnect) {
    for (auto& clientSp : clientsToDisconnect) {
        // We send up ERROR_CAMERA_DEVICE so that the app attempts to reconnect
        // This also triggers a call to updateStatus() which also reads mCameraIdRemapping
        // automatically.
        // and requires mCameraIdRemappingLock.
        clientSp->notifyError(hardware::camera2::ICameraDeviceCallbacks::ERROR_CAMERA_DEVICE,
                CaptureResultExtras{});
        // This also triggers the status updates
        clientSp->disconnect();
        clientSp->disconnect();
    }
    }


    // Invoke destructors (which call disconnect()) now while we don't hold the mServiceLock.
    clientsToDisconnect.clear();

    CameraThreadState::restoreCallingIdentity(token);
    mServiceLock.lock();
    mServiceLock.lock();

    {
        Mutex::Autolock lock(mCameraIdRemappingLock);
        // Update mCameraIdRemapping.
        mCameraIdRemapping.clear();
        mCameraIdRemapping.insert(cameraIdRemapping.begin(), cameraIdRemapping.end());
    }
}
}


std::vector<String8> CameraService::findOriginalIdsForRemappedCameraId(
std::vector<String8> CameraService::findOriginalIdsForRemappedCameraId(
@@ -876,28 +891,27 @@ std::vector<String8> CameraService::findOriginalIdsForRemappedCameraId(
    return cameraIds;
    return cameraIds;
}
}


String8 CameraService::resolveCameraId(const String8& inputCameraId) {
  return resolveCameraId(inputCameraId, String16(""));
}

String8 CameraService::resolveCameraId(
String8 CameraService::resolveCameraId(
    const String8& inputCameraId,
    const String8& inputCameraId,
    int clientUid,
    const String16& packageName) {
    const String16& packageName) {
    String16 packageNameVal = packageName;
    String16 packageNameVal = packageName;
    if (packageName == String16("")) {
    if (packageName == String16("")) {
        int clientUid = CameraThreadState::getCallingUid();
        packageNameVal = getPackageNameFromUid(clientUid);
        packageNameVal = getPackageNameFromUid(clientUid);
    }
    }
    if (clientUid < AID_APP_START || packageNameVal == String16("")) {
        // We shouldn't remap cameras for processes with system/vendor UIDs.
        return inputCameraId;
    }
    Mutex::Autolock lock(mCameraIdRemappingLock);
    Mutex::Autolock lock(mCameraIdRemappingLock);
    if (auto packageMapIter = mCameraIdRemapping.find(packageNameVal);
    if (auto packageMapIter = mCameraIdRemapping.find(packageNameVal);
        packageMapIter != mCameraIdRemapping.end()) {
        packageMapIter != mCameraIdRemapping.end()) {
        ALOGI("%s: resolveCameraId: packageName found %s",
                __FUNCTION__, String8(packageNameVal).c_str());
        auto packageMap = packageMapIter->second;
        auto packageMap = packageMapIter->second;
        if (auto replacementIdIter = packageMap.find(inputCameraId);
        if (auto replacementIdIter = packageMap.find(inputCameraId);
            replacementIdIter != packageMap.end()) {
            replacementIdIter != packageMap.end()) {
            ALOGI("%s: resolveCameraId: inputId found %s, replacing with %s",
            ALOGI("%s: resolveCameraId: remapping cameraId %s for %s to %s",
                    __FUNCTION__, inputCameraId.c_str(),
                    __FUNCTION__, inputCameraId.c_str(),
                    String8(packageNameVal).c_str(),
                    replacementIdIter->second.c_str());
                    replacementIdIter->second.c_str());
            return replacementIdIter->second;
            return replacementIdIter->second;
        }
        }
@@ -909,7 +923,12 @@ Status CameraService::getCameraInfo(int cameraId, bool overrideToPortrait,
        CameraInfo* cameraInfo) {
        CameraInfo* cameraInfo) {
    ATRACE_CALL();
    ATRACE_CALL();
    Mutex::Autolock l(mServiceLock);
    Mutex::Autolock l(mServiceLock);
    std::string cameraIdStr = cameraIdIntToStrLocked(cameraId);

    std::string unresolvedCameraId = cameraIdIntToStrLocked(cameraId);
    std::string cameraIdStr = resolveCameraId(
            String8(unresolvedCameraId.c_str()),
            CameraThreadState::getCallingUid()).string();

    if (shouldRejectSystemCameraConnection(String8(cameraIdStr.c_str()))) {
    if (shouldRejectSystemCameraConnection(String8(cameraIdStr.c_str()))) {
        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION, "Unable to retrieve camera"
        return STATUS_ERROR_FMT(ERROR_INVALID_OPERATION, "Unable to retrieve camera"
                "characteristics for system only device %s: ", cameraIdStr.c_str());
                "characteristics for system only device %s: ", cameraIdStr.c_str());
@@ -978,7 +997,8 @@ String8 CameraService::cameraIdIntToStr(int cameraIdInt) {
Status CameraService::getCameraCharacteristics(const String16& unresolvedCameraId,
Status CameraService::getCameraCharacteristics(const String16& unresolvedCameraId,
        int targetSdkVersion, bool overrideToPortrait, CameraMetadata* cameraInfo) {
        int targetSdkVersion, bool overrideToPortrait, CameraMetadata* cameraInfo) {
    ATRACE_CALL();
    ATRACE_CALL();
    String8 cameraId = resolveCameraId(String8(unresolvedCameraId));
    String8 cameraId = resolveCameraId(String8(unresolvedCameraId),
            CameraThreadState::getCallingUid());
    if (!cameraInfo) {
    if (!cameraInfo) {
        ALOGE("%s: cameraInfo is NULL", __FUNCTION__);
        ALOGE("%s: cameraInfo is NULL", __FUNCTION__);
        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "cameraInfo is NULL");
        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "cameraInfo is NULL");
@@ -1064,9 +1084,11 @@ Status CameraService::getCameraCharacteristics(const String16& unresolvedCameraI
    return ret;
    return ret;
}
}


Status CameraService::getTorchStrengthLevel(const String16& cameraId,
Status CameraService::getTorchStrengthLevel(const String16& unresolvedCameraId,
        int32_t* torchStrength) {
        int32_t* torchStrength) {
    ATRACE_CALL();
    ATRACE_CALL();
    String8 cameraId = resolveCameraId(String8(unresolvedCameraId),
            CameraThreadState::getCallingUid());
    Mutex::Autolock l(mServiceLock);
    Mutex::Autolock l(mServiceLock);
    if (!mInitialized) {
    if (!mInitialized) {
        ALOGE("%s: Camera HAL couldn't be initialized.", __FUNCTION__);
        ALOGE("%s: Camera HAL couldn't be initialized.", __FUNCTION__);
@@ -1343,7 +1365,9 @@ Status CameraService::getLegacyParametersLazy(int cameraId,
        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
        return STATUS_ERROR(ERROR_ILLEGAL_ARGUMENT, "Parameters must not be null");
    }
    }


    String8 id = String8::format("%d", cameraId);
    String8 unresolvedCameraId = String8::format("%d", cameraId);
    String8 id = resolveCameraId(unresolvedCameraId,
            CameraThreadState::getCallingUid());


    // Check if we already have parameters
    // Check if we already have parameters
    {
    {
@@ -1855,7 +1879,9 @@ Status CameraService::connect(
    ATRACE_CALL();
    ATRACE_CALL();
    Status ret = Status::ok();
    Status ret = Status::ok();


    String8 id = cameraIdIntToStr(api1CameraId);
    String8 unresolvedCameraId = cameraIdIntToStr(api1CameraId);
    String8 id = resolveCameraId(unresolvedCameraId, CameraThreadState::getCallingUid());

    sp<Client> client = nullptr;
    sp<Client> client = nullptr;
    ret = connectHelper<ICameraClient,Client>(cameraClient, id, api1CameraId,
    ret = connectHelper<ICameraClient,Client>(cameraClient, id, api1CameraId,
            clientPackageName,/*systemNativeClient*/ false, {}, clientUid, clientPid, API_1,
            clientPackageName,/*systemNativeClient*/ false, {}, clientUid, clientPid, API_1,
@@ -1950,7 +1976,6 @@ Status CameraService::connectDevice(


    ATRACE_CALL();
    ATRACE_CALL();
    Status ret = Status::ok();
    Status ret = Status::ok();
    String8 id = resolveCameraId(String8(unresolvedCameraId), clientPackageName);
    sp<CameraDeviceClient> client = nullptr;
    sp<CameraDeviceClient> client = nullptr;
    String16 clientPackageNameAdj = clientPackageName;
    String16 clientPackageNameAdj = clientPackageName;
    int callingPid = CameraThreadState::getCallingPid();
    int callingPid = CameraThreadState::getCallingPid();
@@ -1962,6 +1987,10 @@ Status CameraService::connectDevice(
        systemNativeClient = true;
        systemNativeClient = true;
    }
    }


    String8 id = resolveCameraId(String8(unresolvedCameraId),
            CameraThreadState::getCallingUid(),
            clientPackageNameAdj);

    if (oomScoreOffset < 0) {
    if (oomScoreOffset < 0) {
        String8 msg =
        String8 msg =
                String8::format("Cannot increase the priority of a client %s pid %d for "
                String8::format("Cannot increase the priority of a client %s pid %d for "
@@ -2453,8 +2482,8 @@ Status CameraService::turnOnTorchWithStrengthLevel(const String16& unresolvedCam
                "Torch client binder in null.");
                "Torch client binder in null.");
    }
    }


    String8 id = resolveCameraId(String8(unresolvedCameraId));
    int uid = CameraThreadState::getCallingUid();
    int uid = CameraThreadState::getCallingUid();
    String8 id = resolveCameraId(String8(unresolvedCameraId), uid);


    if (shouldRejectSystemCameraConnection(id)) {
    if (shouldRejectSystemCameraConnection(id)) {
        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to change the strength level"
        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to change the strength level"
@@ -2584,8 +2613,8 @@ Status CameraService::setTorchMode(const String16& unresolvedCameraId,
                "Torch client Binder is null");
                "Torch client Binder is null");
    }
    }


    String8 id = resolveCameraId(String8(unresolvedCameraId));
    int uid = CameraThreadState::getCallingUid();
    int uid = CameraThreadState::getCallingUid();
    String8 id = resolveCameraId(String8(unresolvedCameraId), uid);


    if (shouldRejectSystemCameraConnection(id)) {
    if (shouldRejectSystemCameraConnection(id)) {
        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to set torch mode"
        return STATUS_ERROR_FMT(ERROR_ILLEGAL_ARGUMENT, "Unable to set torch mode"
@@ -3113,16 +3142,8 @@ Status CameraService::supportsCameraApi(const String16& unresolvedCameraId, int
        /*out*/ bool *isSupported) {
        /*out*/ bool *isSupported) {
    ATRACE_CALL();
    ATRACE_CALL();


    String8 resolvedId;
    const String8 id = resolveCameraId(String8(unresolvedCameraId),
    if (apiVersion == API_VERSION_2) {
            CameraThreadState::getCallingUid());
        resolvedId = resolveCameraId(String8(unresolvedCameraId));
    } else { // if (apiVersion == API_VERSION_1)
        // We don't support remapping for API 1.
        // TODO(b/286287541): Also support remapping for API 1.
        resolvedId = String8(unresolvedCameraId);
    }

    const String8 id = resolvedId;


    ALOGV("%s: for camera ID = %s", __FUNCTION__, id.string());
    ALOGV("%s: for camera ID = %s", __FUNCTION__, id.string());


@@ -3186,7 +3207,8 @@ Status CameraService::isHiddenPhysicalCamera(const String16& unresolvedCameraId,
        /*out*/ bool *isSupported) {
        /*out*/ bool *isSupported) {
    ATRACE_CALL();
    ATRACE_CALL();


    const String8 id = resolveCameraId(String8(unresolvedCameraId));
    const String8 id = resolveCameraId(String8(unresolvedCameraId),
            CameraThreadState::getCallingUid());


    ALOGV("%s: for camera ID = %s", __FUNCTION__, id.string());
    ALOGV("%s: for camera ID = %s", __FUNCTION__, id.string());
    *isSupported = mCameraProviderManager->isHiddenPhysicalCamera(id.string());
    *isSupported = mCameraProviderManager->isHiddenPhysicalCamera(id.string());
+5 −7
Original line number Original line Diff line number Diff line
@@ -972,15 +972,13 @@ private:
     *
     *
     * This returns the Camera Id to use in case inputCameraId was remapped to a
     * This returns the Camera Id to use in case inputCameraId was remapped to a
     * different Id for the given packageName. Otherwise, it returns the inputCameraId.
     * different Id for the given packageName. Otherwise, it returns the inputCameraId.
     */
    String8 resolveCameraId(const String8& inputCameraId, const String16& packageName);
    /**
     * Resolve the (potentially remapped) camera Id to use.
     *
     *
     * This returns the Camera Id to use in case inputCameraId was remapped to a
     * If the packageName is not provided, it will be inferred from the clientUid.
     * different Id for the packageName of the client. Otherwise, it returns the inputCameraId.
     */
     */
    String8 resolveCameraId(const String8& inputCameraId);
    String8 resolveCameraId(
            const String8& inputCameraId,
            int clientUid,
            const String16& packageName = String16(""));


    /**
    /**
     * Updates the state of mCameraIdRemapping, while disconnecting active clients as necessary.
     * Updates the state of mCameraIdRemapping, while disconnecting active clients as necessary.