blob: b82a79f501a4a1e59bbc6d0fda5b15f73091d026 [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
40// ----------------------------------------------------------------------------
41namespace android {
42// ----------------------------------------------------------------------------
43
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +020044namespace {
45
46using ::android::companion::virtualnative::IVirtualDeviceManagerNative;
47
48static constexpr int DEVICE_ID_DEFAULT = 0;
49
50// Returns the deviceId of the device where this uid is observed. If the uid is present on more than
51// one devices, return the default deviceId.
52int getDeviceIdForUid(uid_t uid) {
53 sp<IBinder> binder =
54 defaultServiceManager()->checkService(String16("virtualdevice_native"));
55 if (binder != nullptr) {
56 auto vdm = interface_cast<IVirtualDeviceManagerNative>(binder);
57 std::vector<int> deviceIds;
58 vdm->getDeviceIdsForUid(uid, &deviceIds);
59 // If the UID is associated with multiple virtual devices, use the default device's
60 // sensors as we cannot disambiguate here. This effectively means that the app has
61 // activities on different devices at the same time, so it must handle the device
62 // awareness by itself.
63 if (deviceIds.size() == 1) {
64 const int deviceId = deviceIds.at(0);
65 int devicePolicy = IVirtualDeviceManagerNative::DEVICE_POLICY_DEFAULT;
66 vdm->getDevicePolicy(deviceId,
67 IVirtualDeviceManagerNative::POLICY_TYPE_SENSORS,
68 &devicePolicy);
69 if (devicePolicy == IVirtualDeviceManagerNative::DEVICE_POLICY_CUSTOM) {
70 return deviceId;
71 }
72 }
73 } else {
74 ALOGW("Cannot get virtualdevice_native service");
75 }
76 return DEVICE_ID_DEFAULT;
77}
78
79} // namespace
80
Peng Xufe5476a2017-03-17 17:27:42 -070081Mutex SensorManager::sLock;
82std::map<String16, SensorManager*> SensorManager::sPackageInstances;
Aravind Akellae2806cb2015-07-29 18:03:48 -070083
84SensorManager& SensorManager::getInstanceForPackage(const String16& packageName) {
Peng Xufe5476a2017-03-17 17:27:42 -070085 waitForSensorService(nullptr);
86
Aravind Akellae2806cb2015-07-29 18:03:48 -070087 Mutex::Autolock _l(sLock);
88 SensorManager* sensorManager;
Peng Xufe5476a2017-03-17 17:27:42 -070089 auto iterator = sPackageInstances.find(packageName);
Aravind Akellae2806cb2015-07-29 18:03:48 -070090
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +010091 const uid_t uid = IPCThreadState::self()->getCallingUid();
92 const int deviceId = getDeviceIdForUid(uid);
93
94 // Return the cached instance if the device association of the package has not changed.
Aravind Akellae2806cb2015-07-29 18:03:48 -070095 if (iterator != sPackageInstances.end()) {
96 sensorManager = iterator->second;
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +010097 if (sensorManager->mDeviceId == deviceId) {
98 return *sensorManager;
Aravind Akellae2806cb2015-07-29 18:03:48 -070099 }
Aravind Akellae2806cb2015-07-29 18:03:48 -0700100 }
101
Vladimir Komsiyski71db5f82023-12-08 09:02:20 +0100102 // It is possible that the calling code has no access to the package name.
103 // In this case we will get the packages for the calling UID and pick the
104 // first one for attributing the app op. This will work correctly for
105 // runtime permissions as for legacy apps we will toggle the app op for
106 // all packages in the UID. The caveat is that the operation may be attributed
107 // to the wrong package and stats based on app ops may be slightly off.
108 String16 opPackageName = packageName;
109 if (opPackageName.size() <= 0) {
110 sp<IBinder> binder = defaultServiceManager()->getService(String16("permission"));
111 if (binder != nullptr) {
112 Vector<String16> packages;
113 interface_cast<IPermissionController>(binder)->getPackagesForUid(uid, packages);
114 if (!packages.isEmpty()) {
115 opPackageName = packages[0];
116 } else {
117 ALOGE("No packages for calling UID");
118 }
119 } else {
120 ALOGE("Cannot get permission service");
121 }
122 }
123
124 sensorManager = new SensorManager(opPackageName, deviceId);
125
126 // If we had no package name, we looked it up from the UID and the sensor
127 // manager instance we created should also be mapped to the empty package
128 // name, to avoid looking up the packages for a UID and get the same result.
129 if (packageName.size() <= 0) {
130 sPackageInstances.insert(std::make_pair(String16(), sensorManager));
131 }
132
133 // Stash the per package sensor manager.
134 sPackageInstances.insert(std::make_pair(opPackageName, sensorManager));
135
Aravind Akellae2806cb2015-07-29 18:03:48 -0700136 return *sensorManager;
137}
138
Anthony Stange9352ab12023-02-21 17:57:38 +0000139void SensorManager::removeInstanceForPackage(const String16& packageName) {
140 Mutex::Autolock _l(sLock);
141 auto iterator = sPackageInstances.find(packageName);
142 if (iterator != sPackageInstances.end()) {
143 SensorManager* sensorManager = iterator->second;
144 delete sensorManager;
145 sPackageInstances.erase(iterator);
146 }
147}
148
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +0200149SensorManager::SensorManager(const String16& opPackageName, int deviceId)
150 : mSensorList(nullptr), mOpPackageName(opPackageName), mDeviceId(deviceId),
151 mDirectConnectionHandle(1) {
Brian Duddie8bbd6f42019-06-06 16:43:41 -0700152 Mutex::Autolock _l(mLock);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700153 assertStateLocked();
Mathias Agopian589ce852010-07-13 22:21:56 -0700154}
155
Peng Xu2576cb62016-01-20 00:22:09 -0800156SensorManager::~SensorManager() {
Mathias Agopiana7352c92010-07-14 23:41:37 -0700157 free(mSensorList);
Erik Staatsd35a5742022-02-04 06:37:58 -0800158 free(mDynamicSensorList);
Mathias Agopian589ce852010-07-13 22:21:56 -0700159}
160
Peng Xufe5476a2017-03-17 17:27:42 -0700161status_t SensorManager::waitForSensorService(sp<ISensorServer> *server) {
162 // try for 300 seconds (60*5(getService() tries for 5 seconds)) before giving up ...
163 sp<ISensorServer> s;
164 const String16 name("sensorservice");
165 for (int i = 0; i < 60; i++) {
166 status_t err = getService(name, &s);
167 switch (err) {
168 case NAME_NOT_FOUND:
169 sleep(1);
170 continue;
171 case NO_ERROR:
172 if (server != nullptr) {
173 *server = s;
174 }
175 return NO_ERROR;
176 default:
177 return err;
178 }
179 }
180 return TIMED_OUT;
181}
182
Peng Xu2576cb62016-01-20 00:22:09 -0800183void SensorManager::sensorManagerDied() {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700184 Mutex::Autolock _l(mLock);
185 mSensorServer.clear();
186 free(mSensorList);
Yi Kongd5e079f2018-07-17 16:08:27 -0700187 mSensorList = nullptr;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700188 mSensors.clear();
Erik Staatsd35a5742022-02-04 06:37:58 -0800189 free(mDynamicSensorList);
190 mDynamicSensorList = nullptr;
191 mDynamicSensors.clear();
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700192}
193
Peng Xu2576cb62016-01-20 00:22:09 -0800194status_t SensorManager::assertStateLocked() {
Aravind Akella8f35ca92015-08-17 15:22:12 -0700195 bool initSensorManager = false;
Yi Kongd5e079f2018-07-17 16:08:27 -0700196 if (mSensorServer == nullptr) {
Aravind Akella8f35ca92015-08-17 15:22:12 -0700197 initSensorManager = true;
198 } else {
199 // Ping binder to check if sensorservice is alive.
200 status_t err = IInterface::asBinder(mSensorServer)->pingBinder();
201 if (err != NO_ERROR) {
202 initSensorManager = true;
203 }
204 }
205 if (initSensorManager) {
Peng Xufe5476a2017-03-17 17:27:42 -0700206 waitForSensorService(&mSensorServer);
207 LOG_ALWAYS_FATAL_IF(mSensorServer == nullptr, "getService(SensorService) NULL");
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700208
209 class DeathObserver : public IBinder::DeathRecipient {
Peng Xu2576cb62016-01-20 00:22:09 -0800210 SensorManager& mSensorManager;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700211 virtual void binderDied(const wp<IBinder>& who) {
Yi Kong82d7c632019-09-20 12:10:47 -0700212 ALOGW("sensorservice died [%p]", static_cast<void*>(who.unsafe_get()));
Peng Xu2576cb62016-01-20 00:22:09 -0800213 mSensorManager.sensorManagerDied();
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700214 }
215 public:
Chih-Hung Hsieh68a593e2016-04-28 09:14:32 -0700216 explicit DeathObserver(SensorManager& mgr) : mSensorManager(mgr) { }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700217 };
218
219 mDeathObserver = new DeathObserver(*const_cast<SensorManager *>(this));
Marco Nelissen2ea926b2014-11-14 08:01:01 -0800220 IInterface::asBinder(mSensorServer)->linkToDeath(mDeathObserver);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700221
Vladimir Komsiyskif1d48af2023-10-06 10:11:44 +0200222 if (mDeviceId == DEVICE_ID_DEFAULT) {
223 mSensors = mSensorServer->getSensorList(mOpPackageName);
224 } else {
225 mSensors = mSensorServer->getRuntimeSensorList(mOpPackageName, mDeviceId);
226 }
227
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700228 size_t count = mSensors.size();
Devin Moore49600b12023-04-25 00:17:13 +0000229 // If count is 0, mSensorList will be non-null. This is old
230 // existing behavior and callers expect this.
Dan Stozad723bd72014-11-18 10:24:03 -0800231 mSensorList =
232 static_cast<Sensor const**>(malloc(count * sizeof(Sensor*)));
Yi Kongd5e079f2018-07-17 16:08:27 -0700233 LOG_ALWAYS_FATAL_IF(mSensorList == nullptr, "mSensorList NULL");
Aravind Akella8f35ca92015-08-17 15:22:12 -0700234
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700235 for (size_t i=0 ; i<count ; i++) {
236 mSensorList[i] = mSensors.array() + i;
237 }
238 }
239
240 return NO_ERROR;
241}
242
Peng Xu2576cb62016-01-20 00:22:09 -0800243ssize_t SensorManager::getSensorList(Sensor const* const** list) {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700244 Mutex::Autolock _l(mLock);
245 status_t err = assertStateLocked();
246 if (err < 0) {
Dan Stozad723bd72014-11-18 10:24:03 -0800247 return static_cast<ssize_t>(err);
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700248 }
Mathias Agopian589ce852010-07-13 22:21:56 -0700249 *list = mSensorList;
Dan Stozad723bd72014-11-18 10:24:03 -0800250 return static_cast<ssize_t>(mSensors.size());
Mathias Agopian589ce852010-07-13 22:21:56 -0700251}
252
Vladimir Komsiyski157e4e02023-12-07 18:52:18 +0100253ssize_t SensorManager::getDefaultDeviceSensorList(Vector<Sensor> & list) {
254 Mutex::Autolock _l(mLock);
255 status_t err = assertStateLocked();
256 if (err < 0) {
257 return static_cast<ssize_t>(err);
258 }
259
260 if (mDeviceId == DEVICE_ID_DEFAULT) {
261 list = mSensors;
262 } else {
263 list = mSensorServer->getSensorList(mOpPackageName);
264 }
265
266 return static_cast<ssize_t>(list.size());
267}
268
Peng Xu2576cb62016-01-20 00:22:09 -0800269ssize_t SensorManager::getDynamicSensorList(Vector<Sensor> & dynamicSensors) {
270 Mutex::Autolock _l(mLock);
271 status_t err = assertStateLocked();
272 if (err < 0) {
273 return static_cast<ssize_t>(err);
274 }
275
276 dynamicSensors = mSensorServer->getDynamicSensorList(mOpPackageName);
277 size_t count = dynamicSensors.size();
278
279 return static_cast<ssize_t>(count);
280}
281
Vladimir Komsiyskif76bba52022-10-23 10:56:06 +0200282ssize_t SensorManager::getRuntimeSensorList(int deviceId, Vector<Sensor>& runtimeSensors) {
283 Mutex::Autolock _l(mLock);
284 status_t err = assertStateLocked();
285 if (err < 0) {
286 return static_cast<ssize_t>(err);
287 }
288
289 runtimeSensors = mSensorServer->getRuntimeSensorList(mOpPackageName, deviceId);
290 size_t count = runtimeSensors.size();
291
292 return static_cast<ssize_t>(count);
293}
294
Erik Staatsd35a5742022-02-04 06:37:58 -0800295ssize_t SensorManager::getDynamicSensorList(Sensor const* const** list) {
296 Mutex::Autolock _l(mLock);
297 status_t err = assertStateLocked();
298 if (err < 0) {
299 return static_cast<ssize_t>(err);
300 }
301
302 free(mDynamicSensorList);
303 mDynamicSensorList = nullptr;
304 mDynamicSensors = mSensorServer->getDynamicSensorList(mOpPackageName);
305 size_t dynamicCount = mDynamicSensors.size();
306 if (dynamicCount > 0) {
307 mDynamicSensorList = static_cast<Sensor const**>(
308 malloc(dynamicCount * sizeof(Sensor*)));
309 if (mDynamicSensorList == nullptr) {
310 ALOGE("Failed to allocate dynamic sensor list for %zu sensors.",
311 dynamicCount);
312 return static_cast<ssize_t>(NO_MEMORY);
313 }
314
315 for (size_t i = 0; i < dynamicCount; i++) {
316 mDynamicSensorList[i] = mDynamicSensors.array() + i;
317 }
318 }
319
320 *list = mDynamicSensorList;
321 return static_cast<ssize_t>(mDynamicSensors.size());
322}
323
Mathias Agopiana7352c92010-07-14 23:41:37 -0700324Sensor const* SensorManager::getDefaultSensor(int type)
Mathias Agopian589ce852010-07-13 22:21:56 -0700325{
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700326 Mutex::Autolock _l(mLock);
327 if (assertStateLocked() == NO_ERROR) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700328 bool wakeUpSensor = false;
329 // For the following sensor types, return a wake-up sensor. These types are by default
330 // defined as wake-up sensors. For the rest of the sensor types defined in sensors.h return
331 // a non_wake-up version.
332 if (type == SENSOR_TYPE_PROXIMITY || type == SENSOR_TYPE_SIGNIFICANT_MOTION ||
333 type == SENSOR_TYPE_TILT_DETECTOR || type == SENSOR_TYPE_WAKE_GESTURE ||
Nick Vaccaro5e7f79b2016-10-17 15:40:51 -0700334 type == SENSOR_TYPE_GLANCE_GESTURE || type == SENSOR_TYPE_PICK_UP_GESTURE ||
Nick Vaccaro2e990eb2017-01-12 21:13:58 -0800335 type == SENSOR_TYPE_WRIST_TILT_GESTURE ||
Anthony Stangefdb1fc82020-01-16 15:02:48 -0500336 type == SENSOR_TYPE_LOW_LATENCY_OFFBODY_DETECT || type == SENSOR_TYPE_HINGE_ANGLE) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700337 wakeUpSensor = true;
338 }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700339 // For now we just return the first sensor of that type we find.
340 // in the future it will make sense to let the SensorService make
341 // that decision.
342 for (size_t i=0 ; i<mSensors.size() ; i++) {
Aravind Akellab37ba392014-08-05 14:53:07 -0700343 if (mSensorList[i]->getType() == type &&
344 mSensorList[i]->isWakeUpSensor() == wakeUpSensor) {
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700345 return mSensorList[i];
Aravind Akellab37ba392014-08-05 14:53:07 -0700346 }
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700347 }
Mathias Agopiana7352c92010-07-14 23:41:37 -0700348 }
Yi Kongd5e079f2018-07-17 16:08:27 -0700349 return nullptr;
Mathias Agopian589ce852010-07-13 22:21:56 -0700350}
351
Arthur Ishiguro340882c2021-02-18 15:17:44 -0800352sp<SensorEventQueue> SensorManager::createEventQueue(
353 String8 packageName, int mode, String16 attributionTag) {
Mathias Agopianbe58de02011-10-16 00:38:30 -0700354 sp<SensorEventQueue> queue;
355
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700356 Mutex::Autolock _l(mLock);
357 while (assertStateLocked() == NO_ERROR) {
Arthur Ishiguro340882c2021-02-18 15:17:44 -0800358 sp<ISensorEventConnection> connection = mSensorServer->createSensorEventConnection(
359 packageName, mode, mOpPackageName, attributionTag);
Yi Kongd5e079f2018-07-17 16:08:27 -0700360 if (connection == nullptr) {
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700361 // SensorService just died or the app doesn't have required permissions.
362 ALOGE("createEventQueue: connection is NULL.");
Yi Kongd5e079f2018-07-17 16:08:27 -0700363 return nullptr;
Mathias Agopian1a2b83a2011-10-16 22:15:23 -0700364 }
365 queue = new SensorEventQueue(connection);
366 break;
Mathias Agopianbe58de02011-10-16 00:38:30 -0700367 }
Mathias Agopianbe58de02011-10-16 00:38:30 -0700368 return queue;
Mathias Agopian589ce852010-07-13 22:21:56 -0700369}
370
Aravind Akella841a5922015-06-29 12:37:48 -0700371bool SensorManager::isDataInjectionEnabled() {
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700372 Mutex::Autolock _l(mLock);
373 if (assertStateLocked() == NO_ERROR) {
Aravind Akella841a5922015-06-29 12:37:48 -0700374 return mSensorServer->isDataInjectionEnabled();
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700375 }
Aravind Akella841a5922015-06-29 12:37:48 -0700376 return false;
Aravind Akellaa9e6cc32015-04-16 18:57:31 -0700377}
378
Mark Wheatley8f285d92023-07-07 20:07:18 +0000379bool SensorManager::isReplayDataInjectionEnabled() {
380 Mutex::Autolock _l(mLock);
381 if (assertStateLocked() == NO_ERROR) {
382 return mSensorServer->isReplayDataInjectionEnabled();
383 }
384 return false;
385}
386
387bool SensorManager::isHalBypassReplayDataInjectionEnabled() {
388 Mutex::Autolock _l(mLock);
389 if (assertStateLocked() == NO_ERROR) {
390 return mSensorServer->isHalBypassReplayDataInjectionEnabled();
391 }
392 return false;
393}
394
Peng Xue36e3472016-11-03 11:57:10 -0700395int SensorManager::createDirectChannel(
396 size_t size, int channelType, const native_handle_t *resourceHandle) {
Vladimir Komsiyski4871f092023-01-19 18:25:43 +0100397 static constexpr int DEFAULT_DEVICE_ID = 0;
398 return createDirectChannel(DEFAULT_DEVICE_ID, size, channelType, resourceHandle);
399}
400
401int SensorManager::createDirectChannel(
402 int deviceId, size_t size, int channelType, const native_handle_t *resourceHandle) {
Peng Xue36e3472016-11-03 11:57:10 -0700403 Mutex::Autolock _l(mLock);
404 if (assertStateLocked() != NO_ERROR) {
405 return NO_INIT;
406 }
407
Peng Xud9c8a862017-03-05 01:48:11 -0800408 if (channelType != SENSOR_DIRECT_MEM_TYPE_ASHMEM
409 && channelType != SENSOR_DIRECT_MEM_TYPE_GRALLOC) {
410 ALOGE("Bad channel shared memory type %d", channelType);
411 return BAD_VALUE;
Peng Xue36e3472016-11-03 11:57:10 -0700412 }
Peng Xud9c8a862017-03-05 01:48:11 -0800413
414 sp<ISensorEventConnection> conn =
Vladimir Komsiyski4871f092023-01-19 18:25:43 +0100415 mSensorServer->createSensorDirectConnection(mOpPackageName, deviceId,
Peng Xud9c8a862017-03-05 01:48:11 -0800416 static_cast<uint32_t>(size),
417 static_cast<int32_t>(channelType),
418 SENSOR_DIRECT_FMT_SENSORS_EVENT, resourceHandle);
419 if (conn == nullptr) {
420 return NO_MEMORY;
421 }
422
423 int nativeHandle = mDirectConnectionHandle++;
424 mDirectConnection.emplace(nativeHandle, conn);
425 return nativeHandle;
Peng Xue36e3472016-11-03 11:57:10 -0700426}
427
428void SensorManager::destroyDirectChannel(int channelNativeHandle) {
429 Mutex::Autolock _l(mLock);
430 if (assertStateLocked() == NO_ERROR) {
431 mDirectConnection.erase(channelNativeHandle);
432 }
433}
434
435int SensorManager::configureDirectChannel(int channelNativeHandle, int sensorHandle, int rateLevel) {
436 Mutex::Autolock _l(mLock);
437 if (assertStateLocked() != NO_ERROR) {
438 return NO_INIT;
439 }
440
441 auto i = mDirectConnection.find(channelNativeHandle);
442 if (i == mDirectConnection.end()) {
443 ALOGE("Cannot find the handle in client direct connection table");
444 return BAD_VALUE;
445 }
446
447 int ret;
448 ret = i->second->configureChannel(sensorHandle, rateLevel);
449 ALOGE_IF(ret < 0, "SensorManager::configureChannel (%d, %d) returns %d",
450 static_cast<int>(sensorHandle), static_cast<int>(rateLevel),
451 static_cast<int>(ret));
452 return ret;
453}
454
Peng Xudd5c5cb2017-03-16 17:39:43 -0700455int SensorManager::setOperationParameter(
Alexey Polyudov88711e82017-05-23 19:54:04 -0700456 int handle, int type,
457 const Vector<float> &floats, const Vector<int32_t> &ints) {
Peng Xudd5c5cb2017-03-16 17:39:43 -0700458 Mutex::Autolock _l(mLock);
459 if (assertStateLocked() != NO_ERROR) {
460 return NO_INIT;
461 }
Alexey Polyudov88711e82017-05-23 19:54:04 -0700462 return mSensorServer->setOperationParameter(handle, type, floats, ints);
Peng Xudd5c5cb2017-03-16 17:39:43 -0700463}
464
Mathias Agopian589ce852010-07-13 22:21:56 -0700465// ----------------------------------------------------------------------------
466}; // namespace android