blob: 9411e204e97d71b10a4bc8c819b9348b7b64352c [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
Mathias Agopiana7352c92010-07-14 23:41:37 -070017#define LOG_TAG "Sensors"
18
Mathias Agopian801ea092017-03-06 15:05:04 -080019#include <sensor/SensorManager.h>
20
Mathias Agopian589ce852010-07-13 22:21:56 -070021#include <stdint.h>
22#include <sys/types.h>
23
Peng Xue36e3472016-11-03 11:57:10 -070024#include <cutils/native_handle.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070025#include <utils/Errors.h>
26#include <utils/RefBase.h>
27#include <utils/Singleton.h>
28
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +020029#include <android/companion/virtualnative/IVirtualDeviceManagerNative.h>
30
Mathias Agopian1a2b83a2011-10-16 22:15:23 -070031#include <binder/IBinder.h>
Jiyong Park47f876b2018-04-17 13:56:46 +090032#include <binder/IPermissionController.h>
Mathias Agopiana7352c92010-07-14 23:41:37 -070033#include <binder/IServiceManager.h>
34
Mathias Agopian801ea092017-03-06 15:05:04 -080035#include <sensor/ISensorServer.h>
36#include <sensor/ISensorEventConnection.h>
37#include <sensor/Sensor.h>
38#include <sensor/SensorEventQueue.h>
Mathias Agopian589ce852010-07-13 22:21:56 -070039
Shai Barack9b534db2024-01-25 00:16:03 +000040#include <com_android_hardware_libsensor_flags.h>
41
Mathias Agopian589ce852010-07-13 22:21:56 -070042// ----------------------------------------------------------------------------
43namespace android {
44// ----------------------------------------------------------------------------
45
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +020046namespace {
47
48using ::android::companion::virtualnative::IVirtualDeviceManagerNative;
49
50static constexpr int DEVICE_ID_DEFAULT = 0;
51
52// Returns the deviceId of the device where this uid is observed. If the uid is present on more than
53// one devices, return the default deviceId.
54int getDeviceIdForUid(uid_t uid) {
55 sp<IBinder> binder =
56 defaultServiceManager()->checkService(String16("virtualdevice_native"));
57 if (binder != nullptr) {
58 auto vdm = interface_cast<IVirtualDeviceManagerNative>(binder);
59 std::vector<int> deviceIds;
60 vdm->getDeviceIdsForUid(uid, &deviceIds);
61 // If the UID is associated with multiple virtual devices, use the default device's
62 // sensors as we cannot disambiguate here. This effectively means that the app has
63 // activities on different devices at the same time, so it must handle the device
64 // awareness by itself.
65 if (deviceIds.size() == 1) {
66 const int deviceId = deviceIds.at(0);
67 int devicePolicy = IVirtualDeviceManagerNative::DEVICE_POLICY_DEFAULT;
68 vdm->getDevicePolicy(deviceId,
69 IVirtualDeviceManagerNative::POLICY_TYPE_SENSORS,
70 &devicePolicy);
71 if (devicePolicy == IVirtualDeviceManagerNative::DEVICE_POLICY_CUSTOM) {
72 return deviceId;
73 }
74 }
75 } else {
76 ALOGW("Cannot get virtualdevice_native service");
77 }
78 return DEVICE_ID_DEFAULT;
79}
80
81} // namespace
82
Peng Xufe5476a2017-03-17 17:27:42 -070083Mutex SensorManager::sLock;
84std::map<String16, SensorManager*> SensorManager::sPackageInstances;
Aravind Akellae2806cb2015-07-29 18:03:48 -070085
86SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) {
Peng Xufe5476a2017-03-17 17:27:42 -070087 waitForSensorService(nullptr);
88
Aravind Akellae2806cb2015-07-29 18:03:48 -070089 Mutex::Autolock _l(sLock);
90 SensorManager* sensorManager;
Peng Xufe5476a2017-03-17 17:27:42 -070091 auto iterator = sPackageInstances.find(packageName);
Aravind Akellae2806cb2015-07-29 18:03:48 -070092
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +010093 const uid_t uid = IPCThreadState::self()->getCallingUid();
94 const int deviceId = getDeviceIdForUid(uid);
95
96 // Return the cached instance if the device association of the package has not changed.
Aravind Akellae2806cb2015-07-29 18:03:48 -070097 if (iterator != sPackageInstances.end()) {
98 sensorManager = iterator->second;
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +010099 if (sensorManager->mDeviceId == deviceId) {
100 return *sensorManager;
Aravind Akellae2806cb2015-07-29 18:03:48 -0700101 }
Aravind Akellae2806cb2015-07-29 18:03:48 -0700102 }
103
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +0100104 // It is possible that the calling code has no access to the package name.
105 // In this case we will get the packages for the calling UID and pick the
106 // first one for attributing the app op. This will work correctly for
107 // runtime permissions as for legacy apps we will toggle the app op for
108 // all packages in the UID. The caveat is that the operation may be attributed
109 // to the wrong package and stats based on app ops may be slightly off.
110 String16 opPackageName = packageName;
111 if (opPackageName.size() <= 0) {
112 sp<IBinder> binder = defaultServiceManager()->getService(String16("permission"));
113 if (binder != nullptr) {
114 Vector<String16> packages;
115 interface_cast<IPermissionController>(binder)->getPackagesForUid(uid, packages);
116 if (!packages.isEmpty()) {
117 opPackageName = packages[0];
118 } else {
119 ALOGE("No packages for calling UID");
120 }
121 } else {
122 ALOGE("Cannot get permission service");
123 }
124 }
125
126 sensorManager = new SensorManager(opPackageName, deviceId);
127
128 // If we had no package name, we looked it up from the UID and the sensor
129 // manager instance we created should also be mapped to the empty package
130 // name, to avoid looking up the packages for a UID and get the same result.
131 if (packageName.size() <= 0) {
132 sPackageInstances.insert(std::make_pair(String16(), sensorManager));
133 }
134
135 // Stash the per package sensor manager.
136 sPackageInstances.insert(std::make_pair(opPackageName, sensorManager));
137
Aravind Akellae2806cb2015-07-29 18:03:48 -0700138 return *sensorManager;
139}
140
Anthony Stange9352ab12023-02-21 17:57:38 +0000141void SensorManager::removeInstanceForPackage(const String16& packageName) {
142 Mutex::Autolock _l(sLock);
143 auto iterator = sPackageInstances.find(packageName);
144 if (iterator != sPackageInstances.end()) {
145 SensorManager* sensorManager = iterator->second;
146 delete sensorManager;
147 sPackageInstances.erase(iterator);
148 }
149}
150
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +0200151SensorManager::SensorManager(const String16& opPackageName, int deviceId)
152 : mSensorList(nullptr), mOpPackageName(opPackageName), mDeviceId(deviceId),
153 mDirectConnectionHandle(1) {
Brian Duddie8bbd6f42019-06-06 16:43:41 -0700154 Mutex::Autolock _l(mLock);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700155 assertStateLocked();
Mathias Agopian589ce852010-07-13 22:21:56 -0700156}
157
Peng Xu2576cb62016-01-20 00:22:09 -0800158SensorManager::~SensorManager() {
Mathias Agopiana7352c92010-07-14 23:41:37 -0700159 free(mSensorList);
Erik Staatsd35a5742022-02-04 06:37:58 -0800160 free(mDynamicSensorList);
Mathias Agopian589ce852010-07-13 22:21:56 -0700161}
162
Peng Xufe5476a2017-03-17 17:27:42 -0700163status_t SensorManager::waitForSensorService(sp<ISensorServer> *server) {
164 // try for 300 seconds (60*5(getService() tries for 5 seconds)) before giving up ...
165 sp<ISensorServer> s;
166 const String16 name("sensorservice");
167 for (int i = 0; i < 60; i++) {
168 status_t err = getService(name, &s);
169 switch (err) {
170 case NAME_NOT_FOUND:
171 sleep(1);
172 continue;
173 case NO_ERROR:
174 if (server != nullptr) {
175 *server = s;
176 }
177 return NO_ERROR;
178 default:
179 return err;
180 }
181 }
182 return TIMED_OUT;
183}
184
Peng Xu2576cb62016-01-20 00:22:09 -0800185void SensorManager::sensorManagerDied() {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700186 Mutex::Autolock _l(mLock);
187 mSensorServer.clear();
188 free(mSensorList);
Yi Kongd5e079f2018-07-17 16:08:27 -0700189 mSensorList = nullptr;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700190 mSensors.clear();
Erik Staatsd35a5742022-02-04 06:37:58 -0800191 free(mDynamicSensorList);
192 mDynamicSensorList = nullptr;
193 mDynamicSensors.clear();
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700194}
195
Peng Xu2576cb62016-01-20 00:22:09 -0800196status_t SensorManager::assertStateLocked() {
Shai Barack9b534db2024-01-25 00:16:03 +0000197#if COM_ANDROID_HARDWARE_LIBSENSOR_FLAGS(SENSORMANAGER_PING_BINDER)
198 if (mSensorServer == nullptr) {
199#else
Aravind Akella8f35ca92015-08-17 15:22:12 -0700200 bool initSensorManager = false;
Yi Kongd5e079f2018-07-17 16:08:27 -0700201 if (mSensorServer == nullptr) {
Aravind Akella8f35ca92015-08-17 15:22:12 -0700202 initSensorManager = true;
203 } else {
204 // Ping binder to check if sensorservice is alive.
205 status_t err = IInterface::asBinder(mSensorServer)->pingBinder();
206 if (err != NO_ERROR) {
207 initSensorManager = true;
208 }
209 }
210 if (initSensorManager) {
Shai Barack9b534db2024-01-25 00:16:03 +0000211#endif
Peng Xufe5476a2017-03-17 17:27:42 -0700212 waitForSensorService(&mSensorServer);
213 LOG_ALWAYS_FATAL_IF(mSensorServer == nullptr, "getService(SensorService) NULL");
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700214
215 class DeathObserver : public IBinder::DeathRecipient {
Peng Xu2576cb62016-01-20 00:22:09 -0800216 SensorManager& mSensorManager;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700217 virtual void binderDied(const wp<IBinder>& who) {
Yi Kong82d7c632019-09-20 12:10:47 -0700218 ALOGW("sensorservice died [%p]", static_cast<void*>(who.unsafe_get()));
Peng Xu2576cb62016-01-20 00:22:09 -0800219 mSensorManager.sensorManagerDied();
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700220 }
221 public:
Chih-Hung Hsieh68a593e2016-04-28 09:14:32 -0700222 explicit DeathObserver(SensorManager& mgr) : mSensorManager(mgr) { }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700223 };
224
225 mDeathObserver = new DeathObserver(*const_cast<SensorManager *>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800226 IInterface::asBinder(mSensorServer)->linkToDeath(mDeathObserver);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700227
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +0200228 if (mDeviceId == DEVICE_ID_DEFAULT) {
229 mSensors = mSensorServer->getSensorList(mOpPackageName);
230 } else {
231 mSensors = mSensorServer->getRuntimeSensorList(mOpPackageName, mDeviceId);
232 }
233
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700234 size_t count = mSensors.size();
Devin Moore49600b12023-04-25 00:17:13 +0000235 // If count is 0, mSensorList will be non-null. This is old
236 // existing behavior and callers expect this.
Dan Stozad723bd72014-11-18 10:24:03 -0800237 mSensorList =
238 static_cast<Sensor const**>(malloc(count * sizeof(Sensor*)));
Yi Kongd5e079f2018-07-17 16:08:27 -0700239 LOG_ALWAYS_FATAL_IF(mSensorList == nullptr, "mSensorList NULL");
Aravind Akella8f35ca92015-08-17 15:22:12 -0700240
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700241 for (size_t i=0 ; i<count ; i++) {
242 mSensorList[i] = mSensors.array() + i;
243 }
244 }
245
246 return NO_ERROR;
247}
248
Peng Xu2576cb62016-01-20 00:22:09 -0800249ssize_t SensorManager::getSensorList(Sensor const* const** list) {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700250 Mutex::Autolock _l(mLock);
251 status_t err = assertStateLocked();
252 if (err < 0) {
Dan Stozad723bd72014-11-18 10:24:03 -0800253 return static_cast<ssize_t>(err);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700254 }
Mathias Agopian589ce852010-07-13 22:21:56 -0700255 *list = mSensorList;
Dan Stozad723bd72014-11-18 10:24:03 -0800256 return static_cast<ssize_t>(mSensors.size());
Mathias Agopian589ce852010-07-13 22:21:56 -0700257}
258
Vladimir Komsiyski157e4e02023-12-07 18:52:18 +0100259ssize_t SensorManager::getDefaultDeviceSensorList(Vector<Sensor> & list) {
260 Mutex::Autolock _l(mLock);
261 status_t err = assertStateLocked();
262 if (err < 0) {
263 return static_cast<ssize_t>(err);
264 }
265
266 if (mDeviceId == DEVICE_ID_DEFAULT) {
267 list = mSensors;
268 } else {
269 list = mSensorServer->getSensorList(mOpPackageName);
270 }
271
272 return static_cast<ssize_t>(list.size());
273}
274
Peng Xu2576cb62016-01-20 00:22:09 -0800275ssize_t SensorManager::getDynamicSensorList(Vector<Sensor> & dynamicSensors) {
276 Mutex::Autolock _l(mLock);
277 status_t err = assertStateLocked();
278 if (err < 0) {
279 return static_cast<ssize_t>(err);
280 }
281
282 dynamicSensors = mSensorServer->getDynamicSensorList(mOpPackageName);
283 size_t count = dynamicSensors.size();
284
285 return static_cast<ssize_t>(count);
286}
287
Vladimir Komsiyskif76bba52022-10-23 10:56:06 +0200288ssize_t SensorManager::getRuntimeSensorList(int deviceId, Vector<Sensor>& runtimeSensors) {
289 Mutex::Autolock _l(mLock);
290 status_t err = assertStateLocked();
291 if (err < 0) {
292 return static_cast<ssize_t>(err);
293 }
294
295 runtimeSensors = mSensorServer->getRuntimeSensorList(mOpPackageName, deviceId);
296 size_t count = runtimeSensors.size();
297
298 return static_cast<ssize_t>(count);
299}
300
Erik Staatsd35a5742022-02-04 06:37:58 -0800301ssize_t SensorManager::getDynamicSensorList(Sensor const* const** list) {
302 Mutex::Autolock _l(mLock);
303 status_t err = assertStateLocked();
304 if (err < 0) {
305 return static_cast<ssize_t>(err);
306 }
307
308 free(mDynamicSensorList);
309 mDynamicSensorList = nullptr;
310 mDynamicSensors = mSensorServer->getDynamicSensorList(mOpPackageName);
311 size_t dynamicCount = mDynamicSensors.size();
312 if (dynamicCount > 0) {
313 mDynamicSensorList = static_cast<Sensor const**>(
314 malloc(dynamicCount * sizeof(Sensor*)));
315 if (mDynamicSensorList == nullptr) {
316 ALOGE("Failed to allocate dynamic sensor list for %zu sensors.",
317 dynamicCount);
318 return static_cast<ssize_t>(NO_MEMORY);
319 }
320
321 for (size_t i = 0; i < dynamicCount; i++) {
322 mDynamicSensorList[i] = mDynamicSensors.array() + i;
323 }
324 }
325
326 *list = mDynamicSensorList;
327 return static_cast<ssize_t>(mDynamicSensors.size());
328}
329
Mathias Agopiana7352c92010-07-14 23:41:37 -0700330Sensor const* SensorManager::getDefaultSensor(int type)
Mathias Agopian589ce852010-07-13 22:21:56 -0700331{
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700332 Mutex::Autolock _l(mLock);
333 if (assertStateLocked() == NO_ERROR) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700334 bool wakeUpSensor = false;
335 // For the following sensor types, return a wake-up sensor. These types are by default
336 // defined as wake-up sensors. For the rest of the sensor types defined in sensors.h return
337 // a non_wake-up version.
338 if (type == SENSOR_TYPE_PROXIMITY || type == SENSOR_TYPE_SIGNIFICANT_MOTION ||
339 type == SENSOR_TYPE_TILT_DETECTOR || type == SENSOR_TYPE_WAKE_GESTURE ||
Nick Vaccaro5e7f79b2016-10-17 15:40:51 -0700340 type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE ||
Nick Vaccaro2e990eb2017-01-12 21:13:58 -0800341 type == SENSOR_TYPE_WRIST_TILT_GESTURE ||
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500342 type == SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT || type == SENSOR_TYPE_HINGE_ANGLE) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700343 wakeUpSensor = true;
344 }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700345 // For now we just return the first sensor of that type we find.
346 // in the future it will make sense to let the SensorService make
347 // that decision.
348 for (size_t i=0 ; i<mSensors.size() ; i++) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700349 if (mSensorList[i]->getType() == type &&
350 mSensorList[i]->isWakeUpSensor() == wakeUpSensor) {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700351 return mSensorList[i];
Aravind Akellab37ba392014-08-05 14:53:07 -0700352 }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700353 }
Mathias Agopiana7352c92010-07-14 23:41:37 -0700354 }
Yi Kongd5e079f2018-07-17 16:08:27 -0700355 return nullptr;
Mathias Agopian589ce852010-07-13 22:21:56 -0700356}
357
Arthur Ishiguro340882c2021-02-18 15:17:44 -0800358sp<SensorEventQueue> SensorManager::createEventQueue(
359 String8 packageName, int mode, String16 attributionTag) {
Mathias Agopianbe58de02011-10-16 00:38:30 -0700360 sp<SensorEventQueue> queue;
361
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700362 Mutex::Autolock _l(mLock);
363 while (assertStateLocked() == NO_ERROR) {
Arthur Ishiguro340882c2021-02-18 15:17:44 -0800364 sp<ISensorEventConnection> connection = mSensorServer->createSensorEventConnection(
365 packageName, mode, mOpPackageName, attributionTag);
Yi Kongd5e079f2018-07-17 16:08:27 -0700366 if (connection == nullptr) {
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700367 // SensorService just died or the app doesn't have required permissions.
368 ALOGE("createEventQueue: connection is NULL.");
Yi Kongd5e079f2018-07-17 16:08:27 -0700369 return nullptr;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700370 }
371 queue = new SensorEventQueue(connection);
372 break;
Mathias Agopianbe58de02011-10-16 00:38:30 -0700373 }
Mathias Agopianbe58de02011-10-16 00:38:30 -0700374 return queue;
Mathias Agopian589ce852010-07-13 22:21:56 -0700375}
376
Aravind Akella841a5922015-06-29 12:37:48 -0700377bool SensorManager::isDataInjectionEnabled() {
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700378 Mutex::Autolock _l(mLock);
379 if (assertStateLocked() == NO_ERROR) {
Aravind Akella841a5922015-06-29 12:37:48 -0700380 return mSensorServer->isDataInjectionEnabled();
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700381 }
Aravind Akella841a5922015-06-29 12:37:48 -0700382 return false;
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700383}
384
Mark Wheatley8f285d92023-07-07 20:07:18 +0000385bool SensorManager::isReplayDataInjectionEnabled() {
386 Mutex::Autolock _l(mLock);
387 if (assertStateLocked() == NO_ERROR) {
388 return mSensorServer->isReplayDataInjectionEnabled();
389 }
390 return false;
391}
392
393bool SensorManager::isHalBypassReplayDataInjectionEnabled() {
394 Mutex::Autolock _l(mLock);
395 if (assertStateLocked() == NO_ERROR) {
396 return mSensorServer->isHalBypassReplayDataInjectionEnabled();
397 }
398 return false;
399}
400
Peng Xue36e3472016-11-03 11:57:10 -0700401int SensorManager::createDirectChannel(
402 size_t size, int channelType, const native_handle_t *resourceHandle) {
Vladimir Komsiyski4871f092023-01-19 18:25:43 +0100403 static constexpr int DEFAULT_DEVICE_ID = 0;
404 return createDirectChannel(DEFAULT_DEVICE_ID, size, channelType, resourceHandle);
405}
406
407int SensorManager::createDirectChannel(
408 int deviceId, size_t size, int channelType, const native_handle_t *resourceHandle) {
Peng Xue36e3472016-11-03 11:57:10 -0700409 Mutex::Autolock _l(mLock);
410 if (assertStateLocked() != NO_ERROR) {
411 return NO_INIT;
412 }
413
Peng Xud9c8a862017-03-05 01:48:11 -0800414 if (channelType != SENSOR_DIRECT_MEM_TYPE_ASHMEM
415 && channelType != SENSOR_DIRECT_MEM_TYPE_GRALLOC) {
416 ALOGE("Bad channel shared memory type %d", channelType);
417 return BAD_VALUE;
Peng Xue36e3472016-11-03 11:57:10 -0700418 }
Peng Xud9c8a862017-03-05 01:48:11 -0800419
420 sp<ISensorEventConnection> conn =
Vladimir Komsiyski4871f092023-01-19 18:25:43 +0100421 mSensorServer->createSensorDirectConnection(mOpPackageName, deviceId,
Peng Xud9c8a862017-03-05 01:48:11 -0800422 static_cast<uint32_t>(size),
423 static_cast<int32_t>(channelType),
424 SENSOR_DIRECT_FMT_SENSORS_EVENT, resourceHandle);
425 if (conn == nullptr) {
426 return NO_MEMORY;
427 }
428
429 int nativeHandle = mDirectConnectionHandle++;
430 mDirectConnection.emplace(nativeHandle, conn);
431 return nativeHandle;
Peng Xue36e3472016-11-03 11:57:10 -0700432}
433
434void SensorManager::destroyDirectChannel(int channelNativeHandle) {
435 Mutex::Autolock _l(mLock);
436 if (assertStateLocked() == NO_ERROR) {
437 mDirectConnection.erase(channelNativeHandle);
438 }
439}
440
441int SensorManager::configureDirectChannel(int channelNativeHandle, int sensorHandle, int rateLevel) {
442 Mutex::Autolock _l(mLock);
443 if (assertStateLocked() != NO_ERROR) {
444 return NO_INIT;
445 }
446
447 auto i = mDirectConnection.find(channelNativeHandle);
448 if (i == mDirectConnection.end()) {
449 ALOGE("Cannot find the handle in client direct connection table");
450 return BAD_VALUE;
451 }
452
453 int ret;
454 ret = i->second->configureChannel(sensorHandle, rateLevel);
455 ALOGE_IF(ret < 0, "SensorManager::configureChannel (%d, %d) returns %d",
456 static_cast<int>(sensorHandle), static_cast<int>(rateLevel),
457 static_cast<int>(ret));
458 return ret;
459}
460
Peng Xudd5c5cb2017-03-16 17:39:43 -0700461int SensorManager::setOperationParameter(
Alexey Polyudov88711e82017-05-23 19:54:04 -0700462 int handle, int type,
463 const Vector<float> &floats, const Vector<int32_t> &ints) {
Peng Xudd5c5cb2017-03-16 17:39:43 -0700464 Mutex::Autolock _l(mLock);
465 if (assertStateLocked() != NO_ERROR) {
466 return NO_INIT;
467 }
Alexey Polyudov88711e82017-05-23 19:54:04 -0700468 return mSensorServer->setOperationParameter(handle, type, floats, ints);
Peng Xudd5c5cb2017-03-16 17:39:43 -0700469}
470
Mathias Agopian589ce852010-07-13 22:21:56 -0700471// ----------------------------------------------------------------------------
472}; // namespace android