summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorAhaan Ugale <augale@google.com>2021-03-28 14:31:24 -0700
committerAhaan Ugale <augale@google.com>2021-03-28 14:31:24 -0700
commit9ea331f06d2756cc0878a3bf43b405c24616936c (patch)
tree24732f276ad6712f350f0fbf65e0db055a67bfba /core/java
parent3309f23317403e2691cb71090fb142efba04b61e (diff)
Fix HotwordDetectedResult phrase and extras.
Requiring hotword phrases to be listed in the manifest is punted to T. A simple limited phrase ID is used for now. Use PersistableBundle for the extras so that remotable objects cannot be passed through it. Bug: 182788844 Bug: 168305377 CTS-Coverage-Bug: 183425641 Test: builds Change-Id: I9c1472b586f737788cc10d8dd7e023f348763392
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/service/voice/HotwordDetectedResult.java95
1 files changed, 54 insertions, 41 deletions
diff --git a/core/java/android/service/voice/HotwordDetectedResult.java b/core/java/android/service/voice/HotwordDetectedResult.java
index dd6f69818553..f5d796f92a4d 100644
--- a/core/java/android/service/voice/HotwordDetectedResult.java
+++ b/core/java/android/service/voice/HotwordDetectedResult.java
@@ -21,8 +21,8 @@ import static android.service.voice.HotwordDetector.CONFIDENCE_LEVEL_NONE;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
-import android.os.Bundle;
import android.os.Parcelable;
+import android.os.PersistableBundle;
import com.android.internal.util.DataClass;
@@ -92,16 +92,20 @@ public final class HotwordDetectedResult implements Parcelable {
}
/**
- * Triggered phrase.
+ * An ID representing the keyphrase that triggered the successful detection.
*
- * <p>This phrase has to be listed in the AndroidManifest of the application in order for
- * trigger to be accepted by the system.
+ * <p>Only values between 0 and {@link #getMaxHotwordPhraseId()} (inclusive) are accepted.
*/
- // TODO(b/183128696): allow listing this in the manifest.
- @Nullable
- private final String mHotwordPhrase;
- private static String defaultHotwordPhrase() {
- return null;
+ private final int mHotwordPhraseId;
+ private static int defaultHotwordPhraseId() {
+ return 0;
+ }
+
+ /**
+ * Returns the maximum value of {@link #getHotwordPhraseId()}.
+ */
+ public static int getMaxHotwordPhraseId() {
+ return 63;
}
/**
@@ -115,11 +119,14 @@ public final class HotwordDetectedResult implements Parcelable {
*
* <p>The use of this method is discouraged, and support for it will be removed in future
* versions of Android.
+ *
+ * <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 Bundle mExtras;
- private static Bundle defaultExtras() {
- return new Bundle();
+ private final PersistableBundle mExtras;
+ private static PersistableBundle defaultExtras() {
+ return new PersistableBundle();
}
/**
@@ -136,7 +143,7 @@ public final class HotwordDetectedResult implements Parcelable {
- // Code below generated by codegen v1.0.22.
+ // Code below generated by codegen v1.0.23.
//
// DO NOT MODIFY!
// CHECKSTYLE:OFF Generated code
@@ -155,15 +162,15 @@ public final class HotwordDetectedResult implements Parcelable {
int byteOffset,
int score,
int personalizedScore,
- @Nullable String hotwordPhrase,
- @NonNull Bundle extras) {
+ int hotwordPhraseId,
+ @NonNull PersistableBundle extras) {
this.mConfidenceLevel = confidenceLevel;
com.android.internal.util.AnnotationValidations.validate(
HotwordDetector.HotwordConfidenceLevelValue.class, null, mConfidenceLevel);
this.mByteOffset = byteOffset;
this.mScore = score;
this.mPersonalizedScore = personalizedScore;
- this.mHotwordPhrase = hotwordPhrase;
+ this.mHotwordPhraseId = hotwordPhraseId;
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
@@ -209,9 +216,14 @@ public final class HotwordDetectedResult implements Parcelable {
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 @Nullable String getHotwordPhrase() {
- return mHotwordPhrase;
+ public int getHotwordPhraseId() {
+ return mHotwordPhraseId;
}
/**
@@ -227,7 +239,7 @@ public final class HotwordDetectedResult implements Parcelable {
* versions of Android.
*/
@DataClass.Generated.Member
- public @NonNull Bundle getExtras() {
+ public @NonNull PersistableBundle getExtras() {
return mExtras;
}
@@ -242,7 +254,7 @@ public final class HotwordDetectedResult implements Parcelable {
"byteOffset = " + mByteOffset + ", " +
"score = " + mScore + ", " +
"personalizedScore = " + mPersonalizedScore + ", " +
- "hotwordPhrase = " + mHotwordPhrase + ", " +
+ "hotwordPhraseId = " + mHotwordPhraseId + ", " +
"extras = " + mExtras +
" }";
}
@@ -264,7 +276,7 @@ public final class HotwordDetectedResult implements Parcelable {
&& mByteOffset == that.mByteOffset
&& mScore == that.mScore
&& mPersonalizedScore == that.mPersonalizedScore
- && java.util.Objects.equals(mHotwordPhrase, that.mHotwordPhrase)
+ && mHotwordPhraseId == that.mHotwordPhraseId
&& java.util.Objects.equals(mExtras, that.mExtras);
}
@@ -279,7 +291,7 @@ public final class HotwordDetectedResult implements Parcelable {
_hash = 31 * _hash + mByteOffset;
_hash = 31 * _hash + mScore;
_hash = 31 * _hash + mPersonalizedScore;
- _hash = 31 * _hash + java.util.Objects.hashCode(mHotwordPhrase);
+ _hash = 31 * _hash + mHotwordPhraseId;
_hash = 31 * _hash + java.util.Objects.hashCode(mExtras);
return _hash;
}
@@ -290,15 +302,12 @@ public final class HotwordDetectedResult implements Parcelable {
// You can override field parcelling by defining methods like:
// void parcelFieldName(Parcel dest, int flags) { ... }
- byte flg = 0;
- if (mHotwordPhrase != null) flg |= 0x10;
- dest.writeByte(flg);
dest.writeInt(mConfidenceLevel);
dest.writeInt(mByteOffset);
dest.writeInt(mScore);
dest.writeInt(mPersonalizedScore);
- if (mHotwordPhrase != null) dest.writeString(mHotwordPhrase);
- dest.writeBundle(mExtras);
+ dest.writeInt(mHotwordPhraseId);
+ dest.writeTypedObject(mExtras, flags);
}
@Override
@@ -312,13 +321,12 @@ public final class HotwordDetectedResult implements Parcelable {
// You can override field unparcelling by defining methods like:
// static FieldType unparcelFieldName(Parcel in) { ... }
- byte flg = in.readByte();
int confidenceLevel = in.readInt();
int byteOffset = in.readInt();
int score = in.readInt();
int personalizedScore = in.readInt();
- String hotwordPhrase = (flg & 0x10) == 0 ? null : in.readString();
- Bundle extras = in.readBundle();
+ int hotwordPhraseId = in.readInt();
+ PersistableBundle extras = (PersistableBundle) in.readTypedObject(PersistableBundle.CREATOR);
this.mConfidenceLevel = confidenceLevel;
com.android.internal.util.AnnotationValidations.validate(
@@ -326,7 +334,7 @@ public final class HotwordDetectedResult implements Parcelable {
this.mByteOffset = byteOffset;
this.mScore = score;
this.mPersonalizedScore = personalizedScore;
- this.mHotwordPhrase = hotwordPhrase;
+ this.mHotwordPhraseId = hotwordPhraseId;
this.mExtras = extras;
com.android.internal.util.AnnotationValidations.validate(
NonNull.class, null, mExtras);
@@ -359,8 +367,8 @@ public final class HotwordDetectedResult implements Parcelable {
private int mByteOffset;
private int mScore;
private int mPersonalizedScore;
- private @Nullable String mHotwordPhrase;
- private @NonNull Bundle mExtras;
+ private int mHotwordPhraseId;
+ private @NonNull PersistableBundle mExtras;
private long mBuilderFieldsSet = 0L;
@@ -417,11 +425,16 @@ public final class HotwordDetectedResult implements Parcelable {
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 setHotwordPhrase(@NonNull String value) {
+ public @NonNull Builder setHotwordPhraseId(int value) {
checkNotUsed();
mBuilderFieldsSet |= 0x10;
- mHotwordPhrase = value;
+ mHotwordPhraseId = value;
return this;
}
@@ -438,7 +451,7 @@ public final class HotwordDetectedResult implements Parcelable {
* versions of Android.
*/
@DataClass.Generated.Member
- public @NonNull Builder setExtras(@NonNull Bundle value) {
+ public @NonNull Builder setExtras(@NonNull PersistableBundle value) {
checkNotUsed();
mBuilderFieldsSet |= 0x20;
mExtras = value;
@@ -463,7 +476,7 @@ public final class HotwordDetectedResult implements Parcelable {
mPersonalizedScore = defaultPersonalizedScore();
}
if ((mBuilderFieldsSet & 0x10) == 0) {
- mHotwordPhrase = defaultHotwordPhrase();
+ mHotwordPhraseId = defaultHotwordPhraseId();
}
if ((mBuilderFieldsSet & 0x20) == 0) {
mExtras = defaultExtras();
@@ -473,7 +486,7 @@ public final class HotwordDetectedResult implements Parcelable {
mByteOffset,
mScore,
mPersonalizedScore,
- mHotwordPhrase,
+ mHotwordPhraseId,
mExtras);
return o;
}
@@ -487,10 +500,10 @@ public final class HotwordDetectedResult implements Parcelable {
}
@DataClass.Generated(
- time = 1616110545582L,
- codegenVersion = "1.0.22",
+ time = 1616965644404L,
+ codegenVersion = "1.0.23",
sourceFile = "frameworks/base/core/java/android/service/voice/HotwordDetectedResult.java",
- inputSignatures = "public static final int BYTE_OFFSET_UNSET\nprivate final @android.service.voice.HotwordDetector.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate final int mByteOffset\nprivate final int mScore\nprivate final int mPersonalizedScore\nprivate final @android.annotation.Nullable java.lang.String mHotwordPhrase\nprivate final @android.annotation.NonNull android.os.Bundle mExtras\nprivate static int defaultConfidenceLevel()\nprivate static int defaultByteOffset()\nprivate static int defaultScore()\nprivate static int defaultPersonalizedScore()\npublic static int getMaxScore()\nprivate static java.lang.String defaultHotwordPhrase()\nprivate static android.os.Bundle defaultExtras()\npublic static int getMaxBundleSize()\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 BYTE_OFFSET_UNSET\nprivate final @android.service.voice.HotwordDetector.HotwordConfidenceLevelValue int mConfidenceLevel\nprivate final int mByteOffset\nprivate final int mScore\nprivate final int mPersonalizedScore\nprivate final int mHotwordPhraseId\nprivate final @android.annotation.NonNull android.os.PersistableBundle mExtras\nprivate static int defaultConfidenceLevel()\nprivate static int defaultByteOffset()\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()\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
private void __metadata() {}