Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | #define LOG_TAG "SoundTriggerHwService" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include <stdio.h> |
| 21 | #include <string.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <pthread.h> |
| 24 | |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 25 | #include <system/sound_trigger.h> |
| 26 | #include <cutils/atomic.h> |
| 27 | #include <cutils/properties.h> |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 28 | #include <hardware/hardware.h> |
| 29 | #include <media/AudioSystem.h> |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 30 | #include <utils/Errors.h> |
| 31 | #include <utils/Log.h> |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 32 | #include <binder/IServiceManager.h> |
| 33 | #include <binder/MemoryBase.h> |
| 34 | #include <binder/MemoryHeapBase.h> |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 35 | #include <system/sound_trigger.h> |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 36 | #include <ServiceUtilities.h> |
| 37 | #include "SoundTriggerHwService.h" |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 38 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 39 | #ifdef SOUND_TRIGGER_USE_STUB_MODULE |
| 40 | #define HW_MODULE_PREFIX "stub" |
| 41 | #else |
| 42 | #define HW_MODULE_PREFIX "primary" |
| 43 | #endif |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 44 | namespace android { |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 45 | |
| 46 | SoundTriggerHwService::SoundTriggerHwService() |
| 47 | : BnSoundTriggerHwService(), |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 48 | mNextUniqueId(1), |
| 49 | mMemoryDealer(new MemoryDealer(1024 * 1024, "SoundTriggerHwService")), |
| 50 | mCaptureState(false) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 51 | { |
| 52 | } |
| 53 | |
| 54 | void SoundTriggerHwService::onFirstRef() |
| 55 | { |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 56 | int rc; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 57 | |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 58 | sp<SoundTriggerHalInterface> halInterface = |
| 59 | SoundTriggerHalInterface::connectModule(HW_MODULE_PREFIX); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 60 | |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 61 | if (halInterface == 0) { |
| 62 | ALOGW("could not connect to HAL"); |
| 63 | return; |
| 64 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 65 | sound_trigger_module_descriptor descriptor; |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 66 | rc = halInterface->getProperties(&descriptor.properties); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 67 | if (rc != 0) { |
| 68 | ALOGE("could not read implementation properties"); |
| 69 | return; |
| 70 | } |
| 71 | descriptor.handle = |
| 72 | (sound_trigger_module_handle_t)android_atomic_inc(&mNextUniqueId); |
| 73 | ALOGI("loaded default module %s, handle %d", descriptor.properties.description, |
| 74 | descriptor.handle); |
| 75 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 76 | sp<Module> module = new Module(this, halInterface, descriptor); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 77 | mModules.add(descriptor.handle, module); |
| 78 | mCallbackThread = new CallbackThread(this); |
| 79 | } |
| 80 | |
| 81 | SoundTriggerHwService::~SoundTriggerHwService() |
| 82 | { |
| 83 | if (mCallbackThread != 0) { |
| 84 | mCallbackThread->exit(); |
| 85 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | status_t SoundTriggerHwService::listModules(struct sound_trigger_module_descriptor *modules, |
| 89 | uint32_t *numModules) |
| 90 | { |
| 91 | ALOGV("listModules"); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 92 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 93 | IPCThreadState::self()->getCallingUid())) { |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 94 | return PERMISSION_DENIED; |
| 95 | } |
| 96 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 97 | AutoMutex lock(mServiceLock); |
| 98 | if (numModules == NULL || (*numModules != 0 && modules == NULL)) { |
| 99 | return BAD_VALUE; |
| 100 | } |
| 101 | size_t maxModules = *numModules; |
| 102 | *numModules = mModules.size(); |
| 103 | for (size_t i = 0; i < mModules.size() && i < maxModules; i++) { |
| 104 | modules[i] = mModules.valueAt(i)->descriptor(); |
| 105 | } |
| 106 | return NO_ERROR; |
| 107 | } |
| 108 | |
| 109 | status_t SoundTriggerHwService::attach(const sound_trigger_module_handle_t handle, |
| 110 | const sp<ISoundTriggerClient>& client, |
| 111 | sp<ISoundTrigger>& moduleInterface) |
| 112 | { |
| 113 | ALOGV("attach module %d", handle); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 114 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 115 | IPCThreadState::self()->getCallingUid())) { |
Eric Laurent | 8ba53d8 | 2014-08-01 23:15:05 +0000 | [diff] [blame] | 116 | return PERMISSION_DENIED; |
| 117 | } |
| 118 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 119 | AutoMutex lock(mServiceLock); |
| 120 | moduleInterface.clear(); |
| 121 | if (client == 0) { |
| 122 | return BAD_VALUE; |
| 123 | } |
| 124 | ssize_t index = mModules.indexOfKey(handle); |
| 125 | if (index < 0) { |
| 126 | return BAD_VALUE; |
| 127 | } |
| 128 | sp<Module> module = mModules.valueAt(index); |
| 129 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 130 | sp<ModuleClient> moduleClient = module->addClient(client); |
| 131 | if (moduleClient == 0) { |
| 132 | return NO_INIT; |
| 133 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 134 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 135 | moduleClient->setCaptureState_l(mCaptureState); |
| 136 | moduleInterface = moduleClient; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 137 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 138 | return NO_ERROR; |
| 139 | } |
| 140 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 141 | status_t SoundTriggerHwService::setCaptureState(bool active) |
| 142 | { |
| 143 | ALOGV("setCaptureState %d", active); |
| 144 | AutoMutex lock(mServiceLock); |
| 145 | mCaptureState = active; |
| 146 | for (size_t i = 0; i < mModules.size(); i++) { |
| 147 | mModules.valueAt(i)->setCaptureState_l(active); |
| 148 | } |
| 149 | return NO_ERROR; |
| 150 | } |
| 151 | |
| 152 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 153 | static const int kDumpLockRetries = 50; |
| 154 | static const int kDumpLockSleep = 60000; |
| 155 | |
| 156 | static bool tryLock(Mutex& mutex) |
| 157 | { |
| 158 | bool locked = false; |
| 159 | for (int i = 0; i < kDumpLockRetries; ++i) { |
| 160 | if (mutex.tryLock() == NO_ERROR) { |
| 161 | locked = true; |
| 162 | break; |
| 163 | } |
| 164 | usleep(kDumpLockSleep); |
| 165 | } |
| 166 | return locked; |
| 167 | } |
| 168 | |
| 169 | status_t SoundTriggerHwService::dump(int fd, const Vector<String16>& args __unused) { |
| 170 | String8 result; |
| 171 | if (checkCallingPermission(String16("android.permission.DUMP")) == false) { |
| 172 | result.appendFormat("Permission Denial: can't dump SoundTriggerHwService"); |
| 173 | write(fd, result.string(), result.size()); |
| 174 | } else { |
| 175 | bool locked = tryLock(mServiceLock); |
| 176 | // failed to lock - SoundTriggerHwService is probably deadlocked |
| 177 | if (!locked) { |
| 178 | result.append("SoundTriggerHwService may be deadlocked\n"); |
| 179 | write(fd, result.string(), result.size()); |
| 180 | } |
| 181 | |
| 182 | if (locked) mServiceLock.unlock(); |
| 183 | } |
| 184 | return NO_ERROR; |
| 185 | } |
| 186 | |
| 187 | status_t SoundTriggerHwService::onTransact( |
| 188 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { |
| 189 | return BnSoundTriggerHwService::onTransact(code, data, reply, flags); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | // static |
| 194 | void SoundTriggerHwService::recognitionCallback(struct sound_trigger_recognition_event *event, |
| 195 | void *cookie) |
| 196 | { |
| 197 | Module *module = (Module *)cookie; |
| 198 | if (module == NULL) { |
| 199 | return; |
| 200 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 201 | sp<SoundTriggerHwService> service = module->service().promote(); |
| 202 | if (service == 0) { |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | service->sendRecognitionEvent(event, module); |
| 207 | } |
| 208 | |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 209 | sp<IMemory> SoundTriggerHwService::prepareRecognitionEvent( |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 210 | struct sound_trigger_recognition_event *event) |
| 211 | { |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 212 | AutoMutex lock(mMemoryDealerLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 213 | sp<IMemory> eventMemory; |
| 214 | |
| 215 | //sanitize event |
| 216 | switch (event->type) { |
| 217 | case SOUND_MODEL_TYPE_KEYPHRASE: |
| 218 | ALOGW_IF(event->data_size != 0 && event->data_offset != |
| 219 | sizeof(struct sound_trigger_phrase_recognition_event), |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 220 | "prepareRecognitionEvent(): invalid data offset %u for keyphrase event type", |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 221 | event->data_offset); |
| 222 | event->data_offset = sizeof(struct sound_trigger_phrase_recognition_event); |
| 223 | break; |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 224 | case SOUND_MODEL_TYPE_GENERIC: |
| 225 | ALOGW_IF(event->data_size != 0 && event->data_offset != |
| 226 | sizeof(struct sound_trigger_generic_recognition_event), |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 227 | "prepareRecognitionEvent(): invalid data offset %u for generic event type", |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 228 | event->data_offset); |
| 229 | event->data_offset = sizeof(struct sound_trigger_generic_recognition_event); |
| 230 | break; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 231 | case SOUND_MODEL_TYPE_UNKNOWN: |
| 232 | ALOGW_IF(event->data_size != 0 && event->data_offset != |
| 233 | sizeof(struct sound_trigger_recognition_event), |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 234 | "prepareRecognitionEvent(): invalid data offset %u for unknown event type", |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 235 | event->data_offset); |
| 236 | event->data_offset = sizeof(struct sound_trigger_recognition_event); |
| 237 | break; |
| 238 | default: |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 239 | return eventMemory; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | size_t size = event->data_offset + event->data_size; |
| 243 | eventMemory = mMemoryDealer->allocate(size); |
| 244 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 245 | eventMemory.clear(); |
| 246 | return eventMemory; |
| 247 | } |
| 248 | memcpy(eventMemory->pointer(), event, size); |
| 249 | |
| 250 | return eventMemory; |
| 251 | } |
| 252 | |
| 253 | void SoundTriggerHwService::sendRecognitionEvent(struct sound_trigger_recognition_event *event, |
| 254 | Module *module) |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 255 | { |
| 256 | if (module == NULL) { |
| 257 | return; |
| 258 | } |
| 259 | sp<IMemory> eventMemory = prepareRecognitionEvent(event); |
| 260 | if (eventMemory == 0) { |
| 261 | return; |
| 262 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 263 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 264 | sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_RECOGNITION, |
| 265 | eventMemory); |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 266 | callbackEvent->setModule(module); |
| 267 | sendCallbackEvent(callbackEvent); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | // static |
| 271 | void SoundTriggerHwService::soundModelCallback(struct sound_trigger_model_event *event, |
| 272 | void *cookie) |
| 273 | { |
| 274 | Module *module = (Module *)cookie; |
| 275 | if (module == NULL) { |
| 276 | return; |
| 277 | } |
| 278 | sp<SoundTriggerHwService> service = module->service().promote(); |
| 279 | if (service == 0) { |
| 280 | return; |
| 281 | } |
| 282 | |
| 283 | service->sendSoundModelEvent(event, module); |
| 284 | } |
| 285 | |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 286 | sp<IMemory> SoundTriggerHwService::prepareSoundModelEvent(struct sound_trigger_model_event *event) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 287 | { |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 288 | AutoMutex lock(mMemoryDealerLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 289 | sp<IMemory> eventMemory; |
| 290 | |
| 291 | size_t size = event->data_offset + event->data_size; |
| 292 | eventMemory = mMemoryDealer->allocate(size); |
| 293 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 294 | eventMemory.clear(); |
| 295 | return eventMemory; |
| 296 | } |
| 297 | memcpy(eventMemory->pointer(), event, size); |
| 298 | |
| 299 | return eventMemory; |
| 300 | } |
| 301 | |
| 302 | void SoundTriggerHwService::sendSoundModelEvent(struct sound_trigger_model_event *event, |
| 303 | Module *module) |
| 304 | { |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 305 | sp<IMemory> eventMemory = prepareSoundModelEvent(event); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 306 | if (eventMemory == 0) { |
| 307 | return; |
| 308 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 309 | sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SOUNDMODEL, |
| 310 | eventMemory); |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 311 | callbackEvent->setModule(module); |
| 312 | sendCallbackEvent(callbackEvent); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 313 | } |
| 314 | |
| 315 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 316 | sp<IMemory> SoundTriggerHwService::prepareServiceStateEvent_l(sound_trigger_service_state_t state) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 317 | { |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 318 | AutoMutex lock(mMemoryDealerLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 319 | sp<IMemory> eventMemory; |
| 320 | |
| 321 | size_t size = sizeof(sound_trigger_service_state_t); |
| 322 | eventMemory = mMemoryDealer->allocate(size); |
| 323 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 324 | eventMemory.clear(); |
| 325 | return eventMemory; |
| 326 | } |
| 327 | *((sound_trigger_service_state_t *)eventMemory->pointer()) = state; |
| 328 | return eventMemory; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 331 | // call with mServiceLock held |
| 332 | void SoundTriggerHwService::sendServiceStateEvent_l(sound_trigger_service_state_t state, |
| 333 | Module *module) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 334 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 335 | sp<IMemory> eventMemory = prepareServiceStateEvent_l(state); |
| 336 | if (eventMemory == 0) { |
| 337 | return; |
| 338 | } |
| 339 | sp<Module> strongModule; |
| 340 | for (size_t i = 0; i < mModules.size(); i++) { |
| 341 | if (mModules.valueAt(i).get() == module) { |
| 342 | strongModule = mModules.valueAt(i); |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | if (strongModule == 0) { |
| 347 | return; |
| 348 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 349 | sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SERVICE_STATE, |
| 350 | eventMemory); |
| 351 | callbackEvent->setModule(strongModule); |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 352 | sendCallbackEvent(callbackEvent); |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void SoundTriggerHwService::sendServiceStateEvent_l(sound_trigger_service_state_t state, |
| 356 | ModuleClient *moduleClient) |
| 357 | { |
| 358 | sp<IMemory> eventMemory = prepareServiceStateEvent_l(state); |
| 359 | if (eventMemory == 0) { |
| 360 | return; |
| 361 | } |
| 362 | sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SERVICE_STATE, |
| 363 | eventMemory); |
| 364 | callbackEvent->setModuleClient(moduleClient); |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 365 | sendCallbackEvent(callbackEvent); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 366 | } |
| 367 | |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 368 | void SoundTriggerHwService::sendCallbackEvent(const sp<CallbackEvent>& event) |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 369 | { |
| 370 | mCallbackThread->sendCallbackEvent(event); |
| 371 | } |
| 372 | |
| 373 | void SoundTriggerHwService::onCallbackEvent(const sp<CallbackEvent>& event) |
| 374 | { |
| 375 | ALOGV("onCallbackEvent"); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 376 | sp<Module> module; |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 377 | sp<ModuleClient> moduleClient; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 378 | { |
| 379 | AutoMutex lock(mServiceLock); |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 380 | //CallbackEvent is either for Module or ModuleClient |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 381 | module = event->mModule.promote(); |
| 382 | if (module == 0) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 383 | moduleClient = event->mModuleClient.promote(); |
| 384 | if (moduleClient == 0) { |
| 385 | return; |
| 386 | } |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 387 | } else { |
| 388 | // Sanity check on this being a Module we know about. |
| 389 | bool foundModule = false; |
| 390 | for (size_t i = 0; i < mModules.size(); i++) { |
| 391 | if (mModules.valueAt(i).get() == module.get()) { |
| 392 | foundModule = true; |
| 393 | break; |
| 394 | } |
| 395 | } |
| 396 | if (!foundModule) { |
| 397 | ALOGE("onCallbackEvent for unknown module"); |
| 398 | return; |
| 399 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 402 | if (module != 0) { |
| 403 | ALOGV("onCallbackEvent for module"); |
| 404 | module->onCallbackEvent(event); |
| 405 | } else if (moduleClient != 0) { |
| 406 | ALOGV("onCallbackEvent for moduleClient"); |
| 407 | moduleClient->onCallbackEvent(event); |
| 408 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 409 | { |
| 410 | AutoMutex lock(mServiceLock); |
| 411 | // clear now to execute with mServiceLock locked |
| 412 | event->mMemory.clear(); |
| 413 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | #undef LOG_TAG |
| 417 | #define LOG_TAG "SoundTriggerHwService::CallbackThread" |
| 418 | |
| 419 | SoundTriggerHwService::CallbackThread::CallbackThread(const wp<SoundTriggerHwService>& service) |
| 420 | : mService(service) |
| 421 | { |
| 422 | } |
| 423 | |
| 424 | SoundTriggerHwService::CallbackThread::~CallbackThread() |
| 425 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 426 | while (!mEventQueue.isEmpty()) { |
| 427 | mEventQueue[0]->mMemory.clear(); |
| 428 | mEventQueue.removeAt(0); |
| 429 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | void SoundTriggerHwService::CallbackThread::onFirstRef() |
| 433 | { |
| 434 | run("soundTrigger cbk", ANDROID_PRIORITY_URGENT_AUDIO); |
| 435 | } |
| 436 | |
| 437 | bool SoundTriggerHwService::CallbackThread::threadLoop() |
| 438 | { |
| 439 | while (!exitPending()) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 440 | sp<CallbackEvent> event; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 441 | sp<SoundTriggerHwService> service; |
| 442 | { |
| 443 | Mutex::Autolock _l(mCallbackLock); |
| 444 | while (mEventQueue.isEmpty() && !exitPending()) { |
| 445 | ALOGV("CallbackThread::threadLoop() sleep"); |
| 446 | mCallbackCond.wait(mCallbackLock); |
| 447 | ALOGV("CallbackThread::threadLoop() wake up"); |
| 448 | } |
| 449 | if (exitPending()) { |
| 450 | break; |
| 451 | } |
| 452 | event = mEventQueue[0]; |
| 453 | mEventQueue.removeAt(0); |
| 454 | service = mService.promote(); |
| 455 | } |
| 456 | if (service != 0) { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 457 | service->onCallbackEvent(event); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 458 | } |
| 459 | } |
| 460 | return false; |
| 461 | } |
| 462 | |
| 463 | void SoundTriggerHwService::CallbackThread::exit() |
| 464 | { |
| 465 | Mutex::Autolock _l(mCallbackLock); |
| 466 | requestExit(); |
| 467 | mCallbackCond.broadcast(); |
| 468 | } |
| 469 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 470 | void SoundTriggerHwService::CallbackThread::sendCallbackEvent( |
| 471 | const sp<SoundTriggerHwService::CallbackEvent>& event) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 472 | { |
| 473 | AutoMutex lock(mCallbackLock); |
| 474 | mEventQueue.add(event); |
| 475 | mCallbackCond.signal(); |
| 476 | } |
| 477 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 478 | SoundTriggerHwService::CallbackEvent::CallbackEvent(event_type type, sp<IMemory> memory) |
| 479 | : mType(type), mMemory(memory) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 480 | { |
| 481 | } |
| 482 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 483 | SoundTriggerHwService::CallbackEvent::~CallbackEvent() |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 484 | { |
| 485 | } |
| 486 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 487 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 488 | #undef LOG_TAG |
| 489 | #define LOG_TAG "SoundTriggerHwService::Module" |
| 490 | |
| 491 | SoundTriggerHwService::Module::Module(const sp<SoundTriggerHwService>& service, |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 492 | const sp<SoundTriggerHalInterface>& halInterface, |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 493 | sound_trigger_module_descriptor descriptor) |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 494 | : mService(service), mHalInterface(halInterface), mDescriptor(descriptor), |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 495 | mServiceState(SOUND_TRIGGER_STATE_NO_INIT) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 496 | { |
| 497 | } |
| 498 | |
| 499 | SoundTriggerHwService::Module::~Module() { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 500 | mModuleClients.clear(); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 503 | sp<SoundTriggerHwService::ModuleClient> |
| 504 | SoundTriggerHwService::Module::addClient(const sp<ISoundTriggerClient>& client) |
| 505 | { |
| 506 | AutoMutex lock(mLock); |
| 507 | sp<ModuleClient> moduleClient; |
| 508 | |
| 509 | for (size_t i = 0; i < mModuleClients.size(); i++) { |
| 510 | if (mModuleClients[i]->client() == client) { |
| 511 | // Client already present, reuse client |
| 512 | return moduleClient; |
| 513 | } |
| 514 | } |
| 515 | moduleClient = new ModuleClient(this, client); |
| 516 | |
| 517 | ALOGV("addClient() client %p", moduleClient.get()); |
| 518 | mModuleClients.add(moduleClient); |
| 519 | |
| 520 | return moduleClient; |
| 521 | } |
| 522 | |
| 523 | void SoundTriggerHwService::Module::detach(const sp<ModuleClient>& moduleClient) |
| 524 | { |
| 525 | ALOGV("Module::detach()"); |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 526 | Vector<audio_session_t> releasedSessions; |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 527 | |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 528 | { |
| 529 | AutoMutex lock(mLock); |
| 530 | ssize_t index = -1; |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 531 | |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 532 | for (size_t i = 0; i < mModuleClients.size(); i++) { |
| 533 | if (mModuleClients[i] == moduleClient) { |
| 534 | index = i; |
| 535 | break; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 536 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 537 | } |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 538 | if (index == -1) { |
| 539 | return; |
| 540 | } |
| 541 | |
| 542 | ALOGV("remove client %p", moduleClient.get()); |
| 543 | mModuleClients.removeAt(index); |
| 544 | |
| 545 | // Iterate in reverse order as models are removed from list inside the loop. |
| 546 | for (size_t i = mModels.size(); i > 0; i--) { |
| 547 | sp<Model> model = mModels.valueAt(i - 1); |
| 548 | if (moduleClient == model->mModuleClient) { |
| 549 | mModels.removeItemsAt(i - 1); |
| 550 | ALOGV("detach() unloading model %d", model->mHandle); |
| 551 | if (mHalInterface != 0) { |
| 552 | if (model->mState == Model::STATE_ACTIVE) { |
| 553 | mHalInterface->stopRecognition(model->mHandle); |
| 554 | } |
| 555 | mHalInterface->unloadSoundModel(model->mHandle); |
| 556 | } |
| 557 | releasedSessions.add(model->mCaptureSession); |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | for (size_t i = 0; i < releasedSessions.size(); i++) { |
| 563 | // do not call AudioSystem methods with mLock held |
| 564 | AudioSystem::releaseSoundTriggerSession(releasedSessions[i]); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 565 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelMemory, |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 569 | sp<ModuleClient> moduleClient, |
| 570 | sound_model_handle_t *handle) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 571 | { |
| 572 | ALOGV("loadSoundModel() handle"); |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 573 | if (mHalInterface == 0) { |
| 574 | return NO_INIT; |
| 575 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 576 | if (modelMemory == 0 || modelMemory->pointer() == NULL) { |
| 577 | ALOGE("loadSoundModel() modelMemory is 0 or has NULL pointer()"); |
| 578 | return BAD_VALUE; |
| 579 | } |
| 580 | struct sound_trigger_sound_model *sound_model = |
| 581 | (struct sound_trigger_sound_model *)modelMemory->pointer(); |
| 582 | |
Eric Laurent | bb00d8f | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 583 | size_t structSize; |
| 584 | if (sound_model->type == SOUND_MODEL_TYPE_KEYPHRASE) { |
| 585 | structSize = sizeof(struct sound_trigger_phrase_sound_model); |
| 586 | } else { |
| 587 | structSize = sizeof(struct sound_trigger_sound_model); |
| 588 | } |
| 589 | |
| 590 | if (sound_model->data_offset < structSize || |
| 591 | sound_model->data_size > (UINT_MAX - sound_model->data_offset) || |
| 592 | modelMemory->size() < sound_model->data_offset || |
| 593 | sound_model->data_size > (modelMemory->size() - sound_model->data_offset)) { |
| 594 | android_errorWriteLog(0x534e4554, "30148546"); |
| 595 | ALOGE("loadSoundModel() data_size is too big"); |
| 596 | return BAD_VALUE; |
| 597 | } |
| 598 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 599 | audio_session_t session; |
| 600 | audio_io_handle_t ioHandle; |
| 601 | audio_devices_t device; |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 602 | // do not call AudioSystem methods with mLock held |
| 603 | status_t status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 604 | if (status != NO_ERROR) { |
| 605 | return status; |
| 606 | } |
| 607 | |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 608 | { |
| 609 | AutoMutex lock(mLock); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 610 | |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 611 | if (mModels.size() >= mDescriptor.properties.max_sound_models) { |
| 612 | ALOGW("loadSoundModel(): Not loading, max number of models (%d) would be exceeded", |
| 613 | mDescriptor.properties.max_sound_models); |
| 614 | status = INVALID_OPERATION; |
| 615 | goto exit; |
| 616 | } |
| 617 | |
| 618 | status = mHalInterface->loadSoundModel(sound_model, |
| 619 | SoundTriggerHwService::soundModelCallback, |
| 620 | this, handle); |
| 621 | if (status != NO_ERROR) { |
| 622 | goto exit; |
| 623 | } |
| 624 | |
| 625 | sp<Model> model = new Model(*handle, session, ioHandle, device, sound_model->type, |
| 626 | moduleClient); |
| 627 | mModels.replaceValueFor(*handle, model); |
| 628 | } |
| 629 | exit: |
| 630 | if (status != NO_ERROR) { |
| 631 | // do not call AudioSystem methods with mLock held |
| 632 | AudioSystem::releaseSoundTriggerSession(session); |
| 633 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 634 | return status; |
| 635 | } |
| 636 | |
| 637 | status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t handle) |
| 638 | { |
| 639 | ALOGV("unloadSoundModel() model handle %d", handle); |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 640 | status_t status; |
| 641 | audio_session_t session; |
Eric Laurent | 02eb47c | 2014-11-20 10:10:20 -0800 | [diff] [blame] | 642 | |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 643 | { |
| 644 | AutoMutex lock(mLock); |
| 645 | if (mHalInterface == 0) { |
| 646 | return NO_INIT; |
| 647 | } |
| 648 | ssize_t index = mModels.indexOfKey(handle); |
| 649 | if (index < 0) { |
| 650 | return BAD_VALUE; |
| 651 | } |
| 652 | sp<Model> model = mModels.valueAt(index); |
| 653 | mModels.removeItem(handle); |
| 654 | if (model->mState == Model::STATE_ACTIVE) { |
| 655 | mHalInterface->stopRecognition(model->mHandle); |
| 656 | model->mState = Model::STATE_IDLE; |
| 657 | } |
| 658 | status = mHalInterface->unloadSoundModel(handle); |
| 659 | session = model->mCaptureSession; |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 660 | } |
Eric Laurent | 338e8ba | 2017-10-05 10:58:38 -0700 | [diff] [blame] | 661 | // do not call AudioSystem methods with mLock held |
| 662 | AudioSystem::releaseSoundTriggerSession(session); |
| 663 | return status; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | status_t SoundTriggerHwService::Module::startRecognition(sound_model_handle_t handle, |
Eric Laurent | 0832b2d | 2014-07-06 16:17:25 -0700 | [diff] [blame] | 667 | const sp<IMemory>& dataMemory) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 668 | { |
| 669 | ALOGV("startRecognition() model handle %d", handle); |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 670 | if (mHalInterface == 0) { |
| 671 | return NO_INIT; |
| 672 | } |
Eric Laurent | bb00d8f | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 673 | if (dataMemory == 0 || dataMemory->pointer() == NULL) { |
| 674 | ALOGE("startRecognition() dataMemory is 0 or has NULL pointer()"); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 675 | return BAD_VALUE; |
| 676 | |
| 677 | } |
Eric Laurent | bb00d8f | 2016-08-17 06:19:32 -0700 | [diff] [blame] | 678 | |
| 679 | struct sound_trigger_recognition_config *config = |
| 680 | (struct sound_trigger_recognition_config *)dataMemory->pointer(); |
| 681 | |
| 682 | if (config->data_offset < sizeof(struct sound_trigger_recognition_config) || |
| 683 | config->data_size > (UINT_MAX - config->data_offset) || |
| 684 | dataMemory->size() < config->data_offset || |
| 685 | config->data_size > (dataMemory->size() - config->data_offset)) { |
| 686 | ALOGE("startRecognition() data_size is too big"); |
| 687 | return BAD_VALUE; |
| 688 | } |
| 689 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 690 | AutoMutex lock(mLock); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 691 | if (mServiceState == SOUND_TRIGGER_STATE_DISABLED) { |
| 692 | return INVALID_OPERATION; |
| 693 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 694 | sp<Model> model = getModel(handle); |
| 695 | if (model == 0) { |
| 696 | return BAD_VALUE; |
| 697 | } |
| 698 | |
| 699 | if (model->mState == Model::STATE_ACTIVE) { |
| 700 | return INVALID_OPERATION; |
| 701 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 702 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 703 | |
| 704 | //TODO: get capture handle and device from audio policy service |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 705 | config->capture_handle = model->mCaptureIOHandle; |
| 706 | config->capture_device = model->mCaptureDevice; |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 707 | status_t status = mHalInterface->startRecognition(handle, config, |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 708 | SoundTriggerHwService::recognitionCallback, |
Eric Laurent | 0832b2d | 2014-07-06 16:17:25 -0700 | [diff] [blame] | 709 | this); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 710 | |
| 711 | if (status == NO_ERROR) { |
| 712 | model->mState = Model::STATE_ACTIVE; |
| 713 | model->mConfig = *config; |
| 714 | } |
| 715 | |
| 716 | return status; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | status_t SoundTriggerHwService::Module::stopRecognition(sound_model_handle_t handle) |
| 720 | { |
| 721 | ALOGV("stopRecognition() model handle %d", handle); |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 722 | if (mHalInterface == 0) { |
| 723 | return NO_INIT; |
| 724 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 725 | AutoMutex lock(mLock); |
| 726 | sp<Model> model = getModel(handle); |
| 727 | if (model == 0) { |
| 728 | return BAD_VALUE; |
| 729 | } |
| 730 | |
| 731 | if (model->mState != Model::STATE_ACTIVE) { |
| 732 | return INVALID_OPERATION; |
| 733 | } |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 734 | mHalInterface->stopRecognition(handle); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 735 | model->mState = Model::STATE_IDLE; |
| 736 | return NO_ERROR; |
| 737 | } |
| 738 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 739 | void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& event) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 740 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 741 | ALOGV("onCallbackEvent type %d", event->mType); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 742 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 743 | sp<IMemory> eventMemory = event->mMemory; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 744 | |
| 745 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 746 | return; |
| 747 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 748 | if (mModuleClients.isEmpty()) { |
| 749 | ALOGI("%s no clients", __func__); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 750 | return; |
| 751 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 752 | |
| 753 | switch (event->mType) { |
| 754 | case CallbackEvent::TYPE_RECOGNITION: { |
| 755 | struct sound_trigger_recognition_event *recognitionEvent = |
| 756 | (struct sound_trigger_recognition_event *)eventMemory->pointer(); |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 757 | sp<ISoundTriggerClient> client; |
| 758 | { |
| 759 | AutoMutex lock(mLock); |
| 760 | sp<Model> model = getModel(recognitionEvent->model); |
| 761 | if (model == 0) { |
| 762 | ALOGW("%s model == 0", __func__); |
| 763 | return; |
| 764 | } |
| 765 | if (model->mState != Model::STATE_ACTIVE) { |
| 766 | ALOGV("onCallbackEvent model->mState %d != Model::STATE_ACTIVE", model->mState); |
| 767 | return; |
| 768 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 769 | |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 770 | recognitionEvent->capture_session = model->mCaptureSession; |
| 771 | model->mState = Model::STATE_IDLE; |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 772 | client = model->mModuleClient->client(); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 773 | } |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 774 | if (client != 0) { |
| 775 | client->onRecognitionEvent(eventMemory); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 776 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 777 | } break; |
| 778 | case CallbackEvent::TYPE_SOUNDMODEL: { |
| 779 | struct sound_trigger_model_event *soundmodelEvent = |
| 780 | (struct sound_trigger_model_event *)eventMemory->pointer(); |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 781 | sp<ISoundTriggerClient> client; |
| 782 | { |
| 783 | AutoMutex lock(mLock); |
| 784 | sp<Model> model = getModel(soundmodelEvent->model); |
| 785 | if (model == 0) { |
| 786 | ALOGW("%s model == 0", __func__); |
| 787 | return; |
| 788 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 789 | client = model->mModuleClient->client(); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 790 | } |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 791 | if (client != 0) { |
| 792 | client->onSoundModelEvent(eventMemory); |
| 793 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 794 | } break; |
| 795 | case CallbackEvent::TYPE_SERVICE_STATE: { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 796 | Vector< sp<ISoundTriggerClient> > clients; |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 797 | { |
| 798 | AutoMutex lock(mLock); |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 799 | for (size_t i = 0; i < mModuleClients.size(); i++) { |
| 800 | if (mModuleClients[i] != 0) { |
| 801 | clients.add(mModuleClients[i]->client()); |
| 802 | } |
| 803 | } |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 804 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 805 | for (size_t i = 0; i < clients.size(); i++) { |
| 806 | clients[i]->onServiceStateChange(eventMemory); |
Eric Laurent | 886561f | 2014-08-28 19:45:37 -0700 | [diff] [blame] | 807 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 808 | } break; |
| 809 | default: |
| 810 | LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType); |
| 811 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | sp<SoundTriggerHwService::Model> SoundTriggerHwService::Module::getModel( |
| 815 | sound_model_handle_t handle) |
| 816 | { |
| 817 | sp<Model> model; |
| 818 | ssize_t index = mModels.indexOfKey(handle); |
| 819 | if (index >= 0) { |
| 820 | model = mModels.valueAt(index); |
| 821 | } |
| 822 | return model; |
| 823 | } |
| 824 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 825 | // Called with mServiceLock held |
| 826 | void SoundTriggerHwService::Module::setCaptureState_l(bool active) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 827 | { |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 828 | ALOGV("Module::setCaptureState_l %d", active); |
| 829 | sp<SoundTriggerHwService> service; |
| 830 | sound_trigger_service_state_t state; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 831 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 832 | Vector< sp<IMemory> > events; |
| 833 | { |
| 834 | AutoMutex lock(mLock); |
| 835 | state = (active && !mDescriptor.properties.concurrent_capture) ? |
| 836 | SOUND_TRIGGER_STATE_DISABLED : SOUND_TRIGGER_STATE_ENABLED; |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 837 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 838 | if (state == mServiceState) { |
| 839 | return; |
| 840 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 841 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 842 | mServiceState = state; |
| 843 | |
| 844 | service = mService.promote(); |
| 845 | if (service == 0) { |
| 846 | return; |
| 847 | } |
| 848 | |
| 849 | if (state == SOUND_TRIGGER_STATE_ENABLED) { |
| 850 | goto exit; |
| 851 | } |
| 852 | |
Chris Thornton | efcf16c | 2016-03-27 17:13:28 -0700 | [diff] [blame] | 853 | const bool supports_stop_all = |
Chris Thornton | de22f8a | 2017-08-29 16:46:37 -0700 | [diff] [blame] | 854 | (mHalInterface != 0) && (mHalInterface->stopAllRecognitions() != -ENOSYS); |
Chris Thornton | efcf16c | 2016-03-27 17:13:28 -0700 | [diff] [blame] | 855 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 856 | for (size_t i = 0; i < mModels.size(); i++) { |
| 857 | sp<Model> model = mModels.valueAt(i); |
| 858 | if (model->mState == Model::STATE_ACTIVE) { |
Eric Laurent | 7a544b4 | 2016-08-05 19:01:13 -0700 | [diff] [blame] | 859 | if (mHalInterface != 0 && !supports_stop_all) { |
| 860 | mHalInterface->stopRecognition(model->mHandle); |
Chris Thornton | efcf16c | 2016-03-27 17:13:28 -0700 | [diff] [blame] | 861 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 862 | // keep model in ACTIVE state so that event is processed by onCallbackEvent() |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 863 | if (model->mType == SOUND_MODEL_TYPE_KEYPHRASE) { |
| 864 | struct sound_trigger_phrase_recognition_event event; |
| 865 | memset(&event, 0, sizeof(struct sound_trigger_phrase_recognition_event)); |
| 866 | event.num_phrases = model->mConfig.num_phrases; |
| 867 | for (size_t i = 0; i < event.num_phrases; i++) { |
| 868 | event.phrase_extras[i] = model->mConfig.phrases[i]; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 869 | } |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 870 | event.common.status = RECOGNITION_STATUS_ABORT; |
| 871 | event.common.type = model->mType; |
| 872 | event.common.model = model->mHandle; |
| 873 | event.common.data_size = 0; |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 874 | sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common); |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 875 | if (eventMemory != 0) { |
| 876 | events.add(eventMemory); |
| 877 | } |
| 878 | } else if (model->mType == SOUND_MODEL_TYPE_GENERIC) { |
| 879 | struct sound_trigger_generic_recognition_event event; |
| 880 | memset(&event, 0, sizeof(struct sound_trigger_generic_recognition_event)); |
| 881 | event.common.status = RECOGNITION_STATUS_ABORT; |
| 882 | event.common.type = model->mType; |
| 883 | event.common.model = model->mHandle; |
| 884 | event.common.data_size = 0; |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 885 | sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common); |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 886 | if (eventMemory != 0) { |
| 887 | events.add(eventMemory); |
| 888 | } |
Ryan Bavetta | 9609a91 | 2016-01-28 19:22:29 -0800 | [diff] [blame] | 889 | } else if (model->mType == SOUND_MODEL_TYPE_UNKNOWN) { |
| 890 | struct sound_trigger_phrase_recognition_event event; |
| 891 | memset(&event, 0, sizeof(struct sound_trigger_phrase_recognition_event)); |
| 892 | event.common.status = RECOGNITION_STATUS_ABORT; |
| 893 | event.common.type = model->mType; |
| 894 | event.common.model = model->mHandle; |
| 895 | event.common.data_size = 0; |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 896 | sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common); |
Ryan Bavetta | 9609a91 | 2016-01-28 19:22:29 -0800 | [diff] [blame] | 897 | if (eventMemory != 0) { |
| 898 | events.add(eventMemory); |
| 899 | } |
Ryan Bavetta | 00a727c | 2016-01-26 21:56:19 -0800 | [diff] [blame] | 900 | } else { |
| 901 | goto exit; |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 902 | } |
| 903 | } |
| 904 | } |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 905 | } |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 906 | |
| 907 | for (size_t i = 0; i < events.size(); i++) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 908 | sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_RECOGNITION, |
| 909 | events[i]); |
| 910 | callbackEvent->setModule(this); |
Chris Thornton | 79c5661 | 2017-10-25 14:47:44 -0700 | [diff] [blame] | 911 | service->sendCallbackEvent(callbackEvent); |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | exit: |
| 915 | service->sendServiceStateEvent_l(state, this); |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 916 | } |
| 917 | |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 918 | |
| 919 | SoundTriggerHwService::Model::Model(sound_model_handle_t handle, audio_session_t session, |
| 920 | audio_io_handle_t ioHandle, audio_devices_t device, |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 921 | sound_trigger_sound_model_type_t type, |
| 922 | sp<ModuleClient>& moduleClient) : |
Eric Laurent | df3dc7e | 2014-07-27 18:39:40 -0700 | [diff] [blame] | 923 | mHandle(handle), mState(STATE_IDLE), mCaptureSession(session), |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 924 | mCaptureIOHandle(ioHandle), mCaptureDevice(device), mType(type), |
| 925 | mModuleClient(moduleClient) |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 926 | { |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 929 | #undef LOG_TAG |
| 930 | #define LOG_TAG "SoundTriggerHwService::ModuleClient" |
| 931 | |
| 932 | SoundTriggerHwService::ModuleClient::ModuleClient(const sp<Module>& module, |
| 933 | const sp<ISoundTriggerClient>& client) |
| 934 | : mModule(module), mClient(client) |
| 935 | { |
| 936 | } |
| 937 | |
| 938 | void SoundTriggerHwService::ModuleClient::onFirstRef() |
| 939 | { |
Chris Thornton | c8a9f4a | 2017-02-06 18:31:42 -0800 | [diff] [blame] | 940 | sp<IBinder> binder = IInterface::asBinder(mClient); |
| 941 | if (binder != 0) { |
| 942 | binder->linkToDeath(this); |
| 943 | } |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | SoundTriggerHwService::ModuleClient::~ModuleClient() |
| 947 | { |
| 948 | } |
| 949 | |
| 950 | status_t SoundTriggerHwService::ModuleClient::dump(int fd __unused, |
| 951 | const Vector<String16>& args __unused) { |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 952 | String8 result; |
| 953 | return NO_ERROR; |
| 954 | } |
| 955 | |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 956 | void SoundTriggerHwService::ModuleClient::detach() { |
| 957 | ALOGV("detach()"); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 958 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 959 | IPCThreadState::self()->getCallingUid())) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 960 | return; |
| 961 | } |
| 962 | |
| 963 | { |
| 964 | AutoMutex lock(mLock); |
| 965 | if (mClient != 0) { |
| 966 | IInterface::asBinder(mClient)->unlinkToDeath(this); |
| 967 | mClient.clear(); |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | sp<Module> module = mModule.promote(); |
| 972 | if (module == 0) { |
| 973 | return; |
| 974 | } |
| 975 | module->detach(this); |
| 976 | } |
| 977 | |
| 978 | status_t SoundTriggerHwService::ModuleClient::loadSoundModel(const sp<IMemory>& modelMemory, |
| 979 | sound_model_handle_t *handle) |
| 980 | { |
| 981 | ALOGV("loadSoundModel() handle"); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 982 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 983 | IPCThreadState::self()->getCallingUid())) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 984 | return PERMISSION_DENIED; |
| 985 | } |
| 986 | |
| 987 | sp<Module> module = mModule.promote(); |
| 988 | if (module == 0) { |
| 989 | return NO_INIT; |
| 990 | } |
| 991 | return module->loadSoundModel(modelMemory, this, handle); |
| 992 | } |
| 993 | |
| 994 | status_t SoundTriggerHwService::ModuleClient::unloadSoundModel(sound_model_handle_t handle) |
| 995 | { |
| 996 | ALOGV("unloadSoundModel() model handle %d", handle); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 997 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 998 | IPCThreadState::self()->getCallingUid())) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 999 | return PERMISSION_DENIED; |
| 1000 | } |
| 1001 | |
| 1002 | sp<Module> module = mModule.promote(); |
| 1003 | if (module == 0) { |
| 1004 | return NO_INIT; |
| 1005 | } |
| 1006 | return module->unloadSoundModel(handle); |
| 1007 | } |
| 1008 | |
| 1009 | status_t SoundTriggerHwService::ModuleClient::startRecognition(sound_model_handle_t handle, |
| 1010 | const sp<IMemory>& dataMemory) |
| 1011 | { |
| 1012 | ALOGV("startRecognition() model handle %d", handle); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 1013 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 1014 | IPCThreadState::self()->getCallingUid())) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 1015 | return PERMISSION_DENIED; |
| 1016 | } |
| 1017 | |
| 1018 | sp<Module> module = mModule.promote(); |
| 1019 | if (module == 0) { |
| 1020 | return NO_INIT; |
| 1021 | } |
| 1022 | return module->startRecognition(handle, dataMemory); |
| 1023 | } |
| 1024 | |
| 1025 | status_t SoundTriggerHwService::ModuleClient::stopRecognition(sound_model_handle_t handle) |
| 1026 | { |
| 1027 | ALOGV("stopRecognition() model handle %d", handle); |
Eric Laurent | 7504b9e | 2017-08-15 18:17:26 -0700 | [diff] [blame] | 1028 | if (!captureHotwordAllowed(IPCThreadState::self()->getCallingPid(), |
| 1029 | IPCThreadState::self()->getCallingUid())) { |
Haynes Mathew George | e52c500 | 2016-10-12 17:27:18 -0700 | [diff] [blame] | 1030 | return PERMISSION_DENIED; |
| 1031 | } |
| 1032 | |
| 1033 | sp<Module> module = mModule.promote(); |
| 1034 | if (module == 0) { |
| 1035 | return NO_INIT; |
| 1036 | } |
| 1037 | return module->stopRecognition(handle); |
| 1038 | } |
| 1039 | |
| 1040 | void SoundTriggerHwService::ModuleClient::setCaptureState_l(bool active) |
| 1041 | { |
| 1042 | ALOGV("ModuleClient::setCaptureState_l %d", active); |
| 1043 | sp<SoundTriggerHwService> service; |
| 1044 | sound_trigger_service_state_t state; |
| 1045 | |
| 1046 | sp<Module> module = mModule.promote(); |
| 1047 | if (module == 0) { |
| 1048 | return; |
| 1049 | } |
| 1050 | { |
| 1051 | AutoMutex lock(mLock); |
| 1052 | state = (active && !module->isConcurrentCaptureAllowed()) ? |
| 1053 | SOUND_TRIGGER_STATE_DISABLED : SOUND_TRIGGER_STATE_ENABLED; |
| 1054 | |
| 1055 | service = module->service().promote(); |
| 1056 | if (service == 0) { |
| 1057 | return; |
| 1058 | } |
| 1059 | } |
| 1060 | service->sendServiceStateEvent_l(state, this); |
| 1061 | } |
| 1062 | |
| 1063 | void SoundTriggerHwService::ModuleClient::onCallbackEvent(const sp<CallbackEvent>& event) |
| 1064 | { |
| 1065 | ALOGV("ModuleClient onCallbackEvent type %d", event->mType); |
| 1066 | |
| 1067 | sp<IMemory> eventMemory = event->mMemory; |
| 1068 | |
| 1069 | if (eventMemory == 0 || eventMemory->pointer() == NULL) { |
| 1070 | return; |
| 1071 | } |
| 1072 | |
| 1073 | switch (event->mType) { |
| 1074 | case CallbackEvent::TYPE_SERVICE_STATE: { |
| 1075 | sp<ISoundTriggerClient> client; |
| 1076 | { |
| 1077 | AutoMutex lock(mLock); |
| 1078 | client = mClient; |
| 1079 | } |
| 1080 | if (client !=0 ) { |
| 1081 | client->onServiceStateChange(eventMemory); |
| 1082 | } |
| 1083 | } break; |
| 1084 | default: |
| 1085 | LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType); |
| 1086 | } |
| 1087 | } |
| 1088 | |
| 1089 | void SoundTriggerHwService::ModuleClient::binderDied( |
| 1090 | const wp<IBinder> &who __unused) { |
| 1091 | ALOGW("client binder died for client %p", this); |
| 1092 | detach(); |
| 1093 | } |
| 1094 | |
Eric Laurent | b7a11d8 | 2014-04-18 17:40:41 -0700 | [diff] [blame] | 1095 | }; // namespace android |