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

Commit 82b5b24a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Dumpsys sensorservice --proto"

parents e6bbfa35 24743868
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ cc_library_shared {
        "libbinder",
        "libsensor",
        "libsensorprivacy",
        "libprotoutil",
        "libcrypto",
        "libbase",
        "libhidlbase",
@@ -52,6 +53,8 @@ cc_library_shared {

    static_libs: ["android.hardware.sensors@1.0-convert"],

    generated_headers: ["framework-cppstream-protos"],

    // our public headers depend on libsensor and libsensorprivacy
    export_shared_lib_headers: ["libsensor", "libsensorprivacy"],
}
+36 −0
Original line number Diff line number Diff line
@@ -17,6 +17,8 @@
#include "RecentEventLogger.h"
#include "SensorServiceUtils.h"

#include <android/util/ProtoOutputStream.h>
#include <frameworks/base/core/proto/android/service/sensor_service.proto.h>
#include <utils/Timers.h>

#include <inttypes.h>
@@ -84,6 +86,40 @@ std::string RecentEventLogger::dump() const {
    return std::string(buffer.string());
}

/**
 * Dump debugging information as android.service.SensorEventsProto protobuf message using
 * ProtoOutputStream.
 *
 * See proto definition and some notes about ProtoOutputStream in
 * frameworks/base/core/proto/android/service/sensor_service.proto
 */
void RecentEventLogger::dump(util::ProtoOutputStream* proto) const {
    using namespace service::SensorEventsProto;
    std::lock_guard<std::mutex> lk(mLock);

    proto->write(RecentEventsLog::RECENT_EVENTS_COUNT, int(mRecentEvents.size()));
    for (int i = mRecentEvents.size() - 1; i >= 0; --i) {
        const auto& ev = mRecentEvents[i];
        const uint64_t token = proto->start(RecentEventsLog::EVENTS);
        proto->write(Event::TIMESTAMP_SEC, float(ev.mEvent.timestamp) / 1e9f);
        proto->write(Event::WALL_TIMESTAMP_MS, ev.mWallTime.tv_sec * 1000LL
                + ns2ms(ev.mWallTime.tv_nsec));

        if (mMaskData) {
            proto->write(Event::MASKED, true);
        } else {
            if (mSensorType == SENSOR_TYPE_STEP_COUNTER) {
                proto->write(Event::INT64_DATA, int64_t(ev.mEvent.u64.step_counter));
            } else {
                for (size_t k = 0; k < mEventSize; ++k) {
                    proto->write(Event::FLOAT_ARRAY, ev.mEvent.data[k]);
                }
            }
        }
        proto->end(token);
    }
}

void RecentEventLogger::setFormat(std::string format) {
    if (format == "mask_data" ) {
        mMaskData = true;
+1 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ public:

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

protected:
+40 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "SensorService.h"

#include <android-base/logging.h>
#include <android/util/ProtoOutputStream.h>
#include <frameworks/base/core/proto/android/service/sensor_service.proto.h>
#include <sensors/convert.h>
#include <cutils/atomic.h>
#include <utils/Errors.h>
@@ -39,6 +41,7 @@ using android::hardware::sensors::V2_0::WakeLockQueueFlagBits;
using android::hardware::hidl_vec;
using android::hardware::Return;
using android::SensorDeviceUtils::HidlServiceRegistrationWaiter;
using android::util::ProtoOutputStream;

namespace android {
// ---------------------------------------------------------------------------
@@ -396,6 +399,43 @@ std::string SensorDevice::dump() const {
    return result.string();
}

/**
 * Dump debugging information as android.service.SensorDeviceProto protobuf message using
 * ProtoOutputStream.
 *
 * See proto definition and some notes about ProtoOutputStream in
 * frameworks/base/core/proto/android/service/sensor_service.proto
 */
void SensorDevice::dump(ProtoOutputStream* proto) const {
    using namespace service::SensorDeviceProto;
    if (mSensors == nullptr) {
        proto->write(INITIALIZED , false);
        return;
    }
    proto->write(INITIALIZED , true);
    proto->write(TOTAL_SENSORS , int(mSensorList.size()));
    proto->write(ACTIVE_SENSORS , int(mActivationCount.size()));

    Mutex::Autolock _l(mLock);
    for (const auto & s : mSensorList) {
        int32_t handle = s.handle;
        const Info& info = mActivationCount.valueFor(handle);
        if (info.numActiveClients() == 0) continue;

        uint64_t token = proto->start(SENSORS);
        proto->write(SensorProto::HANDLE , handle);
        proto->write(SensorProto::ACTIVE_COUNT , int(info.batchParams.size()));
        for (size_t j = 0; j < info.batchParams.size(); j++) {
            const BatchParams& params = info.batchParams[j];
            proto->write(SensorProto::SAMPLING_PERIOD_MS , params.mTSample / 1e6f);
            proto->write(SensorProto::BATCHING_PERIOD_MS , params.mTBatch / 1e6f);
        }
        proto->write(SensorProto::SAMPLING_PERIOD_SELECTED , info.bestBatchParams.mTSample / 1e6f);
        proto->write(SensorProto::BATCHING_PERIOD_SELECTED , info.bestBatchParams.mTBatch / 1e6f);
        proto->end(token);
    }
}

ssize_t SensorDevice::getSensorList(sensor_t const** list) {
    *list = &mSensorList[0];

+2 −1
Original line number Diff line number Diff line
@@ -123,7 +123,8 @@ public:
    bool isSensorActive(int handle) const;

    // Dumpable
    virtual std::string dump() const;
    virtual std::string dump() const override;
    virtual void dump(util::ProtoOutputStream* proto) const override;
private:
    friend class Singleton<SensorDevice>;

Loading