1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
18 
19 namespace android {
20 namespace hardware {
21 namespace soundtrigger {
22 namespace V2_2 {
23 namespace implementation {
24 
25 using ::android::hardware::soundtrigger::V2_0::SoundModelHandle;
26 using ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback;
27 using ::android::hardware::soundtrigger::V2_0::RecognitionMode;
28 using ::android::hardware::audio::common::V2_0::Uuid;
29 
30 struct SoundTriggerHw : public ISoundTriggerHw {
31     // Methods from V2_0::ISoundTriggerHw follow.
getPropertiesandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw32     Return<void> getProperties(getProperties_cb _hidl_cb) override {
33         V2_0::ISoundTriggerHw::Properties props;
34 
35         props.implementor = "The Android Open Source Project";
36         props.description = "The Andtoid Studio Emulator Soundtrigger no-op implementation";
37         props.version = 0;
38         props.uuid = (Uuid){
39             .timeLow = 0x04030201,
40             .timeMid = 0x0605,
41             .versionAndTimeHigh = 0x0807,
42             .variantAndClockSeqHigh = 0x0A09,
43             .node = hidl_array<uint8_t, 6>({ 'r', 'a', 'n', 'c', 'h', 'u' }),
44         };
45         props.maxSoundModels = 42;
46         props.maxKeyPhrases = 4242;
47         props.maxUsers = 7;
48         props.recognitionModes = RecognitionMode::VOICE_TRIGGER
49                                  | RecognitionMode::GENERIC_TRIGGER;
50         props.captureTransition = false;
51         props.maxBufferMs = 0;
52         props.concurrentCapture = false;
53         props.triggerInEvent = true;
54         props.powerConsumptionMw = 42;
55 
56         _hidl_cb(0, props);
57         return Void();
58     }
59 
loadSoundModelandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw60     Return<void> loadSoundModel(const V2_0::ISoundTriggerHw::SoundModel& soundModel,
61                                 const sp<V2_0::ISoundTriggerHwCallback>& callback,
62                                 int32_t cookie,
63                                 loadSoundModel_cb _hidl_cb) override {
64         (void)soundModel;
65         (void)callback;
66         (void)cookie;
67         _hidl_cb(0, genHandle());
68         return Void();
69     }
70 
loadPhraseSoundModelandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw71     Return<void> loadPhraseSoundModel(const V2_0::ISoundTriggerHw::PhraseSoundModel& soundModel,
72                                       const sp<V2_0::ISoundTriggerHwCallback>& callback,
73                                       int32_t cookie,
74                                       loadPhraseSoundModel_cb _hidl_cb) override {
75         (void)soundModel;
76         (void)callback;
77         (void)cookie;
78         _hidl_cb(0, genHandle());
79         return Void();
80     }
81 
unloadSoundModelandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw82     Return<int32_t> unloadSoundModel(int32_t modelHandle) override {
83         (void)modelHandle;
84         return 0;
85     }
86 
startRecognitionandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw87     Return<int32_t> startRecognition(int32_t modelHandle,
88                                      const V2_0::ISoundTriggerHw::RecognitionConfig& config,
89                                      const sp<V2_0::ISoundTriggerHwCallback>& callback,
90                                      int32_t cookie) override {
91         (void)modelHandle;
92         (void)config;
93         (void)callback;
94         (void)cookie;
95         return 0;
96     }
97 
stopRecognitionandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw98     Return<int32_t> stopRecognition(int32_t modelHandle) override {
99         (void)modelHandle;
100         return 0;
101     }
102 
stopAllRecognitionsandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw103     Return<int32_t> stopAllRecognitions() override {
104         return 0;
105     }
106 
107     // Methods from V2_1::ISoundTriggerHw follow.
loadSoundModel_2_1android::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw108     Return<void> loadSoundModel_2_1(const V2_1::ISoundTriggerHw::SoundModel& soundModel,
109                                     const sp<V2_1::ISoundTriggerHwCallback>& callback,
110                                     int32_t cookie,
111                                     loadSoundModel_2_1_cb _hidl_cb) override {
112         (void)soundModel;
113         (void)callback;
114         (void)cookie;
115         _hidl_cb(0, genHandle());
116         return Void();
117     }
118 
loadPhraseSoundModel_2_1android::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw119     Return<void> loadPhraseSoundModel_2_1(const V2_1::ISoundTriggerHw::PhraseSoundModel& soundModel,
120                                           const sp<V2_1::ISoundTriggerHwCallback>& callback,
121                                           int32_t cookie,
122                                           loadPhraseSoundModel_2_1_cb _hidl_cb) override {
123         (void)soundModel;
124         (void)callback;
125         (void)cookie;
126         _hidl_cb(0, genHandle());
127         return Void();
128     }
129 
startRecognition_2_1android::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw130     Return<int32_t> startRecognition_2_1(int32_t modelHandle,
131                                          const V2_1::ISoundTriggerHw::RecognitionConfig& config,
132                                          const sp<V2_1::ISoundTriggerHwCallback>& callback,
133                                          int32_t cookie) override {
134         (void)modelHandle;
135         (void)config;
136         (void)callback;
137         (void)cookie;
138         return 0;
139     }
140 
141     // Methods from V2_2::ISoundTriggerHw follow.
getModelStateandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw142     Return<int32_t> getModelState(int32_t modelHandle) override {
143         (void)modelHandle;
144         return 0;
145     }
146 
genHandleandroid::hardware::soundtrigger::V2_2::implementation::SoundTriggerHw147     SoundModelHandle genHandle() {
148         mHandle = std::max(0, mHandle + 1);
149         return mHandle;
150     }
151 
152     SoundModelHandle mHandle = 0;
153 };
154 
HIDL_FETCH_ISoundTriggerHw(const char *)155 extern "C" ISoundTriggerHw* HIDL_FETCH_ISoundTriggerHw(const char* /* name */) {
156     return new SoundTriggerHw();
157 }
158 
159 }  // namespace implementation
160 }  // namespace V2_2
161 }  // namespace soundtrigger
162 }  // namespace hardware
163 }  // namespace android
164