Merge "Logging the number of bits egressing from the hotword trusted process" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
023fa14302
@@ -237,6 +237,55 @@ public final class HotwordDetectedResult implements Parcelable {
|
|||||||
return size;
|
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 += Integer.SIZE;
|
||||||
|
}
|
||||||
|
if (hotwordDetectedResult.getHotwordDurationMillis() != 0) {
|
||||||
|
totalBits += bitCount(AudioRecord.getMaxSharedAudioHistoryMillis());
|
||||||
|
}
|
||||||
|
if (hotwordDetectedResult.getAudioChannel() != AUDIO_CHANNEL_UNSET) {
|
||||||
|
totalBits += Integer.SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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() {
|
private void onConstructed() {
|
||||||
Preconditions.checkArgumentInRange(mScore, 0, getMaxScore(), "score");
|
Preconditions.checkArgumentInRange(mScore, 0, getMaxScore(), "score");
|
||||||
Preconditions.checkArgumentInRange(mPersonalizedScore, 0, getMaxScore(),
|
Preconditions.checkArgumentInRange(mPersonalizedScore, 0, getMaxScore(),
|
||||||
@@ -784,10 +833,10 @@ public final class HotwordDetectedResult implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@DataClass.Generated(
|
@DataClass.Generated(
|
||||||
time = 1624361647985L,
|
time = 1625198973370L,
|
||||||
codegenVersion = "1.0.23",
|
codegenVersion = "1.0.23",
|
||||||
sourceFile = "frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java",
|
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 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 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 android.os.PersistableBundle defaultExtras()\npublic static int getMaxBundleSize()\npublic @android.annotation.Nullable android.media.MediaSyncEvent getMediaSyncEvent()\npublic static int getParcelableSize(android.os.Parcelable)\nprivate void onConstructed()\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
|
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 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 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 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()\nclass HotwordDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
|
||||||
@Deprecated
|
@Deprecated
|
||||||
private void __metadata() {}
|
private void __metadata() {}
|
||||||
|
|
||||||
|
|||||||
@@ -283,6 +283,10 @@ final class HotwordDetectionConnection {
|
|||||||
if (mPerformingSoftwareHotwordDetection) {
|
if (mPerformingSoftwareHotwordDetection) {
|
||||||
mSoftwareCallback.onDetected(result, null, null);
|
mSoftwareCallback.onDetected(result, null, null);
|
||||||
mPerformingSoftwareHotwordDetection = false;
|
mPerformingSoftwareHotwordDetection = false;
|
||||||
|
if (result != null) {
|
||||||
|
Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(result)
|
||||||
|
+ " bits from hotword trusted process");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Slog.i(TAG, "Hotword detection has already completed");
|
Slog.i(TAG, "Hotword detection has already completed");
|
||||||
}
|
}
|
||||||
@@ -372,6 +376,10 @@ final class HotwordDetectionConnection {
|
|||||||
if (mValidatingDspTrigger) {
|
if (mValidatingDspTrigger) {
|
||||||
mValidatingDspTrigger = false;
|
mValidatingDspTrigger = false;
|
||||||
externalCallback.onKeyphraseDetected(recognitionEvent, result);
|
externalCallback.onKeyphraseDetected(recognitionEvent, result);
|
||||||
|
if (result != null) {
|
||||||
|
Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(result)
|
||||||
|
+ " bits from hotword trusted process");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Slog.i(TAG, "Ignored hotword detected since trigger has been handled");
|
Slog.i(TAG, "Ignored hotword detected since trigger has been handled");
|
||||||
}
|
}
|
||||||
@@ -425,6 +433,10 @@ final class HotwordDetectionConnection {
|
|||||||
}
|
}
|
||||||
mValidatingDspTrigger = false;
|
mValidatingDspTrigger = false;
|
||||||
externalCallback.onKeyphraseDetected(recognitionEvent, result);
|
externalCallback.onKeyphraseDetected(recognitionEvent, result);
|
||||||
|
if (result != null) {
|
||||||
|
Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(result)
|
||||||
|
+ " bits from hotword trusted process");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -654,6 +666,10 @@ final class HotwordDetectionConnection {
|
|||||||
// TODO: noteOp here.
|
// TODO: noteOp here.
|
||||||
callback.onDetected(triggerResult, null /* audioFormat */,
|
callback.onDetected(triggerResult, null /* audioFormat */,
|
||||||
null /* audioStream */);
|
null /* audioStream */);
|
||||||
|
if (triggerResult != null) {
|
||||||
|
Slog.i(TAG, "Egressed " + HotwordDetectedResult.getUsageSize(
|
||||||
|
triggerResult) + " bits from hotword trusted process");
|
||||||
|
}
|
||||||
// TODO: Add a delay before closing.
|
// TODO: Add a delay before closing.
|
||||||
bestEffortClose(audioSource);
|
bestEffortClose(audioSource);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user