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, |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 37 | FLUSH_SENSOR, |
| 38 | DECREASE_WAKE_LOCK_REFCOUNT |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpSensorEventConnection : public BpInterface<ISensorEventConnection> |
| 42 | { |
| 43 | public: |
| 44 | BpSensorEventConnection(const sp<IBinder>& impl) |
| 45 | : BpInterface<ISensorEventConnection>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 49 | virtual sp<BitTube> getSensorChannel() const |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 50 | { |
| 51 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 52 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 53 | remote()->transact(GET_SENSOR_CHANNEL, data, &reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 54 | return new BitTube(reply); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 57 | virtual status_t enableDisable(int handle, bool enabled, nsecs_t samplingPeriodNs, |
| 58 | nsecs_t maxBatchReportLatencyNs, int reservedFlags) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 59 | { |
| 60 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 61 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 62 | data.writeInt32(handle); |
| 63 | data.writeInt32(enabled); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 64 | data.writeInt64(samplingPeriodNs); |
| 65 | data.writeInt64(maxBatchReportLatencyNs); |
| 66 | data.writeInt32(reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 67 | remote()->transact(ENABLE_DISABLE, data, &reply); |
| 68 | return reply.readInt32(); |
| 69 | } |
| 70 | |
| 71 | virtual status_t setEventRate(int handle, nsecs_t ns) |
| 72 | { |
| 73 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 74 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 75 | data.writeInt32(handle); |
| 76 | data.writeInt64(ns); |
| 77 | remote()->transact(SET_EVENT_RATE, data, &reply); |
| 78 | return reply.readInt32(); |
| 79 | } |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 80 | |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 81 | virtual status_t flush() { |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 82 | Parcel data, reply; |
| 83 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 84 | remote()->transact(FLUSH_SENSOR, data, &reply); |
| 85 | return reply.readInt32(); |
| 86 | } |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 87 | |
| 88 | virtual void decreaseWakeLockRefCount() { |
| 89 | Parcel data, reply; |
| 90 | data.writeInterfaceToken(ISensorEventConnection::getInterfaceDescriptor()); |
| 91 | remote()->transact(DECREASE_WAKE_LOCK_REFCOUNT, data, &reply, IBinder::FLAG_ONEWAY); |
| 92 | return; |
| 93 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | IMPLEMENT_META_INTERFACE(SensorEventConnection, "android.gui.SensorEventConnection"); |
| 97 | |
| 98 | // ---------------------------------------------------------------------------- |
| 99 | |
| 100 | status_t BnSensorEventConnection::onTransact( |
| 101 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 102 | { |
| 103 | switch(code) { |
| 104 | case GET_SENSOR_CHANNEL: { |
| 105 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Mathias Agopian | 5cae0d0 | 2011-10-20 18:42:02 -0700 | [diff] [blame] | 106 | sp<BitTube> channel(getSensorChannel()); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 107 | channel->writeToParcel(reply); |
| 108 | return NO_ERROR; |
| 109 | } break; |
| 110 | case ENABLE_DISABLE: { |
| 111 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 112 | int handle = data.readInt32(); |
| 113 | int enabled = data.readInt32(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 114 | nsecs_t samplingPeriodNs = data.readInt64(); |
| 115 | nsecs_t maxBatchReportLatencyNs = data.readInt64(); |
| 116 | int reservedFlags = data.readInt32(); |
| 117 | status_t result = enableDisable(handle, enabled, samplingPeriodNs, |
| 118 | maxBatchReportLatencyNs, reservedFlags); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 119 | reply->writeInt32(result); |
| 120 | return NO_ERROR; |
| 121 | } break; |
| 122 | case SET_EVENT_RATE: { |
| 123 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 124 | int handle = data.readInt32(); |
| 125 | int ns = data.readInt64(); |
| 126 | status_t result = setEventRate(handle, ns); |
| 127 | reply->writeInt32(result); |
| 128 | return NO_ERROR; |
| 129 | } break; |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 130 | case FLUSH_SENSOR: { |
| 131 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
Aravind Akella | 701166d | 2013-10-08 14:59:26 -0700 | [diff] [blame] | 132 | status_t result = flush(); |
Aravind Akella | 724d91d | 2013-06-27 12:04:23 -0700 | [diff] [blame] | 133 | reply->writeInt32(result); |
| 134 | return NO_ERROR; |
| 135 | } break; |
Aravind Akella | 9a844cf | 2014-02-11 18:58:52 -0800 | [diff] [blame] | 136 | case DECREASE_WAKE_LOCK_REFCOUNT: { |
| 137 | CHECK_INTERFACE(ISensorEventConnection, data, reply); |
| 138 | decreaseWakeLockRefCount(); |
| 139 | return NO_ERROR; |
| 140 | } break; |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 141 | } |
| 142 | return BBinder::onTransact(code, data, reply, flags); |
| 143 | } |
| 144 | |
| 145 | // ---------------------------------------------------------------------------- |
| 146 | }; // namespace android |