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

Commit ee36adbd authored by Ashutosh Joshi's avatar Ashutosh Joshi Committed by Android (Google) Code Review
Browse files

Merge "Show masked value for sensor with permission" into cw-f-dev

parents d946ae67 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());