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 | |
| 17 | #include <stdint.h> |
| 18 | #include <sys/types.h> |
| 19 | |
| 20 | #include <utils/Errors.h> |
| 21 | #include <utils/RefBase.h> |
| 22 | #include <utils/Timers.h> |
| 23 | |
| 24 | #include <binder/Parcel.h> |
| 25 | #include <binder/IInterface.h> |
| 26 | |
| 27 | #include <gui/ISensorEventConnection.h> |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 28 | #include <gui/BitTube.h> |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 29 | |
| 30 | namespace android { |
| 31 | // ---------------------------------------------------------------------------- |
| 32 | |
| 33 | enum { |
| 34 | GET_SENSOR_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, |
| 35 | ENABLE_DISABLE, |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 36 | SET_EVENT_RATE, |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 37 | FLUSH_SENSOR, |
| 38 | CONFIGURE_CHANNEL |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpSensorEventConnection : public BpInterface<ISensorEventConnection> |
| 42 | { |
| 43 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 44 | explicit BpSensorEventConnection(const sp<IBinder>& impl) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 45 | : BpInterface<ISensorEventConnection>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 49 | virtual ~BpSensorEventConnection(); |
| 50 | |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 51 | virtual sp<BitTube> getSensorChannel() const |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 52 | { |
| 53 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 54 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 55 | remote()->transact(GET_SENSOR_CHANNEL, data, &reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 56 | return new BitTube(reply); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 57 | } |
| 58 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 59 | virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, |
| 60 | nsecs_t maxBatchReportLatencyNs, int reservedFlags) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 61 | { |
| 62 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 63 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 64 | data.writeInt32(handle); |
| 65 | data.writeInt32(enabled); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 66 | data.writeInt64(samplingPeriodNs); |
| 67 | data.writeInt64(maxBatchReportLatencyNs); |
| 68 | data.writeInt32(reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 69 | remote()->transact(ENABLE_DISABLE, data, &reply); |
| 70 | return reply.readInt32(); |
| 71 | } |
| 72 | |
| 73 | virtual status_t setEventRate(int handle, nsecs_t ns) |
| 74 | { |
| 75 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 76 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 77 | data.writeInt32(handle); |
| 78 | data.writeInt64(ns); |
| 79 | remote()->transact(SET_EVENT_RATE, data, &reply); |
| 80 | return reply.readInt32(); |
| 81 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 82 | |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 83 | virtual status_t flush() { |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 84 | Parcel data, reply; |
| 85 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 86 | remote()->transact(FLUSH_SENSOR, data, &reply); |
| 87 | return reply.readInt32(); |
| 88 | } |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 89 | |
| 90 | virtual int32_t configureChannel(int32_t handle, int32_t rateLevel) { |
| 91 | Parcel data, reply; |
| 92 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
| 93 | data.writeInt32(handle); |
| 94 | data.writeInt32(rateLevel); |
| 95 | remote()->transact(CONFIGURE_CHANNEL, data, &reply); |
| 96 | return reply.readInt32(); |
| 97 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 100 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 101 | // translation unit (see clang warning -Wweak-vtables) |
| 102 | BpSensorEventConnection::~BpSensorEventConnection() {} |
| 103 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 104 | IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection"); |
| 105 | |
| 106 | // ---------------------------------------------------------------------------- |
| 107 | |
| 108 | status_t BnSensorEventConnection::onTransact( |
| 109 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 110 | { |
| 111 | switch(code) { |
| 112 | case GET_SENSOR_CHANNEL: { |
| 113 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 114 | sp<BitTube> channel(getSensorChannel()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 115 | channel->writeToParcel(reply); |
| 116 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 117 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 118 | case ENABLE_DISABLE: { |
| 119 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 120 | int handle = data.readInt32(); |
| 121 | int enabled = data.readInt32(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 122 | nsecs_t samplingPeriodNs = data.readInt64(); |
| 123 | nsecs_t maxBatchReportLatencyNs = data.readInt64(); |
| 124 | int reservedFlags = data.readInt32(); |
| 125 | status_t result = enableDisable(handle, enabled, samplingPeriodNs, |
| 126 | maxBatchReportLatencyNs, reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 127 | reply->writeInt32(result); |
| 128 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 129 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 130 | case SET_EVENT_RATE: { |
| 131 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 132 | int handle = data.readInt32(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 133 | nsecs_t ns = data.readInt64(); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 134 | status_t result = setEventRate(handle, ns); |
| 135 | reply->writeInt32(result); |
| 136 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 137 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 138 | case FLUSH_SENSOR: { |
| 139 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 140 | status_t result = flush(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 141 | reply->writeInt32(result); |
| 142 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 143 | } |
Peng Xu | e36e347 | 2016-11-03 11:57:10 -0700 | [diff] [blame] | 144 | case CONFIGURE_CHANNEL: { |
| 145 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 146 | int handle = data.readInt32(); |
| 147 | int rateLevel = data.readInt32(); |
| 148 | status_t result = configureChannel(handle, rateLevel); |
| 149 | reply->writeInt32(result); |
| 150 | return NO_ERROR; |
| 151 | } |
| 152 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 153 | } |
| 154 | return BBinder::onTransact(code, data, reply, flags); |
| 155 | } |
| 156 | |
| 157 | // ---------------------------------------------------------------------------- |
| 158 | }; // namespace android |