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/Vector.h> |
| 23 | #include <utils/Timers.h> |
| 24 | |
| 25 | #include <binder/Parcel.h> |
| 26 | #include <binder/IInterface.h> |
| 27 | |
| 28 | #include <gui/Sensor.h> |
| 29 | #include <gui/ISensorServer.h> |
| 30 | #include <gui/ISensorEventConnection.h> |
| 31 | |
| 32 | namespace android { |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | enum { |
| 36 | GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION, |
| 37 | CREATE_SENSOR_EVENT_CONNECTION, |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 38 | ENABLE_DATA_INJECTION |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | class BpSensorServer : public BpInterface<ISensorServer> |
| 42 | { |
| 43 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame^] | 44 | explicit BpSensorServer(const sp<IBinder>& impl) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 45 | : BpInterface<ISensorServer>(impl) |
| 46 | { |
| 47 | } |
| 48 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 49 | virtual ~BpSensorServer(); |
| 50 | |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 51 | virtual Vector<Sensor> getSensorList(const String16& opPackageName) |
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(ISensorServer::getInterfaceDescriptor()); |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 55 | data.writeString16(opPackageName); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 56 | remote()->transact(GET_SENSOR_LIST, data, &reply); |
| 57 | Sensor s; |
| 58 | Vector<Sensor> v; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 59 | uint32_t n = reply.readUint32(); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 60 | v.setCapacity(n); |
| 61 | while (n--) { |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 62 | reply.read(s); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 63 | v.add(s); |
| 64 | } |
| 65 | return v; |
| 66 | } |
| 67 | |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 68 | virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName, |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 69 | int mode, const String16& opPackageName) |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 70 | { |
| 71 | Parcel data, reply; |
Mathias Agopian | a7352c9 | 2010-07-14 23:41:37 -0700 | [diff] [blame] | 72 | data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor()); |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 73 | data.writeString8(packageName); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 74 | data.writeInt32(mode); |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 75 | data.writeString16(opPackageName); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 76 | remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply); |
| 77 | return interface_cast<ISensorEventConnection>(reply.readStrongBinder()); |
| 78 | } |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 79 | |
Aravind Akella | 841a592 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 80 | virtual int isDataInjectionEnabled() { |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 81 | Parcel data, reply; |
| 82 | data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor()); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 83 | remote()->transact(ENABLE_DATA_INJECTION, data, &reply); |
| 84 | return reply.readInt32(); |
| 85 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 88 | // Out-of-line virtual method definition to trigger vtable emission in this |
| 89 | // translation unit (see clang warning -Wweak-vtables) |
| 90 | BpSensorServer::~BpSensorServer() {} |
| 91 | |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 92 | IMPLEMENT_META_INTERFACE(SensorServer, "android.gui.SensorServer"); |
| 93 | |
| 94 | // ---------------------------------------------------------------------- |
| 95 | |
| 96 | status_t BnSensorServer::onTransact( |
| 97 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) |
| 98 | { |
| 99 | switch(code) { |
| 100 | case GET_SENSOR_LIST: { |
| 101 | CHECK_INTERFACE(ISensorServer, data, reply); |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 102 | const String16& opPackageName = data.readString16(); |
| 103 | Vector<Sensor> v(getSensorList(opPackageName)); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 104 | size_t n = v.size(); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 105 | reply->writeUint32(static_cast<uint32_t>(n)); |
| 106 | for (size_t i = 0; i < n; i++) { |
Mathias Agopian | 8683fca | 2012-08-12 19:37:16 -0700 | [diff] [blame] | 107 | reply->write(v[i]); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 108 | } |
| 109 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 110 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 111 | case CREATE_SENSOR_EVENT_CONNECTION: { |
| 112 | CHECK_INTERFACE(ISensorServer, data, reply); |
Aravind Akella | 4949c50 | 2015-02-11 15:54:35 -0800 | [diff] [blame] | 113 | String8 packageName = data.readString8(); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 114 | int32_t mode = data.readInt32(); |
Svetoslav | b412f6e | 2015-04-29 16:50:41 -0700 | [diff] [blame] | 115 | const String16& opPackageName = data.readString16(); |
| 116 | sp<ISensorEventConnection> connection(createSensorEventConnection(packageName, mode, |
| 117 | opPackageName)); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 118 | reply->writeStrongBinder(IInterface::asBinder(connection)); |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 119 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 120 | } |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 121 | case ENABLE_DATA_INJECTION: { |
| 122 | CHECK_INTERFACE(ISensorServer, data, reply); |
Aravind Akella | 841a592 | 2015-06-29 12:37:48 -0700 | [diff] [blame] | 123 | int32_t ret = isDataInjectionEnabled(); |
Aravind Akella | a9e6cc3 | 2015-04-16 18:57:31 -0700 | [diff] [blame] | 124 | reply->writeInt32(static_cast<int32_t>(ret)); |
| 125 | return NO_ERROR; |
| 126 | } |
Mathias Agopian | 589ce85 | 2010-07-13 22:21:56 -0700 | [diff] [blame] | 127 | } |
| 128 | return BBinder::onTransact(code, data, reply, flags); |
| 129 | } |
| 130 | |
| 131 | // ---------------------------------------------------------------------------- |
| 132 | }; // namespace android |