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

Commit 9cdab584 authored by Devin Moore's avatar Devin Moore Committed by Automerger Merge Worker
Browse files

Merge changes from topics "sensor_conver", "sensorservice_aidl" am: a3793499 am: 3191a512

parents fe0216c5 3191a512
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_native_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_native_license"],
}

cc_library_shared {
    name: "libsensorserviceaidl",
    srcs: [
        "EventQueue.cpp",
        "DirectReportChannel.cpp",
        "SensorManager.cpp",
        "utils.cpp",
    ],
    cflags: [
        "-Wall",
        "-Werror",
    ],
    header_libs: ["jni_headers"],
    shared_libs: [
        "libbase",
        "libutils",
        "libcutils",
        "libbinder_ndk",
        "libsensor",
        "android.frameworks.sensorservice-V1-ndk",
        "android.hardware.sensors-V1-ndk",
    ],
    export_include_dirs: [
        "include/",
    ],
    static_libs: [
        "android.hardware.sensors-V1-convert",
    ],

    export_header_lib_headers: ["jni_headers"],
    local_include_dirs: [
        "include/sensorserviceaidl/",
    ],
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 "DirectReportChannel.h"

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

DirectReportChannel::DirectReportChannel(::android::SensorManager& manager, int channelId)
      : mManager(manager), mId(channelId) {}

DirectReportChannel::~DirectReportChannel() {
    mManager.destroyDirectChannel(mId);
}

ndk::ScopedAStatus DirectReportChannel::configure(
        int32_t sensorHandle, ::aidl::android::hardware::sensors::ISensors::RateLevel rate,
        int32_t* _aidl_return) {
    int token = mManager.configureDirectChannel(mId, sensorHandle, static_cast<int>(rate));
    if (token <= 0) {
        return ndk::ScopedAStatus::fromServiceSpecificError(token);
    }
    *_aidl_return = token;
    return ndk::ScopedAStatus::ok();
}

} // namespace implementation
} // namespace sensorservice
} // namespace frameworks
} // namespace android
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */
#pragma once

#include <aidl/android/frameworks/sensorservice/BnDirectReportChannel.h>
#include <aidl/android/hardware/sensors/ISensors.h>
#include <sensor/SensorManager.h>

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

class DirectReportChannel final
      : public ::aidl::android::frameworks::sensorservice::BnDirectReportChannel {
public:
    DirectReportChannel(::android::SensorManager& manager, int channelId);
    ~DirectReportChannel();

    ndk::ScopedAStatus configure(int32_t sensorHandle,
                                 ::aidl::android::hardware::sensors::ISensors::RateLevel rate,
                                 int32_t* _aidl_return) override;

private:
    ::android::SensorManager& mManager;
    const int mId;
};

} // namespace implementation
} // namespace sensorservice
} // namespace frameworks
} // namespace android
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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 <android-base/logging.h>
#include <utils/Looper.h>

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

using ::aidl::android::frameworks::sensorservice::IEventQueueCallback;
using ::aidl::android::hardware::sensors::Event;

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

    int handleEvent(__unused int fd, __unused int events, __unused void* data) {
        ASensorEvent event;
        ssize_t actual;

        auto internalQueue = mQueue.promote();
        if (internalQueue == nullptr) {
            return 1;
        }

        while ((actual = internalQueue->read(&event, 1)) > 0) {
            internalQueue->sendAck(&event, actual);
            ndk::ScopedAStatus ret = mCallback->onEvent(convertEvent(event));
            if (!ret.isOk()) {
                LOG(ERROR) << "Failed to envoke EventQueueCallback: " << ret;
            }
        }

        return 1; // continue to receive callbacks
    }

private:
    wp<::android::SensorEventQueue> mQueue;
    std::shared_ptr<IEventQueueCallback> mCallback;
};

EventQueue::EventQueue(std::shared_ptr<IEventQueueCallback> callback, sp<::android::Looper> looper,
                       sp<::android::SensorEventQueue> internalQueue)
      : mLooper(looper), mInternalQueue(internalQueue) {
    mLooper->addFd(internalQueue->getFd(), ALOOPER_POLL_CALLBACK, ALOOPER_EVENT_INPUT,
                   new EventQueueLooperCallback(internalQueue, callback), nullptr);
}

// FIXME why was this on onLastStrongRef instead of dtor?
EventQueue::~EventQueue() {
    mLooper->removeFd(mInternalQueue->getFd());
}

ndk::ScopedAStatus EventQueue::enableSensor(int32_t in_sensorHandle, int32_t in_samplingPeriodUs,
                                            int64_t in_maxBatchReportLatencyUs) {
    return convertResult(mInternalQueue->enableSensor(in_sensorHandle, in_samplingPeriodUs,
                                                      in_maxBatchReportLatencyUs, 0));
}

ndk::ScopedAStatus EventQueue::disableSensor(int32_t in_sensorHandle) {
    return convertResult(mInternalQueue->disableSensor(in_sensorHandle));
}

} // namespace implementation
} // namespace sensorservice
} // namespace frameworks
} // namespace android
+47 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.
 */
#pragma once

#include "SensorManagerAidl.h"

#include <aidl/android/frameworks/sensorservice/BnEventQueue.h>
#include <sensor/SensorManager.h>

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

struct EventQueue final : public aidl::android::frameworks::sensorservice::BnEventQueue {
    EventQueue(
            std::shared_ptr<aidl::android::frameworks::sensorservice::IEventQueueCallback> callback,
            sp<::android::Looper> looper, sp<::android::SensorEventQueue> internalQueue);
    ~EventQueue();

    ndk::ScopedAStatus enableSensor(int32_t in_sensorHandle, int32_t in_samplingPeriodUs,
                                    int64_t in_maxBatchReportLatencyUs) override;
    ndk::ScopedAStatus disableSensor(int32_t sensorHandle) override;

private:
    friend class EventQueueLooperCallback;
    sp<::android::Looper> mLooper;
    sp<::android::SensorEventQueue> mInternalQueue;
};

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