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

Commit 08f1b67b authored by Peng Xu's avatar Peng Xu Committed by android-build-merger
Browse files

Show masked value for sensor with permission

am: fba3c11b

Change-Id: If4b9fd323d0f8333cd1d1dea8c1d801b43c7e157
parents ebbfaf3f fba3c11b
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ namespace {

RecentEventLogger::RecentEventLogger(int sensorType) :
        mSensorType(sensorType), mEventSize(eventSizeBySensorType(mSensorType)),
        mRecentEvents(logSizeBySensorType(sensorType)) {
        mRecentEvents(logSizeBySensorType(sensorType)), mMaskData(false) {
    // blank
}

@@ -60,6 +60,7 @@ std::string RecentEventLogger::dump() const {
                (int) ns2ms(ev.mWallTime.tv_nsec));

        // data
        if (!mMaskData) {
            if (mSensorType == SENSOR_TYPE_STEP_COUNTER) {
                buffer.appendFormat("%" PRIu64 ", ", ev.mEvent.u64.step_counter);
            } else {
@@ -67,11 +68,22 @@ std::string RecentEventLogger::dump() const {
                    buffer.appendFormat("%.2f, ", ev.mEvent.data[k]);
                }
            }
        } else {
            buffer.append("[value masked]");
        }
        buffer.append("\n");
    }
    return std::string(buffer.string());
}

void RecentEventLogger::setFormat(std::string format) {
    if (format == "mask_data" ) {
        mMaskData = true;
    } else {
        mMaskData = false;
    }
}

bool RecentEventLogger::populateLastEvent(sensors_event_t *event) const {
    std::lock_guard<std::mutex> lk(mLock);

+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ public:

    // Dumpable interface
    virtual std::string dump() const override;
    virtual void setFormat(std::string format) override;

protected:
    struct SensorEventLog {
@@ -57,6 +58,8 @@ protected:
    mutable std::mutex mLock;
    RingBuffer<SensorEventLog> mRecentEvents;

    bool mMaskData;

private:
    static size_t logSizeBySensorType(int sensorType);
};
+7 −2
Original line number Diff line number Diff line
@@ -322,6 +322,7 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) {
                IPCThreadState::self()->getCallingPid(),
                IPCThreadState::self()->getCallingUid());
    } else {
        bool privileged = IPCThreadState::self()->getCallingUid() == 0;
        if (args.size() > 2) {
           return INVALID_OPERATION;
        }
@@ -393,8 +394,12 @@ status_t SensorService::dump(int fd, const Vector<String16>& args) {
            result.append("Recent Sensor events:\n");
            for (auto&& i : mRecentEvent) {
                sp<SensorInterface> s = mSensors.getInterface(i.first);
                if (!i.second->isEmpty() &&
                    s->getSensor().getRequiredPermission().isEmpty()) {
                if (!i.second->isEmpty()) {
                    if (privileged || s->getSensor().getRequiredPermission().isEmpty()) {
                        i.second->setFormat("normal");
                    } else {
                        i.second->setFormat("mask_data");
                    }
                    // if there is events and sensor does not need special permission.
                    result.appendFormat("%s: ", s->getSensor().getName().string());
                    result.append(i.second->dump().c_str());