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

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

Merge changes from topic "direct_uid_idle" into rvc-dev am: 283bb209 am:...

Merge changes from topic "direct_uid_idle" into rvc-dev am: 283bb209 am: d729c50f am: 07a23089

Change-Id: Iae442ada6910c4c93c90f6792ebd9cbfb4750fab
parents e8e7b1a3 07a23089
Loading
Loading
Loading
Loading
+35 −16
Original line number Diff line number Diff line
@@ -93,6 +93,18 @@ sp<BitTube> SensorService::SensorDirectConnection::getSensorChannel() const {
    return nullptr;
}

void SensorService::SensorDirectConnection::onSensorAccessChanged(bool hasAccess) {
    if (!hasAccess) {
        stopAll(true /* backupRecord */);
    } else {
        recoverAll();
    }
}

bool SensorService::SensorDirectConnection::hasSensorAccess() const {
    return mService->hasSensorAccess(mUid, mOpPackageName);
}

status_t SensorService::SensorDirectConnection::enableDisable(
        int handle, bool enabled, nsecs_t samplingPeriodNs, nsecs_t maxBatchReportLatencyNs,
        int reservedFlags) {
@@ -125,7 +137,7 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int
        return NO_ERROR;
    }

    if (!mService->isOperationPermitted(mOpPackageName)) {
    if (!hasSensorAccess()) {
        return PERMISSION_DENIED;
    }

@@ -169,12 +181,15 @@ int32_t SensorService::SensorDirectConnection::configureChannel(int handle, int
}

void SensorService::SensorDirectConnection::stopAll(bool backupRecord) {
    Mutex::Autolock _l(mConnectionLock);
    stopAllLocked(backupRecord);
}

void SensorService::SensorDirectConnection::stopAllLocked(bool backupRecord) {
    struct sensors_direct_cfg_t config = {
        .rate_level = SENSOR_DIRECT_RATE_STOP
    };

    Mutex::Autolock _l(mConnectionLock);
    SensorDevice& dev(SensorDevice::getInstance());
    for (auto &i : mActivated) {
        dev.configureDirectChannel(i.first, getHalChannelHandle(), &config);
@@ -187,12 +202,15 @@ void SensorService::SensorDirectConnection::stopAll(bool backupRecord) {
}

void SensorService::SensorDirectConnection::recoverAll() {
    stopAll(false);

    Mutex::Autolock _l(mConnectionLock);
    if (!mActivatedBackup.empty()) {
        stopAllLocked(false);

        SensorDevice& dev(SensorDevice::getInstance());

        // recover list of report from backup
        ALOG_ASSERT(mActivated.empty(),
                    "mActivated must be empty if mActivatedBackup was non-empty");
        mActivated = mActivatedBackup;
        mActivatedBackup.clear();

@@ -204,6 +222,7 @@ void SensorService::SensorDirectConnection::recoverAll() {
            dev.configureDirectChannel(i.first, getHalChannelHandle(), &config);
        }
    }
}

int32_t SensorService::SensorDirectConnection::getHalChannelHandle() const {
    return mHalChannelHandle;
+24 −8
Original line number Diff line number Diff line
@@ -42,17 +42,14 @@ public:
    void dump(String8& result) const;
    void dump(util::ProtoOutputStream* proto) const;
    uid_t getUid() const { return mUid; }
    const String16& getOpPackageName() const { return mOpPackageName; }
    int32_t getHalChannelHandle() const;
    bool isEquivalent(const sensors_direct_mem_t *mem) const;

    // stop all active sensor report. if backupRecord is set to false,
    // those report can be recovered by recoverAll
    // called by SensorService when enter restricted mode
    void stopAll(bool backupRecord = false);

    // recover sensor reports previously stopped by stopAll(true)
    // called by SensorService when return to NORMAL mode.
    void recoverAll();
    // Invoked when access to sensors for this connection has changed, e.g. lost or
    // regained due to changes in the sensor restricted/privacy mode or the
    // app changed to idle/active status.
    void onSensorAccessChanged(bool hasAccess);

protected:
    virtual ~SensorDirectConnection();
@@ -66,6 +63,25 @@ protected:
    virtual int32_t configureChannel(int handle, int rateLevel);
    virtual void destroy();
private:
    bool hasSensorAccess() const;

    // Stops all active sensor direct report requests.
    //
    // If backupRecord is true, stopped requests can be recovered
    // by a subsequent recoverAll() call (e.g. when temporarily stopping
    // sensors for sensor privacy/restrict mode or when an app becomes
    // idle).
    void stopAll(bool backupRecord = false);
    // Same as stopAll() but with mConnectionLock held.
    void stopAllLocked(bool backupRecord);

    // Recover sensor requests previously stopped by stopAll(true).
    // This method can be called when a sensor access resumes (e.g.
    // sensor privacy/restrict mode lifted or app becomes active).
    //
    // If no requests are backed up by stopAll(), this method is no-op.
    void recoverAll();

    const sp<SensorService> mService;
    const uid_t mUid;
    const sensors_direct_mem_t mMem;
+27 −8
Original line number Diff line number Diff line
@@ -308,6 +308,24 @@ void SensorService::onUidStateChanged(uid_t uid, UidState state) {
            dev.setUidStateForConnection(conn.get(), state);
        }
    }

    for (const sp<SensorDirectConnection>& conn : connLock.getDirectConnections()) {
        if (conn->getUid() == uid) {
            // Update sensor subscriptions if needed
            bool hasAccess = hasSensorAccessLocked(conn->getUid(), conn->getOpPackageName());
            conn->onSensorAccessChanged(hasAccess);
        }
    }
}

bool SensorService::hasSensorAccess(uid_t uid, const String16& opPackageName) {
    Mutex::Autolock _l(mLock);
    return hasSensorAccessLocked(uid, opPackageName);
}

bool SensorService::hasSensorAccessLocked(uid_t uid, const String16& opPackageName) {
    return !mSensorPrivacyPolicy->isSensorPrivacyEnabled()
        && isUidActive(uid) && !isOperationRestrictedLocked(opPackageName);
}

const Sensor& SensorService::registerSensor(SensorInterface* s, bool isDebug, bool isVirtual) {
@@ -640,8 +658,9 @@ void SensorService::disableAllSensors() {

void SensorService::disableAllSensorsLocked(ConnectionSafeAutolock* connLock) {
    SensorDevice& dev(SensorDevice::getInstance());
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
        connection->stopAll(true /* backupRecord */);
    for (const sp<SensorDirectConnection>& conn : connLock->getDirectConnections()) {
        bool hasAccess = hasSensorAccessLocked(conn->getUid(), conn->getOpPackageName());
        conn->onSensorAccessChanged(hasAccess);
    }
    dev.disableAllSensors();
    // Clear all pending flush connections for all active sensors. If one of the active
@@ -668,8 +687,9 @@ void SensorService::enableAllSensorsLocked(ConnectionSafeAutolock* connLock) {
    }
    SensorDevice& dev(SensorDevice::getInstance());
    dev.enableAllSensors();
    for (const sp<SensorDirectConnection>& connection : connLock->getDirectConnections()) {
        connection->recoverAll();
    for (const sp<SensorDirectConnection>& conn : connLock->getDirectConnections()) {
        bool hasAccess = hasSensorAccessLocked(conn->getUid(), conn->getOpPackageName());
        conn->onSensorAccessChanged(hasAccess);
    }
}

@@ -1888,13 +1908,12 @@ bool SensorService::isWhiteListedPackage(const String8& packageName) {
    return (packageName.contains(mWhiteListedPackage.string()));
}

bool SensorService::isOperationPermitted(const String16& opPackageName) {
    Mutex::Autolock _l(mLock);
bool SensorService::isOperationRestrictedLocked(const String16& opPackageName) {
    if (mCurrentOperatingMode == RESTRICTED) {
        String8 package(opPackageName);
        return isWhiteListedPackage(package);
        return !isWhiteListedPackage(package);
    }
    return true;
    return false;
}

void SensorService::UidPolicy::registerSelf() {
+11 −1
Original line number Diff line number Diff line
@@ -339,7 +339,11 @@ private:
    // allowed to register for or call flush on sensors. Typically only cts test packages are
    // allowed.
    bool isWhiteListedPackage(const String8& packageName);
    bool isOperationPermitted(const String16& opPackageName);

    // Returns true if a connection with the specified opPackageName has no access to sensors
    // in the RESTRICTED mode (i.e. the service is in RESTRICTED mode, and the package is not
    // whitelisted). mLock must be held to invoke this method.
    bool isOperationRestrictedLocked(const String16& opPackageName);

    // Reset the state of SensorService to NORMAL mode.
    status_t resetToNormalMode();
@@ -358,6 +362,12 @@ private:
    // Sets whether the given UID can get sensor data
    void onUidStateChanged(uid_t uid, UidState state);

    // Returns true if a connection with the given uid and opPackageName
    // currently has access to sensors.
    bool hasSensorAccess(uid_t uid, const String16& opPackageName);
    // Same as hasSensorAccess but with mLock held.
    bool hasSensorAccessLocked(uid_t uid, const String16& opPackageName);

    // Overrides the UID state as if it is idle
    status_t handleSetUidState(Vector<String16>& args, int err);
    // Clears the override for the UID state