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