1 /*
2  * Copyright (C) 2022 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 package com.android.server.soundtrigger_middleware;
18 
19 import android.media.soundtrigger.PhraseRecognitionEvent;
20 import android.media.soundtrigger.PhraseRecognitionExtra;
21 import android.media.soundtrigger.RecognitionEvent;
22 import android.media.soundtrigger.RecognitionStatus;
23 import android.media.soundtrigger.SoundModelType;
24 import android.media.soundtrigger_middleware.PhraseRecognitionEventSys;
25 import android.media.soundtrigger_middleware.RecognitionEventSys;
26 
27 /**
28  * Utilities for working with sound trigger related AIDL generated types.
29  */
30 public class AidlUtil {
31     /**
32      * Initialize a new recognition event.
33      * @return The new event.
34      */
newEmptyRecognitionEvent()35     static RecognitionEvent newEmptyRecognitionEvent() {
36         RecognitionEvent result = new RecognitionEvent();
37         result.data = new byte[0];
38         return result;
39     }
40 
41     /**
42      * Initialize a new phrase recognition event.
43      * @return The new event.
44      */
newEmptyPhraseRecognitionEvent()45     static PhraseRecognitionEvent newEmptyPhraseRecognitionEvent() {
46         PhraseRecognitionEvent result = new PhraseRecognitionEvent();
47         result.common = newEmptyRecognitionEvent();
48         result.phraseExtras = new PhraseRecognitionExtra[0];
49         return result;
50     }
51 
52     /**
53      * Creates a new generic abort event.
54      *
55      * @return The new event.
56      */
newAbortEvent()57     static RecognitionEventSys newAbortEvent() {
58         RecognitionEvent recognitionEvent = newEmptyRecognitionEvent();
59         recognitionEvent.type = SoundModelType.GENERIC;
60         recognitionEvent.status = RecognitionStatus.ABORTED;
61         RecognitionEventSys recognitionEventSys = new RecognitionEventSys();
62         recognitionEventSys.recognitionEvent = recognitionEvent;
63         return recognitionEventSys;
64     }
65 
66     /**
67      * Creates a new generic phrase event.
68      *
69      * @return The new event.
70      */
newAbortPhraseEvent()71     static PhraseRecognitionEventSys newAbortPhraseEvent() {
72         PhraseRecognitionEvent recognitionEvent = newEmptyPhraseRecognitionEvent();
73         recognitionEvent.common.type = SoundModelType.KEYPHRASE;
74         recognitionEvent.common.status = RecognitionStatus.ABORTED;
75         PhraseRecognitionEventSys phraseRecognitionEventSys = new PhraseRecognitionEventSys();
76         phraseRecognitionEventSys.phraseRecognitionEvent = recognitionEvent;
77         return phraseRecognitionEventSys;
78     }
79 }
80