3 ** Copyright 2014, The Android Open Source Project
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
9 ** http://www.apache.org/licenses/LICENSE-2.0
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
18 #define LOG_TAG "ISoundTrigger"
19 #include <utils/Log.h>
20 #include <utils/Errors.h>
21 #include <binder/IMemory.h>
22 #include <soundtrigger/ISoundTrigger.h>
23 #include <soundtrigger/ISoundTriggerHwService.h>
24 #include <soundtrigger/ISoundTriggerClient.h>
25 #include <system/sound_trigger.h>
30 DETACH = IBinder::FIRST_CALL_TRANSACTION,
37 class BpSoundTrigger: public BpInterface<ISoundTrigger>
40 BpSoundTrigger(const sp<IBinder>& impl)
41 : BpInterface<ISoundTrigger>(impl)
49 data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
50 remote()->transact(DETACH, data, &reply);
53 status_t loadSoundModel(const sp<IMemory>& modelMemory,
54 sound_model_handle_t *handle)
56 if (modelMemory == 0 || handle == NULL) {
60 data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
61 data.writeStrongBinder(modelMemory->asBinder());
62 status_t status = remote()->transact(LOAD_SOUND_MODEL, data, &reply);
63 if (status != NO_ERROR ||
64 (status = (status_t)reply.readInt32()) != NO_ERROR) {
67 reply.read(handle, sizeof(sound_model_handle_t));
71 virtual status_t unloadSoundModel(sound_model_handle_t handle)
74 data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
75 data.write(&handle, sizeof(sound_model_handle_t));
76 status_t status = remote()->transact(UNLOAD_SOUND_MODEL, data, &reply);
77 if (status != NO_ERROR) {
78 status = (status_t)reply.readInt32();
83 virtual status_t startRecognition(sound_model_handle_t handle,
84 const sp<IMemory>& dataMemory)
87 data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
88 data.write(&handle, sizeof(sound_model_handle_t));
89 if (dataMemory == 0) {
92 data.writeInt32(dataMemory->size());
94 data.writeStrongBinder(dataMemory->asBinder());
95 status_t status = remote()->transact(START_RECOGNITION, data, &reply);
96 if (status != NO_ERROR) {
97 status = (status_t)reply.readInt32();
102 virtual status_t stopRecognition(sound_model_handle_t handle)
105 data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
106 data.write(&handle, sizeof(sound_model_handle_t));
107 status_t status = remote()->transact(STOP_RECOGNITION, data, &reply);
108 if (status != NO_ERROR) {
109 status = (status_t)reply.readInt32();
116 IMPLEMENT_META_INTERFACE(SoundTrigger, "android.hardware.ISoundTrigger");
118 // ----------------------------------------------------------------------
120 status_t BnSoundTrigger::onTransact(
121 uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
126 CHECK_INTERFACE(ISoundTrigger, data, reply);
130 case LOAD_SOUND_MODEL: {
131 CHECK_INTERFACE(ISoundTrigger, data, reply);
132 sp<IMemory> modelMemory = interface_cast<IMemory>(
133 data.readStrongBinder());
134 sound_model_handle_t handle;
135 status_t status = loadSoundModel(modelMemory, &handle);
136 reply->writeInt32(status);
137 if (status == NO_ERROR) {
138 reply->write(&handle, sizeof(sound_model_handle_t));
142 case UNLOAD_SOUND_MODEL: {
143 CHECK_INTERFACE(ISoundTrigger, data, reply);
144 sound_model_handle_t handle;
145 data.read(&handle, sizeof(sound_model_handle_t));
146 status_t status = unloadSoundModel(handle);
147 reply->writeInt32(status);
150 case START_RECOGNITION: {
151 CHECK_INTERFACE(ISoundTrigger, data, reply);
152 sound_model_handle_t handle;
153 data.read(&handle, sizeof(sound_model_handle_t));
154 sp<IMemory> dataMemory;
155 if (data.readInt32() != 0) {
156 dataMemory = interface_cast<IMemory>(data.readStrongBinder());
158 status_t status = startRecognition(handle, dataMemory);
159 reply->writeInt32(status);
162 case STOP_RECOGNITION: {
163 CHECK_INTERFACE(ISoundTrigger, data, reply);
164 sound_model_handle_t handle;
165 data.read(&handle, sizeof(sound_model_handle_t));
166 status_t status = stopRecognition(handle);
167 reply->writeInt32(status);
171 return BBinder::onTransact(code, data, reply, flags);
175 // ----------------------------------------------------------------------------
177 }; // namespace android