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

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

Merge changes from topic 'sensors_framework_hal' into oc-dev

* changes:
  android.frameworks.sensorservice@1.0: make classes final
  android.frameworks.sensorservice@1.0: ashmem direct channel check sizes.
  android.frameworks.sensorservice@1.0: fix configureDirectChannel return positive integer.
  Implement android.frameworks.sensorservice@1.0::IEventQueue.
  Renamed HIDL SensorManager::mManager -> mInternalManager.
parents a44aa44d a07b3eec
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -83,7 +83,7 @@ public:
    status_t disableSensor(Sensor const* sensor) const;
    status_t disableSensor(Sensor const* sensor) const;
    status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;
    status_t setEventRate(Sensor const* sensor, nsecs_t ns) const;


    // these are here only to support SensorManager.java
    // these are here only to support SensorManager.java and HIDL Frameworks SensorManager.
    status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs,
    status_t enableSensor(int32_t handle, int32_t samplingPeriodUs, int64_t maxBatchReportLatencyUs,
                          int reservedFlags) const;
                          int reservedFlags) const;
    status_t disableSensor(int32_t handle) const;
    status_t disableSensor(int32_t handle) const;
+4 −0
Original line number Original line Diff line number Diff line
cc_library_shared {
cc_library_shared {
    name: "libsensorservicehidl",
    name: "libsensorservicehidl",
    srcs: [
    srcs: [
        "EventQueue.cpp",
        "DirectReportChannel.cpp",
        "DirectReportChannel.cpp",
        "SensorManager.cpp",
        "SensorManager.cpp",
        "utils.cpp",
        "utils.cpp",
@@ -19,6 +20,9 @@ cc_library_shared {
        "android.hardware.sensors@1.0",
        "android.hardware.sensors@1.0",
        "android.hidl.base@1.0",
        "android.hidl.base@1.0",
    ],
    ],
    static_libs: [
        "android.hardware.sensors@1.0-convert",
    ],
    export_include_dirs: [
    export_include_dirs: [
        "include/"
        "include/"
    ],
    ],
+3 −2
Original line number Original line Diff line number Diff line
@@ -32,8 +32,9 @@ DirectReportChannel::~DirectReportChannel() {


// Methods from ::android::frameworks::sensorservice::V1_0::IDirectReportChannel follow.
// Methods from ::android::frameworks::sensorservice::V1_0::IDirectReportChannel follow.
Return<Result> DirectReportChannel::configure(int32_t sensorHandle, RateLevel rate) {
Return<Result> DirectReportChannel::configure(int32_t sensorHandle, RateLevel rate) {
    return convertResult(mManager.configureDirectChannel(mId,
    int token = mManager.configureDirectChannel(mId,
            static_cast<int>(sensorHandle), static_cast<int>(rate)));
            static_cast<int>(sensorHandle), static_cast<int>(rate));
    return token <= 0 ? convertResult(token) : Result::OK;
}
}




+1 −1
Original line number Original line Diff line number Diff line
@@ -41,7 +41,7 @@ using ::android::hardware::Return;
using ::android::hardware::Void;
using ::android::hardware::Void;
using ::android::sp;
using ::android::sp;


struct DirectReportChannel : public IDirectReportChannel {
struct DirectReportChannel final : public IDirectReportChannel {


    DirectReportChannel(::android::SensorManager& manager, int channelId);
    DirectReportChannel(::android::SensorManager& manager, int channelId);
    ~DirectReportChannel();
    ~DirectReportChannel();
+84 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2017 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "EventQueue.h"
#include "utils.h"

#include <utils/Looper.h>

namespace android {
namespace frameworks {
namespace sensorservice {
namespace V1_0 {
namespace implementation {

class EventQueueLooperCallback : public ::android::LooperCallback {
public:
    EventQueueLooperCallback(sp<EventQueue> queue, sp<IEventQueueCallback> callback)
            : mQueue(queue), mCallback(callback) {
    }

    int handleEvent(__unused int fd, __unused int events, __unused void* data) {

        ASensorEvent event;
        ssize_t actual;
        const sp<::android::SensorEventQueue>& internalQueue = mQueue->mInternalQueue;

        while ((actual = internalQueue->read(&event, 1 /* count */)) > 0) {
            internalQueue->sendAck(&event, actual);
            mCallback->onEvent(convertEvent(event));
        }

        return 1; // continue to receive callbacks
    }

private:
    sp<EventQueue> mQueue;
    sp<IEventQueueCallback> mCallback;
};

EventQueue::EventQueue(
        sp<IEventQueueCallback> callback,
        sp<::android::Looper> looper,
        sp<::android::SensorEventQueue> internalQueue)
            : mLooper(looper),
              mInternalQueue(internalQueue) {

    mLooper->addFd(mInternalQueue->getFd(), ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT,
            new EventQueueLooperCallback(this, callback), NULL /* data */);
}

EventQueue::~EventQueue() {
    mLooper->removeFd(mInternalQueue->getFd());
}

// Methods from ::android::frameworks::sensorservice::V1_0::IEventQueue follow.
Return<Result> EventQueue::enableSensor(int32_t sensorHandle, int32_t samplingPeriodUs,
        int64_t maxBatchReportLatencyUs) {
    // TODO implement
    return convertResult(mInternalQueue->enableSensor(sensorHandle, samplingPeriodUs,
            maxBatchReportLatencyUs, 0 /* reserved flags */));
}

Return<Result> EventQueue::disableSensor(int32_t sensorHandle) {
    return convertResult(mInternalQueue->disableSensor(sensorHandle));
}

}  // namespace implementation
}  // namespace V1_0
}  // namespace sensorservice
}  // namespace frameworks
}  // namespace android
Loading