1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
|
/*
* Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.service.voice;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.res.Resources;
import android.media.AudioRecord;
import android.media.MediaSyncEvent;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.PersistableBundle;
import com.android.internal.R;
import com.android.internal.util.DataClass;
import com.android.internal.util.Preconditions;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
/**
* Represents a result supporting the hotword detection.
*
* @hide
*/
@DataClass(
genConstructor = false,
genBuilder = true,
genEqualsHashCode = true,
genHiddenConstDefs = true,
genParcelable = true,
genToString = true
)
@SystemApi
public final class HotwordDetectedResult implements Parcelable {
/** No confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_NONE = 0;
/** Low confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_LOW = 1;
/** Low-to-medium confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_LOW_MEDIUM = 2;
/** Medium confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_MEDIUM = 3;
/** Medium-to-high confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_MEDIUM_HIGH = 4;
/** High confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_HIGH = 5;
/** Very high confidence in hotword detector result. */
public static final int CONFIDENCE_LEVEL_VERY_HIGH = 6;
/** @hide */
@IntDef(prefix = {"CONFIDENCE_LEVEL_"}, value = {
CONFIDENCE_LEVEL_NONE,
CONFIDENCE_LEVEL_LOW,
CONFIDENCE_LEVEL_LOW_MEDIUM,
CONFIDENCE_LEVEL_MEDIUM,
CONFIDENCE_LEVEL_MEDIUM_HIGH,
CONFIDENCE_LEVEL_HIGH,
CONFIDENCE_LEVEL_VERY_HIGH
})
@interface HotwordConfidenceLevelValue {
}
/** Represents unset value for the hotword offset. */
public static final int HOTWORD_OFFSET_UNSET = -1;
/** Represents unset value for the triggered audio channel. */
public static final int AUDIO_CHANNEL_UNSET = -1;
/** Limits the max value for the hotword offset. */
private static final int LIMIT_HOTWORD_OFFSET_MAX_VALUE = 60 * 60 * 1000; // 1 hour
/** Limits the max value for the triggered audio channel. */
private static final int LIMIT_AUDIO_CHANNEL_MAX_VALUE = 63;
/**
* The bundle key for proximity
*
* TODO(b/238896013): Move the proximity logic out of bundle to proper API.
*/
private static final String EXTRA_PROXIMITY =
"android.service.voice.extra.PROXIMITY";
/**
* Users’ proximity is unknown (proximity sensing was inconclusive and is unsupported).
*
* @hide
*/
public static final int PROXIMITY_UNKNOWN = -1;
/**
* Proximity value that represents that the object is near.
*
* @hide
*/
public static final int PROXIMITY_NEAR = 1;
/**
* Proximity value that represents that the object is far.
*
* @hide
*/
public static final int PROXIMITY_FAR = 2;
/** @hide */
@IntDef(prefix = {"PROXIMITY"}, value = {
PROXIMITY_UNKNOWN,
PROXIMITY_NEAR,
PROXIMITY_FAR
})
@Retention(RetentionPolicy.SOURCE)
public @interface ProximityValue {}
/** Confidence level in the trigger outcome. */
@HotwordConfidenceLevelValue
private final int mConfidenceLevel;
private static int defaultConfidenceLevel() {
return CONFIDENCE_LEVEL_NONE;
}
/**
* A {@code MediaSyncEvent} that allows the {@link HotwordDetector} to recapture the audio
* that contains the hotword trigger. This must be obtained using
* {@link android.media.AudioRecord#shareAudioHistory(String, long)}.
*/
@Nullable
private MediaSyncEvent mMediaSyncEvent = null;
/**
* Offset in milliseconds the audio stream when the trigger event happened (end of hotword
* phrase).
*
* <p>Only value between 0 and 3600000 (inclusive) is accepted.
*/
private int mHotwordOffsetMillis = HOTWORD_OFFSET_UNSET;
/**
* Duration in milliseconds of the hotword trigger phrase.
*
* <p>Only values between 0 and {@link android.media.AudioRecord#getMaxSharedAudioHistoryMillis}
* (inclusive) are accepted.
*/
private int mHotwordDurationMillis = 0;
/**
* Audio channel containing the highest-confidence hotword signal.
*
* <p>Only value between 0 and 63 (inclusive) is accepted.
*/
private int mAudioChannel = AUDIO_CHANNEL_UNSET;
/**
* Returns whether the trigger has happened due to model having been personalized to fit user's
* voice.
*/
private boolean mHotwordDetectionPersonalized = false;
/**
* Score for the hotword trigger.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
private final int mScore;
private static int defaultScore() {
return 0;
}
/**
* Score for the hotword trigger for device user.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
private final int mPersonalizedScore;
private static int defaultPersonalizedScore() {
return 0;
}
/**
* Returns the maximum values of {@link #getScore} and {@link #getPersonalizedScore}.
* <p>
* The float value should be calculated as {@code getScore() / getMaxScore()}.
*/
public static int getMaxScore() {
return 255;
}
/**
* An ID representing the keyphrase that triggered the successful detection.
*
* <p>Only values between 0 and {@link #getMaxHotwordPhraseId()} (inclusive) are accepted.
*/
private final int mHotwordPhraseId;
private static int defaultHotwordPhraseId() {
return 0;
}
/**
* Returns the maximum value of {@link #getHotwordPhraseId()}.
*/
public static int getMaxHotwordPhraseId() {
return 63;
}
/**
* The list of the audio streams containing audio bytes that were used for hotword detection.
*
* @hide
*/
@NonNull
private final List<HotwordAudioStream> mAudioStreams;
private static List<HotwordAudioStream> defaultAudioStreams() {
return Collections.emptyList();
}
/**
* App-specific extras to support trigger.
*
* <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
* bundles will be rejected.
*
* <p>Only primitive types are supported in this bundle. Complex types will be removed from the
* bundle.
*
* <p>The use of this method is discouraged, and support for it will be removed in future
* versions of Android.
*
* <p>After the trigger happens, a special case of proximity-related extra, with the key of
* 'android.service.voice.extra.PROXIMITY_VALUE' and the value of proximity value (integer)
* will be stored to enable proximity logic. {@link HotwordDetectedResult#PROXIMITY_NEAR} will
* indicate 'NEAR' proximity and {@link HotwordDetectedResult#PROXIMITY_FAR} will indicate 'FAR'
* proximity. The proximity value is provided by the system, on devices that support detecting
* proximity of nearby users, to help disambiguate which nearby device should respond. When the
* proximity is unknown, the proximity value will not be stored. This mapping will be excluded
* from the max bundle size calculation because this mapping is included after the result is
* returned from the hotword detector service.
*
* <p>This is a PersistableBundle so it doesn't allow any remotable objects or other contents
* that can be used to communicate with other processes.
*/
@NonNull
private final PersistableBundle mExtras;
private static PersistableBundle defaultExtras() {
return new PersistableBundle();
}
private static int sMaxBundleSize = -1;
/**
* Returns the maximum byte size of the information contained in the bundle.
*
* <p>The total size will be calculated by how much bundle data should be written into the
* Parcel.
*/
public static int getMaxBundleSize() {
if (sMaxBundleSize < 0) {
sMaxBundleSize = Resources.getSystem().getInteger(
R.integer.config_hotwordDetectedResultMaxBundleSize);
}
return sMaxBundleSize;
}
/**
* A {@code MediaSyncEvent} that allows the {@link HotwordDetector} to recapture the audio
* that contains the hotword trigger. This must be obtained using
* {@link android.media.AudioRecord#shareAudioHistory(String, long)}.
* <p>
* This can be {@code null} if reprocessing the hotword trigger isn't required.
*/
// Suppress codegen to make javadoc consistent. Getter returns @Nullable, setter accepts
// @NonNull only, and by default codegen would use the same javadoc on both.
public @Nullable MediaSyncEvent getMediaSyncEvent() {
return mMediaSyncEvent;
}
/**
* Returns how many bytes should be written into the Parcel
*
* @hide
*/
public static int getParcelableSize(@NonNull Parcelable parcelable) {
final Parcel p = Parcel.obtain();
parcelable.writeToParcel(p, 0);
p.setDataPosition(0);
final int size = p.dataSize();
p.recycle();
return size;
}
/**
* Returns how many bits have been written into the HotwordDetectedResult.
*
* @hide
*/
public static int getUsageSize(@NonNull HotwordDetectedResult hotwordDetectedResult) {
int totalBits = 0;
if (hotwordDetectedResult.getConfidenceLevel() != defaultConfidenceLevel()) {
totalBits += bitCount(CONFIDENCE_LEVEL_VERY_HIGH);
}
if (hotwordDetectedResult.getHotwordOffsetMillis() != HOTWORD_OFFSET_UNSET) {
totalBits += bitCount(LIMIT_HOTWORD_OFFSET_MAX_VALUE);
}
if (hotwordDetectedResult.getHotwordDurationMillis() != 0) {
totalBits += bitCount(AudioRecord.getMaxSharedAudioHistoryMillis());
}
if (hotwordDetectedResult.getAudioChannel() != AUDIO_CHANNEL_UNSET) {
totalBits += bitCount(LIMIT_AUDIO_CHANNEL_MAX_VALUE);
}
// Add one bit for HotwordDetectionPersonalized
totalBits += 1;
if (hotwordDetectedResult.getScore() != defaultScore()) {
totalBits += bitCount(HotwordDetectedResult.getMaxScore());
}
if (hotwordDetectedResult.getPersonalizedScore() != defaultPersonalizedScore()) {
totalBits += bitCount(HotwordDetectedResult.getMaxScore());
}
if (hotwordDetectedResult.getHotwordPhraseId() != defaultHotwordPhraseId()) {
totalBits += bitCount(HotwordDetectedResult.getMaxHotwordPhraseId());
}
PersistableBundle persistableBundle = hotwordDetectedResult.getExtras();
if (!persistableBundle.isEmpty()) {
totalBits += getParcelableSize(persistableBundle) * Byte.SIZE;
}
return totalBits;
}
private static int bitCount(long value) {
int bits = 0;
while (value > 0) {
bits++;
value = value >> 1;
}
return bits;
}
private void onConstructed() {
Preconditions.checkArgumentInRange(mScore, 0, getMaxScore(), "score");
Preconditions.checkArgumentInRange(mPersonalizedScore, 0, getMaxScore(),
"personalizedScore");
Preconditions.checkArgumentInRange(mHotwordPhraseId, 0, getMaxHotwordPhraseId(),
"hotwordPhraseId");
Preconditions.checkArgumentInRange((long) mHotwordDurationMillis, 0,
AudioRecord.getMaxSharedAudioHistoryMillis(), "hotwordDurationMillis");
if (mHotwordOffsetMillis != HOTWORD_OFFSET_UNSET) {
Preconditions.checkArgumentInRange(mHotwordOffsetMillis, 0,
LIMIT_HOTWORD_OFFSET_MAX_VALUE, "hotwordOffsetMillis");
}
if (mAudioChannel != AUDIO_CHANNEL_UNSET) {
Preconditions.checkArgumentInRange(mAudioChannel, 0, LIMIT_AUDIO_CHANNEL_MAX_VALUE,
"audioChannel");
}
if (!mExtras.isEmpty()) {
// Remove the proximity key from the bundle before checking the bundle size. The
// proximity value is added after the privileged module and can avoid the
// maxBundleSize limitation.
if (mExtras.containsKey(EXTRA_PROXIMITY)) {
int proximityValue = mExtras.getInt(EXTRA_PROXIMITY);
mExtras.remove(EXTRA_PROXIMITY);
// Skip checking parcelable size if the new bundle size is 0. Newly empty bundle
// has parcelable size of 4, but the default bundle has parcelable size of 0.
if (mExtras.size() > 0) {
Preconditions.checkArgumentInRange(getParcelableSize(mExtras), 0,
getMaxBundleSize(), "extras");
}
mExtras.putInt(EXTRA_PROXIMITY, proximityValue);
} else {
Preconditions.checkArgumentInRange(getParcelableSize(mExtras), 0,
getMaxBundleSize(), "extras");
}
}
}
/**
* The list of the audio streams containing audio bytes that were used for hotword detection.
*
* @hide
*/
@UnsupportedAppUsage
public @NonNull List<HotwordAudioStream> getAudioStreams() {
return List.copyOf(mAudioStreams);
}
@DataClass.Suppress("addAudioStreams")
abstract static class BaseBuilder {
/**
* The list of the audio streams containing audio bytes that were used for hotword
* detection.
*
* @hide
*/
@UnsupportedAppUsage
public @NonNull Builder setAudioStreams(@NonNull List<HotwordAudioStream> value) {
Objects.requireNonNull(value, "value should not be null");
final Builder builder = (Builder) this;
// If the code gen flag in build() is changed, we must update the flag e.g. 0x200 here.
builder.mBuilderFieldsSet |= 0x200;
builder.mAudioStreams = List.copyOf(value);
return builder;
}
}
/**
* Provides an instance of {@link Builder} with state corresponding to this instance.
* @hide
*/
public Builder buildUpon() {
return new Builder()
.setConfidenceLevel(mConfidenceLevel)
.setMediaSyncEvent(mMediaSyncEvent)
.setHotwordOffsetMillis(mHotwordOffsetMillis)
.setHotwordDurationMillis(mHotwordDurationMillis)
.setAudioChannel(mAudioChannel)
.setHotwordDetectionPersonalized(mHotwordDetectionPersonalized)
.setScore(mScore)
.setPersonalizedScore(mPersonalizedScore)
.setHotwordPhraseId(mHotwordPhraseId)
.setAudioStreams(mAudioStreams)
.setExtras(mExtras);
}
/**
* Adds proximity level, either near or far, that is mapped for the given distance into
* the bundle. The proximity value is provided by the system, on devices that support detecting
* proximity of nearby users, to help disambiguate which nearby device should respond.
* This mapping will be excluded from the max bundle size calculation because this mapping is
* included after the result is returned from the hotword detector service. The value will not
* be included if the proximity was unknown.
*
* @hide
*/
public void setProximity(double distance) {
int proximityLevel = convertToProximityLevel(distance);
if (proximityLevel != PROXIMITY_UNKNOWN) {
mExtras.putInt(EXTRA_PROXIMITY, proximityLevel);
}
}
/**
* Mapping of the proximity distance (meters) to proximity values, unknown, near, and far.
* Currently, this mapping is handled by HotwordDetectedResult because it handles just
* HotwordDetectionConnection which we know the mapping of. However, the mapping will need to
* move to a more centralized place once there are more clients.
*
* TODO(b/258531144): Move the proximity mapping to a central location
*/
@ProximityValue
private int convertToProximityLevel(double distance) {
if (distance < 0) {
return PROXIMITY_UNKNOWN;
} else if (distance <= 3) {
return PROXIMITY_NEAR;
} else {
return PROXIMITY_FAR;
}
}
// Code below generated by codegen v1.0.23.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
//
// To regenerate run:
// $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java
//
// To exclude the generated code from IntelliJ auto-formatting enable (one-time):
// Settings > Editor > Code Style > Formatter Control
//@formatter:off
/** @hide */
@IntDef(prefix = "CONFIDENCE_LEVEL_", value = {
CONFIDENCE_LEVEL_NONE,
CONFIDENCE_LEVEL_LOW,
CONFIDENCE_LEVEL_LOW_MEDIUM,
CONFIDENCE_LEVEL_MEDIUM,
CONFIDENCE_LEVEL_MEDIUM_HIGH,
CONFIDENCE_LEVEL_HIGH,
CONFIDENCE_LEVEL_VERY_HIGH
})
@Retention(RetentionPolicy.SOURCE)
@DataClass.Generated.Member
public @interface ConfidenceLevel {}
/** @hide */
@DataClass.Generated.Member
public static String confidenceLevelToString(@ConfidenceLevel int value) {
switch (value) {
case CONFIDENCE_LEVEL_NONE:
return "CONFIDENCE_LEVEL_NONE";
case CONFIDENCE_LEVEL_LOW:
return "CONFIDENCE_LEVEL_LOW";
case CONFIDENCE_LEVEL_LOW_MEDIUM:
return "CONFIDENCE_LEVEL_LOW_MEDIUM";
case CONFIDENCE_LEVEL_MEDIUM:
return "CONFIDENCE_LEVEL_MEDIUM";
case CONFIDENCE_LEVEL_MEDIUM_HIGH:
return "CONFIDENCE_LEVEL_MEDIUM_HIGH";
case CONFIDENCE_LEVEL_HIGH:
return "CONFIDENCE_LEVEL_HIGH";
case CONFIDENCE_LEVEL_VERY_HIGH:
return "CONFIDENCE_LEVEL_VERY_HIGH";
default: return Integer.toHexString(value);
}
}
/** @hide */
@IntDef(prefix = "LIMIT_", value = {
LIMIT_HOTWORD_OFFSET_MAX_VALUE,
LIMIT_AUDIO_CHANNEL_MAX_VALUE
})
@Retention(RetentionPolicy.SOURCE)
@DataClass.Generated.Member
/* package-private */ @interface Limit {}
/** @hide */
@DataClass.Generated.Member
/* package-private */ static String limitToString(@Limit int value) {
switch (value) {
case LIMIT_HOTWORD_OFFSET_MAX_VALUE:
return "LIMIT_HOTWORD_OFFSET_MAX_VALUE";
case LIMIT_AUDIO_CHANNEL_MAX_VALUE:
return "LIMIT_AUDIO_CHANNEL_MAX_VALUE";
default: return Integer.toHexString(value);
}
}
/** @hide */
@IntDef(prefix = "PROXIMITY_", value = {
PROXIMITY_UNKNOWN,
PROXIMITY_NEAR,
PROXIMITY_FAR
})
@Retention(RetentionPolicy.SOURCE)
@DataClass.Generated.Member
public @interface Proximity {}
/** @hide */
@DataClass.Generated.Member
public static String proximityToString(@Proximity int value) {
switch (value) {
case PROXIMITY_UNKNOWN:
return "PROXIMITY_UNKNOWN";
case PROXIMITY_NEAR:
return "PROXIMITY_NEAR";
case PROXIMITY_FAR:
return "PROXIMITY_FAR";
default: return Integer.toHexString(value);
}
}
@DataClass.Generated.Member
/* package-private */ HotwordDetectedResult(
@HotwordConfidenceLevelValue int confidenceLevel,
@Nullable MediaSyncEvent mediaSyncEvent,
int hotwordOffsetMillis,
int hotwordDurationMillis,
int audioChannel,
boolean hotwordDetectionPersonalized,
int score,
int personalizedScore,
int hotwordPhraseId,
@NonNull List<HotwordAudioStream> audioStreams,
@NonNull PersistableBundle extras) {
this.mConfidenceLevel = confidenceLevel;
com.android.internal.util.AnnotationValidations.validate(
HotwordConfidenceLevelValue.class, null, mConfidenceLevel);
this.mMediaSyncEvent = mediaSyncEvent;
this.mHotwordOffsetMillis = hotwordOffsetMillis;
this.mHotwordDurationMillis = hotwordDurationMillis;
this.mAudioChannel = audioChannel;
this.mHotwordDetectionPersonalized = hotwordDetectionPersonalized;
this.mScore = score;
this.mPersonalizedScore = personalizedScore;
this.mHotwordPhraseId = hotwordPhraseId;
this.mAudioStreams = audioStreams;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAudioStreams);
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
onConstructed();
}
/**
* Confidence level in the trigger outcome.
*/
@DataClass.Generated.Member
public @HotwordConfidenceLevelValue int getConfidenceLevel() {
return mConfidenceLevel;
}
/**
* Offset in milliseconds the audio stream when the trigger event happened (end of hotword
* phrase).
*
* <p>Only value between 0 and 3600000 (inclusive) is accepted.
*/
@DataClass.Generated.Member
public int getHotwordOffsetMillis() {
return mHotwordOffsetMillis;
}
/**
* Duration in milliseconds of the hotword trigger phrase.
*
* <p>Only values between 0 and {@link android.media.AudioRecord#getMaxSharedAudioHistoryMillis}
* (inclusive) are accepted.
*/
@DataClass.Generated.Member
public int getHotwordDurationMillis() {
return mHotwordDurationMillis;
}
/**
* Audio channel containing the highest-confidence hotword signal.
*
* <p>Only value between 0 and 63 (inclusive) is accepted.
*/
@DataClass.Generated.Member
public int getAudioChannel() {
return mAudioChannel;
}
/**
* Returns whether the trigger has happened due to model having been personalized to fit user's
* voice.
*/
@DataClass.Generated.Member
public boolean isHotwordDetectionPersonalized() {
return mHotwordDetectionPersonalized;
}
/**
* Score for the hotword trigger.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public int getScore() {
return mScore;
}
/**
* Score for the hotword trigger for device user.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public int getPersonalizedScore() {
return mPersonalizedScore;
}
/**
* An ID representing the keyphrase that triggered the successful detection.
*
* <p>Only values between 0 and {@link #getMaxHotwordPhraseId()} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public int getHotwordPhraseId() {
return mHotwordPhraseId;
}
/**
* App-specific extras to support trigger.
*
* <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
* bundles will be rejected.
*
* <p>Only primitive types are supported in this bundle. Complex types will be removed from the
* bundle.
*
* <p>The use of this method is discouraged, and support for it will be removed in future
* versions of Android.
*
* <p>After the trigger happens, a special case of proximity-related extra, with the key of
* 'android.service.voice.extra.PROXIMITY_VALUE' and the value of proximity value (integer)
* will be stored to enable proximity logic. {@link HotwordDetectedResult#PROXIMITY_NEAR} will
* indicate 'NEAR' proximity and {@link HotwordDetectedResult#PROXIMITY_FAR} will indicate 'FAR'
* proximity. The proximity value is provided by the system, on devices that support detecting
* proximity of nearby users, to help disambiguate which nearby device should respond. When the
* proximity is unknown, the proximity value will not be stored. This mapping will be excluded
* from the max bundle size calculation because this mapping is included after the result is
* returned from the hotword detector service.
*
* <p>This is a PersistableBundle so it doesn't allow any remotable objects or other contents
* that can be used to communicate with other processes.
*/
@DataClass.Generated.Member
public @NonNull PersistableBundle getExtras() {
return mExtras;
}
@Override
@DataClass.Generated.Member
public String toString() {
// You can override field toString logic by defining methods like:
// String fieldNameToString() { ... }
return "HotwordDetectedResult { " +
"confidenceLevel = " + mConfidenceLevel + ", " +
"mediaSyncEvent = " + mMediaSyncEvent + ", " +
"hotwordOffsetMillis = " + mHotwordOffsetMillis + ", " +
"hotwordDurationMillis = " + mHotwordDurationMillis + ", " +
"audioChannel = " + mAudioChannel + ", " +
"hotwordDetectionPersonalized = " + mHotwordDetectionPersonalized + ", " +
"score = " + mScore + ", " +
"personalizedScore = " + mPersonalizedScore + ", " +
"hotwordPhraseId = " + mHotwordPhraseId + ", " +
"audioStreams = " + mAudioStreams + ", " +
"extras = " + mExtras +
" }";
}
@Override
@DataClass.Generated.Member
public boolean equals(@Nullable Object o) {
// You can override field equality logic by defining either of the methods like:
// boolean fieldNameEquals(HotwordDetectedResult other) { ... }
// boolean fieldNameEquals(FieldType otherValue) { ... }
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
@SuppressWarnings("unchecked")
HotwordDetectedResult that = (HotwordDetectedResult) o;
//noinspection PointlessBooleanExpression
return true
&& mConfidenceLevel == that.mConfidenceLevel
&& Objects.equals(mMediaSyncEvent, that.mMediaSyncEvent)
&& mHotwordOffsetMillis == that.mHotwordOffsetMillis
&& mHotwordDurationMillis == that.mHotwordDurationMillis
&& mAudioChannel == that.mAudioChannel
&& mHotwordDetectionPersonalized == that.mHotwordDetectionPersonalized
&& mScore == that.mScore
&& mPersonalizedScore == that.mPersonalizedScore
&& mHotwordPhraseId == that.mHotwordPhraseId
&& Objects.equals(mAudioStreams, that.mAudioStreams)
&& Objects.equals(mExtras, that.mExtras);
}
@Override
@DataClass.Generated.Member
public int hashCode() {
// You can override field hashCode logic by defining methods like:
// int fieldNameHashCode() { ... }
int _hash = 1;
_hash = 31 * _hash + mConfidenceLevel;
_hash = 31 * _hash + Objects.hashCode(mMediaSyncEvent);
_hash = 31 * _hash + mHotwordOffsetMillis;
_hash = 31 * _hash + mHotwordDurationMillis;
_hash = 31 * _hash + mAudioChannel;
_hash = 31 * _hash + Boolean.hashCode(mHotwordDetectionPersonalized);
_hash = 31 * _hash + mScore;
_hash = 31 * _hash + mPersonalizedScore;
_hash = 31 * _hash + mHotwordPhraseId;
_hash = 31 * _hash + Objects.hashCode(mAudioStreams);
_hash = 31 * _hash + Objects.hashCode(mExtras);
return _hash;
}
@Override
@DataClass.Generated.Member
public void writeToParcel(@NonNull Parcel dest, int flags) {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
int flg = 0;
if (mHotwordDetectionPersonalized) flg |= 0x20;
if (mMediaSyncEvent != null) flg |= 0x2;
dest.writeInt(flg);
dest.writeInt(mConfidenceLevel);
if (mMediaSyncEvent != null) dest.writeTypedObject(mMediaSyncEvent, flags);
dest.writeInt(mHotwordOffsetMillis);
dest.writeInt(mHotwordDurationMillis);
dest.writeInt(mAudioChannel);
dest.writeInt(mScore);
dest.writeInt(mPersonalizedScore);
dest.writeInt(mHotwordPhraseId);
dest.writeParcelableList(mAudioStreams, flags);
dest.writeTypedObject(mExtras, flags);
}
@Override
@DataClass.Generated.Member
public int describeContents() { return 0; }
/** @hide */
@SuppressWarnings({"unchecked", "RedundantCast"})
@DataClass.Generated.Member
/* package-private */ HotwordDetectedResult(@NonNull Parcel in) {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
int flg = in.readInt();
boolean hotwordDetectionPersonalized = (flg & 0x20) != 0;
int confidenceLevel = in.readInt();
MediaSyncEvent mediaSyncEvent = (flg & 0x2) == 0 ? null : (MediaSyncEvent) in.readTypedObject(MediaSyncEvent.CREATOR);
int hotwordOffsetMillis = in.readInt();
int hotwordDurationMillis = in.readInt();
int audioChannel = in.readInt();
int score = in.readInt();
int personalizedScore = in.readInt();
int hotwordPhraseId = in.readInt();
List<HotwordAudioStream> audioStreams = new ArrayList<>();
in.readParcelableList(audioStreams, HotwordAudioStream.class.getClassLoader());
PersistableBundle extras = (PersistableBundle) in.readTypedObject(PersistableBundle.CREATOR);
this.mConfidenceLevel = confidenceLevel;
com.android.internal.util.AnnotationValidations.validate(
HotwordConfidenceLevelValue.class, null, mConfidenceLevel);
this.mMediaSyncEvent = mediaSyncEvent;
this.mHotwordOffsetMillis = hotwordOffsetMillis;
this.mHotwordDurationMillis = hotwordDurationMillis;
this.mAudioChannel = audioChannel;
this.mHotwordDetectionPersonalized = hotwordDetectionPersonalized;
this.mScore = score;
this.mPersonalizedScore = personalizedScore;
this.mHotwordPhraseId = hotwordPhraseId;
this.mAudioStreams = audioStreams;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mAudioStreams);
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
onConstructed();
}
@DataClass.Generated.Member
public static final @NonNull Parcelable.Creator<HotwordDetectedResult> CREATOR
= new Parcelable.Creator<HotwordDetectedResult>() {
@Override
public HotwordDetectedResult[] newArray(int size) {
return new HotwordDetectedResult[size];
}
@Override
public HotwordDetectedResult createFromParcel(@NonNull Parcel in) {
return new HotwordDetectedResult(in);
}
};
/**
* A builder for {@link HotwordDetectedResult}
*/
@SuppressWarnings("WeakerAccess")
@DataClass.Generated.Member
public static final class Builder extends BaseBuilder {
private @HotwordConfidenceLevelValue int mConfidenceLevel;
private @Nullable MediaSyncEvent mMediaSyncEvent;
private int mHotwordOffsetMillis;
private int mHotwordDurationMillis;
private int mAudioChannel;
private boolean mHotwordDetectionPersonalized;
private int mScore;
private int mPersonalizedScore;
private int mHotwordPhraseId;
private @NonNull List<HotwordAudioStream> mAudioStreams;
private @NonNull PersistableBundle mExtras;
private long mBuilderFieldsSet = 0L;
public Builder() {
}
/**
* Confidence level in the trigger outcome.
*/
@DataClass.Generated.Member
public @NonNull Builder setConfidenceLevel(@HotwordConfidenceLevelValue int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x1;
mConfidenceLevel = value;
return this;
}
/**
* A {@code MediaSyncEvent} that allows the {@link HotwordDetector} to recapture the audio
* that contains the hotword trigger. This must be obtained using
* {@link android.media.AudioRecord#shareAudioHistory(String, long)}.
*/
@DataClass.Generated.Member
public @NonNull Builder setMediaSyncEvent(@NonNull MediaSyncEvent value) {
checkNotUsed();
mBuilderFieldsSet |= 0x2;
mMediaSyncEvent = value;
return this;
}
/**
* Offset in milliseconds the audio stream when the trigger event happened (end of hotword
* phrase).
*
* <p>Only value between 0 and 3600000 (inclusive) is accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setHotwordOffsetMillis(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x4;
mHotwordOffsetMillis = value;
return this;
}
/**
* Duration in milliseconds of the hotword trigger phrase.
*
* <p>Only values between 0 and {@link android.media.AudioRecord#getMaxSharedAudioHistoryMillis}
* (inclusive) are accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setHotwordDurationMillis(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x8;
mHotwordDurationMillis = value;
return this;
}
/**
* Audio channel containing the highest-confidence hotword signal.
*
* <p>Only value between 0 and 63 (inclusive) is accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setAudioChannel(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x10;
mAudioChannel = value;
return this;
}
/**
* Returns whether the trigger has happened due to model having been personalized to fit user's
* voice.
*/
@DataClass.Generated.Member
public @NonNull Builder setHotwordDetectionPersonalized(boolean value) {
checkNotUsed();
mBuilderFieldsSet |= 0x20;
mHotwordDetectionPersonalized = value;
return this;
}
/**
* Score for the hotword trigger.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setScore(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x40;
mScore = value;
return this;
}
/**
* Score for the hotword trigger for device user.
*
* <p>Only values between 0 and {@link #getMaxScore} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setPersonalizedScore(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x80;
mPersonalizedScore = value;
return this;
}
/**
* An ID representing the keyphrase that triggered the successful detection.
*
* <p>Only values between 0 and {@link #getMaxHotwordPhraseId()} (inclusive) are accepted.
*/
@DataClass.Generated.Member
public @NonNull Builder setHotwordPhraseId(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x100;
mHotwordPhraseId = value;
return this;
}
/**
* App-specific extras to support trigger.
*
* <p>The size of this bundle will be limited to {@link #getMaxBundleSize}. Results will larger
* bundles will be rejected.
*
* <p>Only primitive types are supported in this bundle. Complex types will be removed from the
* bundle.
*
* <p>The use of this method is discouraged, and support for it will be removed in future
* versions of Android.
*
* <p>After the trigger happens, a special case of proximity-related extra, with the key of
* 'android.service.voice.extra.PROXIMITY_VALUE' and the value of proximity value (integer)
* will be stored to enable proximity logic. {@link HotwordDetectedResult#PROXIMITY_NEAR} will
* indicate 'NEAR' proximity and {@link HotwordDetectedResult#PROXIMITY_FAR} will indicate 'FAR'
* proximity. The proximity value is provided by the system, on devices that support detecting
* proximity of nearby users, to help disambiguate which nearby device should respond. When the
* proximity is unknown, the proximity value will not be stored. This mapping will be excluded
* from the max bundle size calculation because this mapping is included after the result is
* returned from the hotword detector service.
*
* <p>This is a PersistableBundle so it doesn't allow any remotable objects or other contents
* that can be used to communicate with other processes.
*/
@DataClass.Generated.Member
public @NonNull Builder setExtras(@NonNull PersistableBundle value) {
checkNotUsed();
mBuilderFieldsSet |= 0x400;
mExtras = value;
return this;
}
/** Builds the instance. This builder should not be touched after calling this! */
public @NonNull HotwordDetectedResult build() {
checkNotUsed();
mBuilderFieldsSet |= 0x800; // Mark builder used
if ((mBuilderFieldsSet & 0x1) == 0) {
mConfidenceLevel = defaultConfidenceLevel();
}
if ((mBuilderFieldsSet & 0x2) == 0) {
mMediaSyncEvent = null;
}
if ((mBuilderFieldsSet & 0x4) == 0) {
mHotwordOffsetMillis = HOTWORD_OFFSET_UNSET;
}
if ((mBuilderFieldsSet & 0x8) == 0) {
mHotwordDurationMillis = 0;
}
if ((mBuilderFieldsSet & 0x10) == 0) {
mAudioChannel = AUDIO_CHANNEL_UNSET;
}
if ((mBuilderFieldsSet & 0x20) == 0) {
mHotwordDetectionPersonalized = false;
}
if ((mBuilderFieldsSet & 0x40) == 0) {
mScore = defaultScore();
}
if ((mBuilderFieldsSet & 0x80) == 0) {
mPersonalizedScore = defaultPersonalizedScore();
}
if ((mBuilderFieldsSet & 0x100) == 0) {
mHotwordPhraseId = defaultHotwordPhraseId();
}
if ((mBuilderFieldsSet & 0x200) == 0) {
mAudioStreams = defaultAudioStreams();
}
if ((mBuilderFieldsSet & 0x400) == 0) {
mExtras = defaultExtras();
}
HotwordDetectedResult o = new HotwordDetectedResult(
mConfidenceLevel,
mMediaSyncEvent,
mHotwordOffsetMillis,
mHotwordDurationMillis,
mAudioChannel,
mHotwordDetectionPersonalized,
mScore,
mPersonalizedScore,
mHotwordPhraseId,
mAudioStreams,
mExtras);
return o;
}
private void checkNotUsed() {
if ((mBuilderFieldsSet & 0x800) != 0) {
throw new IllegalStateException(
"This Builder should not be reused. Use a new Builder instance instead");
}
}
}
@DataClass.Generated(
time = 1668528946960L,
codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java",
inputSignatures = "public static final int CONFIDENCE_LEVEL_NONE\npublic static final int CONFIDENCE_LEVEL_LOW\npublic static final int CONFIDENCE_LEVEL_LOW_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM\npublic static final int CONFIDENCE_LEVEL_MEDIUM_HIGH\npublic static final int CONFIDENCE_LEVEL_HIGH\npublic static final int CONFIDENCE_LEVEL_VERY_HIGH\npublic static final int HOTWORD_OFFSET_UNSET\npublic static final int AUDIO_CHANNEL_UNSET\nprivate static final int LIMIT_HOTWORD_OFFSET_MAX_VALUE\nprivate static final int LIMIT_AUDIO_CHANNEL_MAX_VALUE\nprivate static final java.lang.String EXTRA_PROXIMITY\npublic static final int PROXIMITY_UNKNOWN\npublic static final int PROXIMITY_NEAR\npublic static final int PROXIMITY_FAR\nprivate final @android.service.voice.HotwordDetectedResult.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate @android.annotation.Nullable android.media.MediaSyncEvent mMediaSyncEvent\nprivate int mHotwordOffsetMillis\nprivate int mHotwordDurationMillis\nprivate int mAudioChannel\nprivate boolean mHotwordDetectionPersonalized\nprivate final int mScore\nprivate final int mPersonalizedScore\nprivate final int mHotwordPhraseId\nprivate final @android.annotation.NonNull java.util.List<android.service.voice.HotwordAudioStream> mAudioStreams\nprivate final @android.annotation.NonNull android.os.PersistableBundle mExtras\nprivate static int sMaxBundleSize\nprivate static int defaultConfidenceLevel()\nprivate static int defaultScore()\nprivate static int defaultPersonalizedScore()\npublic static int getMaxScore()\nprivate static int defaultHotwordPhraseId()\npublic static int getMaxHotwordPhraseId()\nprivate static java.util.List<android.service.voice.HotwordAudioStream> defaultAudioStreams()\nprivate static android.os.PersistableBundle defaultExtras()\npublic static int getMaxBundleSize()\npublic @android.annotation.Nullable android.media.MediaSyncEvent getMediaSyncEvent()\npublic static int getParcelableSize(android.os.Parcelable)\npublic static int getUsageSize(android.service.voice.HotwordDetectedResult)\nprivate static int bitCount(long)\nprivate void onConstructed()\npublic @android.compat.annotation.UnsupportedAppUsage @android.annotation.NonNull java.util.List<android.service.voice.HotwordAudioStream> getAudioStreams()\npublic android.service.voice.HotwordDetectedResult.Builder buildUpon()\npublic void setProximity(double)\nprivate @android.service.voice.HotwordDetectedResult.ProximityValue int convertToProximityLevel(double)\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\npublic @android.compat.annotation.UnsupportedAppUsage @android.annotation.NonNull android.service.voice.HotwordDetectedResult.Builder setAudioStreams(java.util.List<android.service.voice.HotwordAudioStream>)\nclass BaseBuilder extends java.lang.Object implements []\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)\npublic @android.compat.annotation.UnsupportedAppUsage @android.annotation.NonNull android.service.voice.HotwordDetectedResult.Builder setAudioStreams(java.util.List<android.service.voice.HotwordAudioStream>)\nclass BaseBuilder extends java.lang.Object implements []")
@Deprecated
private void __metadata() {}
//@formatter:on
// End of generated code
}
|