blob: 3c85ec0f999cf9bfc92b7bf876db9f64f5d70de5 [file] [log] [blame]
Mathias Agopian589ce852010-07-13 22:21:56 -07001/*
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
32namespace android {
33// ----------------------------------------------------------------------------
34
35enum {
36 GET_SENSOR_LIST = IBinder::FIRST_CALL_TRANSACTION,
37 CREATE_SENSOR_EVENT_CONNECTION,
38};
39
40class BpSensorServer : public BpInterface<ISensorServer>
41{
42public:
43 BpSensorServer(const sp<IBinder>& impl)
44 : BpInterface<ISensorServer>(impl)
45 {
46 }
47
Dan Stozad723bd72014-11-18 10:24:03 -080048 virtual ~BpSensorServer();
49
Mathias Agopian589ce852010-07-13 22:21:56 -070050 virtual Vector<Sensor> getSensorList()
51 {
52 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070053 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Mathias Agopian589ce852010-07-13 22:21:56 -070054 remote()->transact(GET_SENSOR_LIST, data, &reply);
55 Sensor s;
56 Vector<Sensor> v;
Dan Stozad723bd72014-11-18 10:24:03 -080057 uint32_t n = reply.readUint32();
Mathias Agopian589ce852010-07-13 22:21:56 -070058 v.setCapacity(n);
59 while (n--) {
Mathias Agopian8683fca2012-08-12 19:37:16 -070060 reply.read(s);
Mathias Agopian589ce852010-07-13 22:21:56 -070061 v.add(s);
62 }
63 return v;
64 }
65
Aravind Akella4949c502015-02-11 15:54:35 -080066 virtual sp<ISensorEventConnection> createSensorEventConnection(const String8& packageName)
Mathias Agopian589ce852010-07-13 22:21:56 -070067 {
68 Parcel data, reply;
Mathias Agopiana7352c92010-07-14 23:41:37 -070069 data.writeInterfaceToken(ISensorServer::getInterfaceDescriptor());
Aravind Akella4949c502015-02-11 15:54:35 -080070 data.writeString8(packageName);
Mathias Agopian589ce852010-07-13 22:21:56 -070071 remote()->transact(CREATE_SENSOR_EVENT_CONNECTION, data, &reply);
72 return interface_cast<ISensorEventConnection>(reply.readStrongBinder());
73 }
74};
75
Dan Stozad723bd72014-11-18 10:24:03 -080076// Out-of-line virtual method definition to trigger vtable emission in this
77// translation unit (see clang warning -Wweak-vtables)
78BpSensorServer::~BpSensorServer() {}
79
Mathias Agopian589ce852010-07-13 22:21:56 -070080IMPLEMENT_META_INTERFACE(SensorServer, "android.gui.SensorServer");
81
82// ----------------------------------------------------------------------
83
84status_t BnSensorServer::onTransact(
85 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
86{
87 switch(code) {
88 case GET_SENSOR_LIST: {
89 CHECK_INTERFACE(ISensorServer, data, reply);
90 Vector<Sensor> v(getSensorList());
91 size_t n = v.size();
Dan Stozad723bd72014-11-18 10:24:03 -080092 reply->writeUint32(static_cast<uint32_t>(n));
93 for (size_t i = 0; i < n; i++) {
Mathias Agopian8683fca2012-08-12 19:37:16 -070094 reply->write(v[i]);
Mathias Agopian589ce852010-07-13 22:21:56 -070095 }
96 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080097 }
Mathias Agopian589ce852010-07-13 22:21:56 -070098 case CREATE_SENSOR_EVENT_CONNECTION: {
99 CHECK_INTERFACE(ISensorServer, data, reply);
Aravind Akella4949c502015-02-11 15:54:35 -0800100 String8 packageName = data.readString8();
101 sp<ISensorEventConnection> connection(createSensorEventConnection(packageName));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800102 reply->writeStrongBinder(IInterface::asBinder(connection));
Mathias Agopian589ce852010-07-13 22:21:56 -0700103 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -0800104 }
Mathias Agopian589ce852010-07-13 22:21:56 -0700105 }
106 return BBinder::onTransact(code, data, reply, flags);
107}
108
109// ----------------------------------------------------------------------------
110}; // namespace android