Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame^] | 17 | #include <sensor/ISensorEventConnection.h> |
| 18 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 19 | #include <stdint.h> |
| 20 | #include <sys/types.h> |
| 21 | |
| 22 | #include <utils/Errors.h> |
| 23 | #include <utils/RefBase.h> |
| 24 | #include <utils/Timers.h> |
| 25 | |
| 26 | #include <binder/Parcel.h> |
| 27 | #include <binder/IInterface.h> |
| 28 | |
Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame^] | 29 | #include <sensor/BitTube.h> |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 30 | |
| 31 | namespace android { |
| 32 | // ---------------------------------------------------------------------------- |
| 33 | |
| 34 | enum { |
| 35 | GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, |
| 36 | ENABLE_DISABLE, |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 37 | SET_EVENT_RATE, |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 38 | FLUSH_SENSOR, |
| 39 | CONFIGURE_CHANNEL |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | class BpSensorEventConnection : public BpInterface<ISensorEventConnection> |
| 43 | { |
| 44 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 45 | explicit BpSensorEventConnection(const sp<IBinder>& impl) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 46 | : BpInterface<ISensorEventConnection>(impl) |
| 47 | { |
| 48 | } |
| 49 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 50 | virtual ~BpSensorEventConnection(); |
| 51 | |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 52 | virtual sp<BitTube> getSensorChannel() const |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 53 | { |
| 54 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 55 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 56 | remote()->transact(GET_SENSOR_CHANNEL, data, &reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 57 | return new BitTube(reply); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 58 | } |
| 59 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 60 | virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, |
| 61 | nsecs_t maxBatchReportLatencyNs, int reservedFlags) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 62 | { |
| 63 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 64 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 65 | data.writeInt32(handle); |
| 66 | data.writeInt32(enabled); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 67 | data.writeInt64(samplingPeriodNs); |
| 68 | data.writeInt64(maxBatchReportLatencyNs); |
| 69 | data.writeInt32(reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 70 | remote()->transact(ENABLE_DISABLE, data, &reply); |
| 71 | return reply.readInt32(); |
| 72 | } |
| 73 | |
| 74 | virtual status_t setEventRate(int handle, nsecs_t ns) |
| 75 | { |
| 76 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 77 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 78 | data.writeInt32(handle); |
| 79 | data.writeInt64(ns); |
| 80 | remote()->transact(SET_EVENT_RATE, data, &reply); |
| 81 | return reply.readInt32(); |
| 82 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 83 | |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 84 | virtual status_t flush() { |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 85 | Parcel data, reply; |
| 86 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 87 | remote()->transact(FLUSH_SENSOR, data, &reply); |
| 88 | return reply.readInt32(); |
| 89 | } |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 90 | |
| 91 | virtual int32_t configureChannel(int32_t handle, int32_t rateLevel) { |
| 92 | Parcel data, reply; |
| 93 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
| 94 | data.writeInt32(handle); |
| 95 | data.writeInt32(rateLevel); |
| 96 | remote()->transact(CONFIGURE_CHANNEL, data, &reply); |
| 97 | return reply.readInt32(); |
| 98 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 101 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 102 | // translation unit (see clang warning -Wweak-vtables) |
| 103 | BpSensorEventConnection::~BpSensorEventConnection() {} |
| 104 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 105 | IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection"); |
| 106 | |
| 107 | // ---------------------------------------------------------------------------- |
| 108 | |
| 109 | status_t BnSensorEventConnection::onTransact( |
| 110 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 111 | { |
| 112 | switch(code) { |
| 113 | case GET_SENSOR_CHANNEL: { |
| 114 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 115 | sp<BitTube> channel(getSensorChannel()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 116 | channel->writeToParcel(reply); |
| 117 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 118 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 119 | case ENABLE_DISABLE: { |
| 120 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 121 | int handle = data.readInt32(); |
| 122 | int enabled = data.readInt32(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 123 | nsecs_t samplingPeriodNs = data.readInt64(); |
| 124 | nsecs_t maxBatchReportLatencyNs = data.readInt64(); |
| 125 | int reservedFlags = data.readInt32(); |
| 126 | status_t result = enableDisable(handle, enabled, samplingPeriodNs, |
| 127 | maxBatchReportLatencyNs, reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 128 | reply->writeInt32(result); |
| 129 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 130 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 131 | case SET_EVENT_RATE: { |
| 132 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 133 | int handle = data.readInt32(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 134 | nsecs_t ns = data.readInt64(); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 135 | status_t result = setEventRate(handle, ns); |
| 136 | reply->writeInt32(result); |
| 137 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 138 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 139 | case FLUSH_SENSOR: { |
| 140 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 141 | status_t result = flush(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 142 | reply->writeInt32(result); |
| 143 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 144 | } |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 145 | case CONFIGURE_CHANNEL: { |
| 146 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 147 | int handle = data.readInt32(); |
| 148 | int rateLevel = data.readInt32(); |
| 149 | status_t result = configureChannel(handle, rateLevel); |
| 150 | reply->writeInt32(result); |
| 151 | return NO_ERROR; |
| 152 | } |
| 153 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 154 | } |
| 155 | return BBinder::onTransact(code, data, reply, flags); |
| 156 | } |
| 157 | |
| 158 | // ---------------------------------------------------------------------------- |
| 159 | }; // namespace android |