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

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

Snap for 9358956 from 15d9586c to tm-qpr2-release

Change-Id: I5274dd3de5497f775c74524fb58afd0201f96119
parents b463442d 15d9586c
Loading
Loading
Loading
Loading
+27 −13
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ using android::base::StringAppendF;

// Identifier to use for our event queue on the loop.
// The number 19 is arbitrary, only useful if using multiple objects on the same looper.
// Note: Instead of a fixed number, the SensorEventQueue's fd could be used instead.
constexpr int kIdent = 19;

static inline Looper* ALooper_to_Looper(ALooper* alooper) {
@@ -60,7 +61,8 @@ class EventQueueGuard {
    EventQueueGuard(const sp<SensorEventQueue>& queue, Looper* looper) : mQueue(queue) {
        mQueue->looper = Looper_to_ALooper(looper);
        mQueue->requestAdditionalInfo = false;
        looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT, nullptr, nullptr);
        looper->addFd(mQueue->getFd(), kIdent, ALOOPER_EVENT_INPUT,
                nullptr /* callback */, nullptr /* data */);
    }

    ~EventQueueGuard() {
@@ -75,7 +77,7 @@ class EventQueueGuard {
    [[nodiscard]] SensorEventQueue* get() const { return mQueue.get(); }

  private:
    sp<SensorEventQueue> mQueue;
    const sp<SensorEventQueue> mQueue;
};

/**
@@ -95,10 +97,7 @@ class SensorEnableGuard {
        }
    }

    SensorEnableGuard(const SensorEnableGuard&) = delete;
    SensorEnableGuard& operator=(const SensorEnableGuard&) = delete;

    // Enable moving.
    // Enable move and delete default copy-ctor/copy-assignment.
    SensorEnableGuard(SensorEnableGuard&& other) : mQueue(other.mQueue), mSensor(other.mSensor) {
        other.mSensor = SensorPoseProvider::INVALID_HANDLE;
    }
@@ -131,7 +130,7 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
        // Figure out the sensor's data format.
        DataFormat format = getSensorFormat(sensor);
        if (format == DataFormat::kUnknown) {
            ALOGE("Unknown format for sensor %" PRId32, sensor);
            ALOGE("%s: Unknown format for sensor %" PRId32, __func__, sensor);
            return false;
        }

@@ -145,17 +144,19 @@ class SensorPoseProviderImpl : public SensorPoseProvider {

        // Enable the sensor.
        if (mQueue->enableSensor(sensor, samplingPeriod.count(), 0, 0)) {
            ALOGE("Failed to enable sensor");
            ALOGE("%s: Failed to enable sensor %" PRId32, __func__, sensor);
            std::lock_guard lock(mMutex);
            mEnabledSensorsExtra.erase(sensor);
            return false;
        }

        mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue.get(), sensor));
        mEnabledSensors.emplace(sensor, SensorEnableGuard(mQueue, sensor));
        ALOGD("%s: Sensor %" PRId32 " started", __func__, sensor);
        return true;
    }

    void stopSensor(int handle) override {
        ALOGD("%s: Sensor %" PRId32 " stopped", __func__, handle);
        mEnabledSensors.erase(handle);
        std::lock_guard lock(mMutex);
        mEnabledSensorsExtra.erase(handle);
@@ -223,9 +224,9 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
    Listener* const mListener;
    SensorManager* const mSensorManager;
    std::timed_mutex mMutex;
    sp<SensorEventQueue> mQueue;
    std::map<int32_t, SensorEnableGuard> mEnabledSensors;
    std::map<int32_t, SensorExtra> mEnabledSensorsExtra GUARDED_BY(mMutex);
    sp<SensorEventQueue> mQueue;

    // We must do some of the initialization operations on the worker thread, because the API relies
    // on the thread-local looper. In addition, as a matter of convenience, we store some of the
@@ -246,7 +247,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
    bool waitInitFinished() { return mInitPromise.get_future().get(); }

    void threadFunc() {
        // Obtain looper.
        // Name our std::thread to help identification.  As is, canCallJava == false.
        androidSetThreadName("SensorPoseProvider-looper");

        // Run at the highest non-realtime priority.
        androidSetThreadPriority(gettid(), PRIORITY_URGENT_AUDIO);

        // The looper is started on the created std::thread.
        mLooper = Looper::prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);

        // Create event queue.
@@ -263,7 +270,8 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
        initFinished(true);

        while (!mQuit) {
            int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr, nullptr, nullptr);
            const int ret = mLooper->pollOnce(-1 /* no timeout */, nullptr /* outFd */,
                    nullptr /* outEvents */, nullptr /* outData */);

            switch (ret) {
                case ALOOPER_POLL_WAKE:
@@ -276,7 +284,13 @@ class SensorPoseProviderImpl : public SensorPoseProvider {
                    break;

                default:
                    ALOGE("Unexpected status out of Looper::pollOnce: %d", ret);
                    // Besides WAKE and kIdent, there should be no timeouts, callbacks,
                    // ALOOPER_POLL_ERROR, or other events.
                    // Exit now to avoid high frequency log spam on error,
                    // e.g. if the fd becomes invalid (b/31093485).
                    ALOGE("%s: Unexpected status out of Looper::pollOnce: %d", __func__, ret);
                    mQuit = true;
                    continue;
            }

            // Process an event.
+2 −0
Original line number Diff line number Diff line
@@ -1814,12 +1814,14 @@ void AudioPolicyService::UidPolicy::dumpInternals(int fd) {
void AudioPolicyService::SensorPrivacyPolicy::registerSelf() {
    SensorPrivacyManager spm;
    mSensorPrivacyEnabled = spm.isSensorPrivacyEnabled();
    (void)spm.addToggleSensorPrivacyListener(this);
    spm.addSensorPrivacyListener(this);
}

void AudioPolicyService::SensorPrivacyPolicy::unregisterSelf() {
    SensorPrivacyManager spm;
    spm.removeSensorPrivacyListener(this);
    spm.removeToggleSensorPrivacyListener(this);
}

bool AudioPolicyService::SensorPrivacyPolicy::isSensorPrivacyEnabled() {
+1 −1
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ void Spatializer::onFirstRef() {
    mLooper->start(
            /*runOnCallingThread*/false,
            /*canCallJava*/       false,
            PRIORITY_AUDIO);
            PRIORITY_URGENT_AUDIO);

    mHandler = new EngineCallbackHandler(this);
    mLooper->registerHandler(mHandler);
+25 −0
Original line number Diff line number Diff line
@@ -59,6 +59,8 @@ FrameProcessor::FrameProcessor(wp<CameraDeviceBase> device,
        m3aState.aeState = ANDROID_CONTROL_AE_STATE_INACTIVE;
        m3aState.afState = ANDROID_CONTROL_AF_STATE_INACTIVE;
        m3aState.awbState = ANDROID_CONTROL_AWB_STATE_INACTIVE;

        mLastFocalLength = l.mParameters.params.getFloat(CameraParameters::KEY_FOCAL_LENGTH);
    }
}

@@ -92,9 +94,32 @@ bool FrameProcessor::processSingleFrame(CaptureResult &frame,
        client->notifyRequestId(mCurrentRequestId);
    }

    processLensState(frame.mMetadata, client);

    return FrameProcessorBase::processSingleFrame(frame, device);
}

void FrameProcessor::processLensState(const CameraMetadata &frame,
        const sp<Camera2Client> &client) {
    ATRACE_CALL();
    camera_metadata_ro_entry_t entry;

    entry = frame.find(ANDROID_LENS_FOCAL_LENGTH);
    if (entry.count == 0) {
        return;
    }

    if (fabs(entry.data.f[0] - mLastFocalLength) > 0.001f) {
        SharedParameters::Lock l(client->getParameters());
        l.mParameters.params.setFloat(
                CameraParameters::KEY_FOCAL_LENGTH,
                entry.data.f[0]);
        l.mParameters.paramsFlattened = l.mParameters.params.flatten();

        mLastFocalLength = entry.data.f[0];
    }
}

status_t FrameProcessor::processFaceDetect(const CameraMetadata &frame,
        const sp<Camera2Client> &client) {
    status_t res = BAD_VALUE;
+6 −0
Original line number Diff line number Diff line
@@ -57,6 +57,9 @@ class FrameProcessor : public FrameProcessorBase {
    virtual bool processSingleFrame(CaptureResult &frame,
                                    const sp<FrameProducer> &device);

    void processLensState(const CameraMetadata &frame,
            const sp<Camera2Client> &client);

    status_t processFaceDetect(const CameraMetadata &frame,
            const sp<Camera2Client> &client);

@@ -110,6 +113,9 @@ class FrameProcessor : public FrameProcessorBase {
    // Emit FaceDetection event to java if faces changed
    void callbackFaceDetection(const sp<Camera2Client>& client,
                               const camera_frame_metadata &metadata);

    // Track most recent focal length sent by the camera device
    float mLastFocalLength;
};