Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6f604ad authored by Sandeep's avatar Sandeep Committed by Android (Google) Code Review
Browse files

Merge "Always on hotword changes"

parents 78311f36 d7018200
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -26427,8 +26427,37 @@ package android.service.trust {
package android.service.voice {
  public class AlwaysOnHotwordDetector {
    method public int getAvailability();
    method public android.content.Intent getManageIntent(int);
    method public int getRecognitionStatus();
    method public int startRecognition();
    method public int stopRecognition();
    field public static final int KEYPHRASE_ENROLLED = 2; // 0x2
    field public static final int KEYPHRASE_HARDWARE_UNAVAILABLE = -2; // 0xfffffffe
    field public static final int KEYPHRASE_UNENROLLED = 1; // 0x1
    field public static final int KEYPHRASE_UNSUPPORTED = -1; // 0xffffffff
    field public static final int MANAGE_ACTION_ENROLL = 0; // 0x0
    field public static final int MANAGE_ACTION_RE_ENROLL = 1; // 0x1
    field public static final int MANAGE_ACTION_UN_ENROLL = 2; // 0x2
    field public static final int RECOGNITION_ACTIVE = 2; // 0x2
    field public static final int RECOGNITION_DISABLED_TEMPORARILY = -1; // 0xffffffff
    field public static final int RECOGNITION_NOT_AVAILABLE = -3; // 0xfffffffd
    field public static final int RECOGNITION_NOT_REQUESTED = -2; // 0xfffffffe
    field public static final int RECOGNITION_REQUESTED = 1; // 0x1
    field public static final int STATUS_ERROR = -2147483648; // 0x80000000
    field public static final int STATUS_OK = 1; // 0x1
  }
  public static abstract interface AlwaysOnHotwordDetector.Callback {
    method public abstract void onDetected();
    method public abstract void onDetectionStarted();
    method public abstract void onDetectionStopped();
  }
  public class VoiceInteractionService extends android.app.Service {
    ctor public VoiceInteractionService();
    method public final android.service.voice.AlwaysOnHotwordDetector getAlwaysOnHotwordDetector(java.lang.String, java.lang.String, android.service.voice.AlwaysOnHotwordDetector.Callback);
    method public android.os.IBinder onBind(android.content.Intent);
    method public void startSession(android.os.Bundle);
    field public static final java.lang.String SERVICE_INTERFACE = "android.service.voice.VoiceInteractionService";
+3 −2
Original line number Diff line number Diff line
/*
/**
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,12 +14,13 @@
 * limitations under the License.
 */

package android.service.voice;
package android.hardware.soundtrigger;

import java.util.UUID;

/**
 * Properties of the DSP hardware on the device.
 *
 * @hide
 */
public class DspInfo {
+4 −0
Original line number Diff line number Diff line
package android.hardware.soundtrigger;

// @hide
parcelable Keyphrase;
 No newline at end of file
+101 −0
Original line number Diff line number Diff line
/**
 * Copyright (C) 2014 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.hardware.soundtrigger;

import android.os.Parcel;
import android.os.Parcelable;

/**
 * A Voice Keyphrase.
 *
 * @hide
 */
public class Keyphrase implements Parcelable {
    /** A unique identifier for this keyphrase */
    public final int id;
    /** A hint text to display corresponding to this keyphrase, e.g. "Hello There". */
    public final String hintText;
    /** The locale of interest when using this Keyphrase. */
    public String locale;

    public static final Parcelable.Creator<Keyphrase> CREATOR
            = new Parcelable.Creator<Keyphrase>() {
        public Keyphrase createFromParcel(Parcel in) {
            return Keyphrase.fromParcel(in);
        }

        public Keyphrase[] newArray(int size) {
            return new Keyphrase[size];
        }
    };

    private static Keyphrase fromParcel(Parcel in) {
        return new Keyphrase(in.readInt(), in.readString(), in.readString());
    }

    public Keyphrase(int id, String hintText, String locale) {
        this.id = id;
        this.hintText = hintText;
        this.locale = locale;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(id);
        dest.writeString(hintText);
        dest.writeString(locale);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((hintText == null) ? 0 : hintText.hashCode());
        result = prime * result + id;
        result = prime * result + ((locale == null) ? 0 : locale.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        Keyphrase other = (Keyphrase) obj;
        if (hintText == null) {
            if (other.hintText != null)
                return false;
        } else if (!hintText.equals(other.hintText))
            return false;
        if (id != other.id)
            return false;
        if (locale == null) {
            if (other.locale != null)
                return false;
        } else if (!locale.equals(other.locale))
            return false;
        return true;
    }
}
+39 −25
Original line number Diff line number Diff line
/*
/**
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,7 +14,7 @@
 * limitations under the License.
 */

package android.service.voice;
package android.hardware.soundtrigger;

import android.Manifest;
import android.content.Intent;
@@ -24,6 +24,7 @@ import android.content.pm.ResolveInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.service.voice.AlwaysOnHotwordDetector;
import android.util.AttributeSet;
import android.util.Slog;
import android.util.Xml;
@@ -34,7 +35,11 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.List;

/** @hide */
/**
 * Enrollment information about the different available keyphrases.
 *
 * @hide
 */
public class KeyphraseEnrollmentInfo {
    private static final String TAG = "KeyphraseEnrollmentInfo";
    /**
@@ -53,10 +58,14 @@ public class KeyphraseEnrollmentInfo {
    public static final String ACTION_MANAGE_VOICE_KEYPHRASES =
            "com.android.intent.action.MANAGE_VOICE_KEYPHRASES";
    /**
     * Intent extra: The intent extra for un-enrolling a user for a particular keyphrase.
     * Intent extra: The intent extra for the specific manage action that needs to be performed.
     * Possible values are {@link AlwaysOnHotwordDetector#MANAGE_ACTION_ENROLL},
     * {@link AlwaysOnHotwordDetector#MANAGE_ACTION_RE_ENROLL}
     * or {@link AlwaysOnHotwordDetector#MANAGE_ACTION_UN_ENROLL}.
     */
    public static final String EXTRA_VOICE_KEYPHRASE_UNENROLL =
            "com.android.intent.extra.VOICE_KEYPHRASE_UNENROLL";
    public static final String EXTRA_VOICE_KEYPHRASE_ACTION =
            "com.android.intent.extra.VOICE_KEYPHRASE_ACTION";

    /**
     * Intent extra: The hint text to be shown on the voice keyphrase management UI.
     */
@@ -68,7 +77,7 @@ public class KeyphraseEnrollmentInfo {
    public static final String EXTRA_VOICE_KEYPHRASE_LOCALE =
            "com.android.intent.extra.VOICE_KEYPHRASE_LOCALE";

    private KeyphraseInfo[] mKeyphrases;
    private KeyphraseMetadata[] mKeyphrases;
    private String mEnrollmentPackage;
    private String mParseError;

@@ -156,8 +165,8 @@ public class KeyphraseEnrollmentInfo {
                        && !searchKeyphraseSupportedLocales.isEmpty()) {
                    supportedLocales = searchKeyphraseSupportedLocales.split(",");
                }
                mKeyphrases = new KeyphraseInfo[1];
                mKeyphrases[0] = new KeyphraseInfo(
                mKeyphrases = new KeyphraseMetadata[1];
                mKeyphrases[0] = new KeyphraseMetadata(
                        searchKeyphraseId, searchKeyphrase, supportedLocales);
            } else {
                mParseError = "searchKeyphraseId not specified in meta-data";
@@ -188,7 +197,7 @@ public class KeyphraseEnrollmentInfo {
     * @return An array of available keyphrases that can be enrolled on the system.
     *         It may be null if no keyphrases can be enrolled.
     */
    public KeyphraseInfo[] getKeyphrases() {
    public KeyphraseMetadata[] listKeyphraseMetadata() {
        return mKeyphrases;
    }

@@ -196,51 +205,56 @@ public class KeyphraseEnrollmentInfo {
     * Returns an intent to launch an activity that manages the given keyphrase
     * for the locale.
     *
     * @param enroll Indicates if the intent should enroll the user or un-enroll them.
     * @param action The enrollment related action that this intent is supposed to perform.
     *        This can be one of {@link AlwaysOnHotwordDetector#MANAGE_ACTION_ENROLL},
     *        {@link AlwaysOnHotwordDetector#MANAGE_ACTION_RE_ENROLL}
     *        or {@link AlwaysOnHotwordDetector#MANAGE_ACTION_UN_ENROLL}
     * @param keyphrase The keyphrase that the user needs to be enrolled to.
     * @param locale The locale for which the enrollment needs to be performed.
     *        This is a Java locale, for example "en_US".
     * @return An {@link Intent} to manage the keyphrase. This can be null if managing the
     *         given keyphrase/locale combination isn't possible.
     */
    public Intent getManageKeyphraseIntent(boolean enroll, String keyphrase, String locale) {
    public Intent getManageKeyphraseIntent(int action, String keyphrase, String locale) {
        if (mEnrollmentPackage == null || mEnrollmentPackage.isEmpty()) {
            Slog.w(TAG, "No enrollment application exists");
            return null;
        }

        if (isKeyphraseEnrollmentSupported(keyphrase, locale)) {
        if (getKeyphraseMetadata(keyphrase, locale) != null) {
            Intent intent = new Intent(ACTION_MANAGE_VOICE_KEYPHRASES)
                    .setPackage(mEnrollmentPackage)
                    .putExtra(EXTRA_VOICE_KEYPHRASE_HINT_TEXT, keyphrase)
                    .putExtra(EXTRA_VOICE_KEYPHRASE_LOCALE, locale);
            if (!enroll) intent.putExtra(EXTRA_VOICE_KEYPHRASE_UNENROLL, true);
                    .putExtra(EXTRA_VOICE_KEYPHRASE_LOCALE, locale)
                    .putExtra(EXTRA_VOICE_KEYPHRASE_ACTION, action);
            return intent;
        }
        return null;
    }

    /**
     * Indicates if enrollment is supported for the given keyphrase & locale.
     * Gets the {@link KeyphraseMetadata} for the given keyphrase and locale, null if any metadata
     * isn't available for the given combination.
     *
     * @param keyphrase The keyphrase that the user needs to be enrolled to.
     * @param locale The locale for which the enrollment needs to be performed.
     *        This is a Java locale, for example "en_US".
     * @return true, if an enrollment client supports the given keyphrase and the given locale.
     */
    public boolean isKeyphraseEnrollmentSupported(String keyphrase, String locale) {
    public KeyphraseMetadata getKeyphraseMetadata(String keyphrase, String locale) {
        if (mKeyphrases == null || mKeyphrases.length == 0) {
            Slog.w(TAG, "Enrollment application doesn't support keyphrases");
            return false;
            return null;
        }
        for (KeyphraseInfo keyphraseInfo : mKeyphrases) {
        for (KeyphraseMetadata keyphraseMetadata : mKeyphrases) {
            // Check if the given keyphrase is supported in the locale provided by
            // the enrollment application.
            String supportedKeyphrase = keyphraseInfo.keyphrase;
            if (supportedKeyphrase.equalsIgnoreCase(keyphrase)
                    && keyphraseInfo.supportedLocales.contains(locale)) {
                return true;
            if (keyphraseMetadata.supportsPhrase(keyphrase)
                    && keyphraseMetadata.supportsLocale(locale)) {
                return keyphraseMetadata;
            }
        }
        Slog.w(TAG, "Enrollment application doesn't support the given keyphrase");
        return false;
        Slog.w(TAG, "Enrollment application doesn't support the given keyphrase/locale");
        return null;
    }
}
Loading