am 85e7177a: Merge "Move public consts to HotwordRecognitionService" into klp-dev
* commit '85e7177abe3024218de589a94bc0914bcfe51547': Move public consts to HotwordRecognitionService
This commit is contained in:
@@ -22819,6 +22819,15 @@ package android.speech.hotword {
|
|||||||
method public android.os.IBinder onBind(android.content.Intent);
|
method public android.os.IBinder onBind(android.content.Intent);
|
||||||
method public abstract void onStartHotwordRecognition(android.speech.hotword.HotwordRecognitionService.Callback);
|
method public abstract void onStartHotwordRecognition(android.speech.hotword.HotwordRecognitionService.Callback);
|
||||||
method public abstract void onStopHotwordRecognition();
|
method public abstract void onStopHotwordRecognition();
|
||||||
|
field public static final int ERROR_AUDIO = 1; // 0x1
|
||||||
|
field public static final int ERROR_CLIENT = 4; // 0x4
|
||||||
|
field public static final int ERROR_FAILED = 3; // 0x3
|
||||||
|
field public static final int ERROR_RECOGNIZER_BUSY = 2; // 0x2
|
||||||
|
field public static final int ERROR_SERVICE_ALREADY_STARTED = 6; // 0x6
|
||||||
|
field public static final int ERROR_TIMEOUT = 5; // 0x5
|
||||||
|
field public static final int ERROR_UNAVAILABLE = 7; // 0x7
|
||||||
|
field public static final int EVENT_TYPE_PROMPT_CHANGED = 1; // 0x1
|
||||||
|
field public static final java.lang.String KEY_PROMPT_TEXT = "prompt_text";
|
||||||
field public static final java.lang.String SERVICE_INTERFACE = "android.speech.hotword.HotwordRecognitionService";
|
field public static final java.lang.String SERVICE_INTERFACE = "android.speech.hotword.HotwordRecognitionService";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -47,6 +47,39 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
/** Debugging flag */
|
/** Debugging flag */
|
||||||
private static final boolean DBG = false;
|
private static final boolean DBG = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key used to retrieve a string to be displayed to the user passed to the
|
||||||
|
* {@link android.speech.hotword.HotwordRecognitionListener#onHotwordEvent(int, Bundle)} method.
|
||||||
|
*/
|
||||||
|
public static final String KEY_PROMPT_TEXT = "prompt_text";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event type used to indicate to the user that the prompt for
|
||||||
|
* hotword recognition has changed.
|
||||||
|
*/
|
||||||
|
public static final int EVENT_TYPE_PROMPT_CHANGED = 1;
|
||||||
|
|
||||||
|
/** Audio recording error. */
|
||||||
|
public static final int ERROR_AUDIO = 1;
|
||||||
|
|
||||||
|
/** RecognitionService busy. */
|
||||||
|
public static final int ERROR_RECOGNIZER_BUSY = 2;
|
||||||
|
|
||||||
|
/** This indicates a permanent failure and the clients shouldn't retry on this */
|
||||||
|
public static final int ERROR_FAILED = 3;
|
||||||
|
|
||||||
|
/** Client-side errors */
|
||||||
|
public static final int ERROR_CLIENT = 4;
|
||||||
|
|
||||||
|
/** The service timed out */
|
||||||
|
public static final int ERROR_TIMEOUT = 5;
|
||||||
|
|
||||||
|
/** The service received concurrent start calls */
|
||||||
|
public static final int ERROR_SERVICE_ALREADY_STARTED = 6;
|
||||||
|
|
||||||
|
/** Hotword recognition is unavailable on the device */
|
||||||
|
public static final int ERROR_UNAVAILABLE = 7;
|
||||||
|
|
||||||
private static final int MSG_START_RECOGNITION = 1;
|
private static final int MSG_START_RECOGNITION = 1;
|
||||||
private static final int MSG_STOP_RECOGNITION = 2;
|
private static final int MSG_STOP_RECOGNITION = 2;
|
||||||
|
|
||||||
@@ -94,7 +127,7 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
HotwordRecognitionService.this.onStartHotwordRecognition(mCurrentCallback);
|
HotwordRecognitionService.this.onStartHotwordRecognition(mCurrentCallback);
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
listener.onHotwordError(HotwordRecognizer.ERROR_RECOGNIZER_BUSY);
|
listener.onHotwordError(ERROR_RECOGNIZER_BUSY);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
if (DBG) Log.d(TAG, "onError call from startRecognition failed");
|
if (DBG) Log.d(TAG, "onError call from startRecognition failed");
|
||||||
}
|
}
|
||||||
@@ -105,10 +138,10 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
private void dispatchStopRecognition(IHotwordRecognitionListener listener) {
|
private void dispatchStopRecognition(IHotwordRecognitionListener listener) {
|
||||||
try {
|
try {
|
||||||
if (mCurrentCallback == null) {
|
if (mCurrentCallback == null) {
|
||||||
listener.onHotwordError(HotwordRecognizer.ERROR_CLIENT);
|
listener.onHotwordError(ERROR_CLIENT);
|
||||||
Log.w(TAG, "stopRecognition called with no preceding startRecognition - ignoring");
|
Log.w(TAG, "stopRecognition called with no preceding startRecognition - ignoring");
|
||||||
} else if (mCurrentCallback.mListener.asBinder() != listener.asBinder()) {
|
} else if (mCurrentCallback.mListener.asBinder() != listener.asBinder()) {
|
||||||
listener.onHotwordError(HotwordRecognizer.ERROR_RECOGNIZER_BUSY);
|
listener.onHotwordError(ERROR_RECOGNIZER_BUSY);
|
||||||
Log.w(TAG, "stopRecognition called by a different caller - ignoring");
|
Log.w(TAG, "stopRecognition called by a different caller - ignoring");
|
||||||
} else { // the correct state
|
} else { // the correct state
|
||||||
mCurrentCallback.onHotwordRecognitionStopped();
|
mCurrentCallback.onHotwordRecognitionStopped();
|
||||||
@@ -192,7 +225,7 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Log.e(TAG, "Recognition service called without HOTWORD_RECOGNITION permissions");
|
Log.e(TAG, "Recognition service called without HOTWORD_RECOGNITION permissions");
|
||||||
listener.onHotwordError(HotwordRecognizer.ERROR_FAILED);
|
listener.onHotwordError(ERROR_FAILED);
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Log.e(TAG, "onHotwordError(ERROR_FAILED) message failed", e);
|
Log.e(TAG, "onHotwordError(ERROR_FAILED) message failed", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,39 +50,6 @@ public class HotwordRecognizer {
|
|||||||
/** Log messages identifier */
|
/** Log messages identifier */
|
||||||
private static final String TAG = "HotwordRecognizer";
|
private static final String TAG = "HotwordRecognizer";
|
||||||
|
|
||||||
/**
|
|
||||||
* Key used to retrieve a string to be displayed to the user passed to the
|
|
||||||
* {@link android.speech.hotword.HotwordRecognitionListener#onHotwordEvent(int, Bundle)} method.
|
|
||||||
*/
|
|
||||||
public static final String PROMPT_TEXT = "prompt_text";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Event type used to indicate to the user that the hotword service has changed
|
|
||||||
* its state.
|
|
||||||
*/
|
|
||||||
public static final int EVENT_TYPE_STATE_CHANGED = 1;
|
|
||||||
|
|
||||||
/** Audio recording error. */
|
|
||||||
public static final int ERROR_AUDIO = 1;
|
|
||||||
|
|
||||||
/** RecognitionService busy. */
|
|
||||||
public static final int ERROR_RECOGNIZER_BUSY = 2;
|
|
||||||
|
|
||||||
/** This indicates a permanent failure and the clients shouldn't retry on this */
|
|
||||||
public static final int ERROR_FAILED = 3;
|
|
||||||
|
|
||||||
/** Client-side errors */
|
|
||||||
public static final int ERROR_CLIENT = 4;
|
|
||||||
|
|
||||||
/** The service timed out */
|
|
||||||
public static final int ERROR_TIMEOUT = 5;
|
|
||||||
|
|
||||||
/** The service received concurrent start calls */
|
|
||||||
public static final int ERROR_SERVICE_ALREADY_STARTED = 6;
|
|
||||||
|
|
||||||
/** Hotword recognition is unavailable on the device */
|
|
||||||
public static final int ERROR_UNAVAILABLE = 7;
|
|
||||||
|
|
||||||
/** action codes */
|
/** action codes */
|
||||||
private static final int MSG_START = 1;
|
private static final int MSG_START = 1;
|
||||||
private static final int MSG_STOP = 2;
|
private static final int MSG_STOP = 2;
|
||||||
@@ -209,7 +176,7 @@ public class HotwordRecognizer {
|
|||||||
|
|
||||||
if (mServiceComponent == null) {
|
if (mServiceComponent == null) {
|
||||||
Log.e(TAG, "no selected voice recognition service");
|
Log.e(TAG, "no selected voice recognition service");
|
||||||
mListener.onHotwordError(ERROR_CLIENT);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_CLIENT);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
serviceIntent.setComponent(mServiceComponent);
|
serviceIntent.setComponent(mServiceComponent);
|
||||||
@@ -219,12 +186,12 @@ public class HotwordRecognizer {
|
|||||||
Log.e(TAG, "bind to recognition service failed");
|
Log.e(TAG, "bind to recognition service failed");
|
||||||
mConnection = null;
|
mConnection = null;
|
||||||
mService = null;
|
mService = null;
|
||||||
mListener.onHotwordError(ERROR_CLIENT);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_CLIENT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
putMessage(Message.obtain(mHandler, MSG_START));
|
putMessage(Message.obtain(mHandler, MSG_START));
|
||||||
} else {
|
} else {
|
||||||
mListener.onHotwordError(ERROR_SERVICE_ALREADY_STARTED);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_SERVICE_ALREADY_STARTED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,7 +219,7 @@ public class HotwordRecognizer {
|
|||||||
if (DBG) Log.d(TAG, "service startRecognition command succeeded");
|
if (DBG) Log.d(TAG, "service startRecognition command succeeded");
|
||||||
} catch (final RemoteException e) {
|
} catch (final RemoteException e) {
|
||||||
Log.e(TAG, "startRecognition() failed", e);
|
Log.e(TAG, "startRecognition() failed", e);
|
||||||
mListener.onHotwordError(ERROR_CLIENT);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_CLIENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +235,7 @@ public class HotwordRecognizer {
|
|||||||
if (DBG) Log.d(TAG, "service stopRecognition command succeeded");
|
if (DBG) Log.d(TAG, "service stopRecognition command succeeded");
|
||||||
} catch (final RemoteException e) {
|
} catch (final RemoteException e) {
|
||||||
Log.e(TAG, "stopRecognition() failed", e);
|
Log.e(TAG, "stopRecognition() failed", e);
|
||||||
mListener.onHotwordError(ERROR_CLIENT);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_CLIENT);
|
||||||
} finally {
|
} finally {
|
||||||
mPendingTasks.clear();
|
mPendingTasks.clear();
|
||||||
mService = null;
|
mService = null;
|
||||||
@@ -281,7 +248,7 @@ public class HotwordRecognizer {
|
|||||||
if (mService != null) {
|
if (mService != null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mListener.onHotwordError(ERROR_CLIENT);
|
mListener.onHotwordError(HotwordRecognitionService.ERROR_CLIENT);
|
||||||
Log.e(TAG, "not connected to the recognition service");
|
Log.e(TAG, "not connected to the recognition service");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ import android.os.UserHandle;
|
|||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.speech.hotword.HotwordRecognitionListener;
|
import android.speech.hotword.HotwordRecognitionListener;
|
||||||
|
import android.speech.hotword.HotwordRecognitionService;
|
||||||
import android.speech.hotword.HotwordRecognizer;
|
import android.speech.hotword.HotwordRecognizer;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
@@ -1775,11 +1776,13 @@ public class KeyguardHostView extends KeyguardViewBase {
|
|||||||
|
|
||||||
public void onHotwordEvent(int eventType, Bundle eventBundle) {
|
public void onHotwordEvent(int eventType, Bundle eventBundle) {
|
||||||
if (DEBUG) Log.d(TAG, "onHotwordEvent: " + eventType);
|
if (DEBUG) Log.d(TAG, "onHotwordEvent: " + eventType);
|
||||||
if (eventType == HotwordRecognizer.EVENT_TYPE_STATE_CHANGED) {
|
if (eventType == HotwordRecognitionService.EVENT_TYPE_PROMPT_CHANGED) {
|
||||||
if (eventBundle != null && eventBundle.containsKey(HotwordRecognizer.PROMPT_TEXT)) {
|
if (eventBundle != null
|
||||||
new KeyguardMessageArea.Helper(
|
&& eventBundle.containsKey(HotwordRecognitionService.KEY_PROMPT_TEXT)) {
|
||||||
(View) getSecurityView(mCurrentSecuritySelection))
|
new KeyguardMessageArea
|
||||||
.setMessage(eventBundle.getString(HotwordRecognizer.PROMPT_TEXT),true);
|
.Helper((View) getSecurityView(mCurrentSecuritySelection))
|
||||||
|
.setMessage(eventBundle.getString(
|
||||||
|
HotwordRecognitionService.KEY_PROMPT_TEXT),true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user