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

Commit 614b2afb authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Extend background app behavior for direct channel" into rvc-dev am:...

Merge "Extend background app behavior for direct channel" into rvc-dev am: 584ab0d9 am: 984ad327

Change-Id: I52f37e17c4730a73843ee930249818cab8959aea
parents 43d19397 984ad327
Loading
Loading
Loading
Loading
+17 −0
Original line number Original line Diff line number Diff line
@@ -93,6 +93,23 @@ sp<BitTube> SensorService::SensorDirectConnection::getSensorChannel() const {
    return nullptr;
    return nullptr;
}
}


void SensorService::SensorDirectConnection::updateSensorSubscriptions() {
    if (!hasSensorAccess()) {
        stopAll(true /* backupRecord */);
    } else {
        recoverAll();
    }
}

void SensorService::SensorDirectConnection::setSensorAccess(bool hasAccess) {
    mHasSensorAccess = hasAccess;
    updateSensorSubscriptions();
}

bool SensorService::SensorDirectConnection::hasSensorAccess() const {
    return mHasSensorAccess && !mService->mSensorPrivacyPolicy->isSensorPrivacyEnabled();
}

status_t SensorService::SensorDirectConnection::enableDisable(
status_t SensorService::SensorDirectConnection::enableDisable(
        int handle, bool enabled, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs,
        int handle, bool enabled, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs,
        int reservedFlags) {
        int reservedFlags) {
+6 −0
Original line number Original line Diff line number Diff line
@@ -54,6 +54,9 @@ public:
    // called by SensorService when return to NORMAL mode.
    // called by SensorService when return to NORMAL mode.
    void recoverAll();
    void recoverAll();


    void updateSensorSubscriptions();

    void setSensorAccess(bool hasAccess);
protected:
protected:
    virtual ~SensorDirectConnection();
    virtual ~SensorDirectConnection();
    // ISensorEventConnection functions
    // ISensorEventConnection functions
@@ -66,6 +69,7 @@ protected:
    virtual int32_t configureChannel(int handle, int rateLevel);
    virtual int32_t configureChannel(int handle, int rateLevel);
    virtual void destroy();
    virtual void destroy();
private:
private:
    bool hasSensorAccess() const;
    const sp<SensorService> mService;
    const sp<SensorService> mService;
    const uid_t mUid;
    const uid_t mUid;
    const sensors_direct_mem_t mMem;
    const sensors_direct_mem_t mMem;
@@ -76,6 +80,8 @@ private:
    std::unordered_map<int, int> mActivated;
    std::unordered_map<int, int> mActivated;
    std::unordered_map<int, int> mActivatedBackup;
    std::unordered_map<int, int> mActivatedBackup;


    std::atomic_bool mHasSensorAccess = true;

    mutable Mutex mDestroyLock;
    mutable Mutex mDestroyLock;
    bool mDestroyed;
    bool mDestroyed;
};
};
+9 −2
Original line number Original line Diff line number Diff line
@@ -302,6 +302,7 @@ void SensorService::onFirstRef() {
void SensorService::setSensorAccess(uid_t uid, bool hasAccess) {
void SensorService::setSensorAccess(uid_t uid, bool hasAccess) {
    ConnectionSafeAutolock connLock = mConnectionHolder.lock(mLock);
    ConnectionSafeAutolock connLock = mConnectionHolder.lock(mLock);
    const auto& connections = connLock.getActiveConnections();
    const auto& connections = connLock.getActiveConnections();
    const auto& directConnections = connLock.getDirectConnections();


    mLock.unlock();
    mLock.unlock();
    for (const sp<SensorEventConnection>& conn : connections) {
    for (const sp<SensorEventConnection>& conn : connections) {
@@ -309,6 +310,12 @@ void SensorService::setSensorAccess(uid_t uid, bool hasAccess) {
            conn->setSensorAccess(hasAccess);
            conn->setSensorAccess(hasAccess);
        }
        }
    }
    }

    for (const sp<SensorDirectConnection>& conn : directConnections) {
        if (conn->getUid() == uid) {
            conn->setSensorAccess(hasAccess);
        }
    }
}
}


const Sensor& SensorService::registerSensor(SensorInterface* s, bool isDebug, bool isVirtual) {
const Sensor& SensorService::registerSensor(SensorInterface* s, bool isDebug, bool isVirtual) {
@@ -645,7 +652,7 @@ void SensorService::disableAllSensorsLocked(ConnectionSafeAutolock* connLock) {
        connection->updateSensorSubscriptions();
        connection->updateSensorSubscriptions();
    }
    }
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
        connection->stopAll(true /* backupRecord */);
        connection->updateSensorSubscriptions();
    }
    }
    dev.disableAllSensors();
    dev.disableAllSensors();
    // Clear all pending flush connections for all active sensors. If one of the active
    // Clear all pending flush connections for all active sensors. If one of the active
@@ -676,7 +683,7 @@ void SensorService::enableAllSensorsLocked(ConnectionSafeAutolock* connLock) {
        connection->updateSensorSubscriptions();
        connection->updateSensorSubscriptions();
    }
    }
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
        connection->recoverAll();
        connection->updateSensorSubscriptions();
    }
    }
}
}