summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/speech/hotword/HotwordRecognitionListener.java6
-rw-r--r--core/java/android/speech/hotword/HotwordRecognitionService.java37
-rw-r--r--core/java/android/speech/hotword/HotwordRecognizer.java12
-rw-r--r--core/java/android/speech/hotword/IHotwordRecognitionListener.aidl7
4 files changed, 43 insertions, 19 deletions
diff --git a/core/java/android/speech/hotword/HotwordRecognitionListener.java b/core/java/android/speech/hotword/HotwordRecognitionListener.java
index 8e62373d65ca..8a32654c5bac 100644
--- a/core/java/android/speech/hotword/HotwordRecognitionListener.java
+++ b/core/java/android/speech/hotword/HotwordRecognitionListener.java
@@ -16,7 +16,6 @@
package android.speech.hotword;
-import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
@@ -47,9 +46,10 @@ public interface HotwordRecognitionListener {
/**
* Called back when hotword is detected.
- * The action tells the client what action to take, post hotword-detection.
+ *
+ * @param intent for the activity to launch, post hotword detection.
*/
- void onHotwordRecognized(PendingIntent intent);
+ void onHotwordRecognized(Intent intent);
/**
* Called when the HotwordRecognitionService encounters an error.
diff --git a/core/java/android/speech/hotword/HotwordRecognitionService.java b/core/java/android/speech/hotword/HotwordRecognitionService.java
index 521d06d8abb4..c70bdab640f1 100644
--- a/core/java/android/speech/hotword/HotwordRecognitionService.java
+++ b/core/java/android/speech/hotword/HotwordRecognitionService.java
@@ -21,6 +21,7 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
+import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
@@ -31,7 +32,6 @@ import android.util.Log;
/**
* This class provides a base class for hotword detection service implementations.
* This class should be extended only if you wish to implement a new hotword recognizer.
- * {@hide}
*/
public abstract class HotwordRecognitionService extends Service {
/**
@@ -45,8 +45,7 @@ public abstract class HotwordRecognitionService extends Service {
private static final String TAG = "HotwordRecognitionService";
/** Debugging flag */
- // TODO: Turn off.
- private static final boolean DBG = true;
+ private static final boolean DBG = false;
private static final int MSG_START_RECOGNITION = 1;
private static final int MSG_STOP_RECOGNITION = 2;
@@ -160,7 +159,7 @@ public abstract class HotwordRecognitionService extends Service {
public void startHotwordRecognition(IHotwordRecognitionListener listener) {
if (DBG) Log.d(TAG, "startRecognition called by: " + listener.asBinder());
- if (mInternalService != null) {
+ if (mInternalService != null && mInternalService.checkPermissions(listener)) {
mInternalService.mHandler.sendMessage(
Message.obtain(mInternalService.mHandler, MSG_START_RECOGNITION, listener));
}
@@ -168,7 +167,7 @@ public abstract class HotwordRecognitionService extends Service {
public void stopHotwordRecognition(IHotwordRecognitionListener listener) {
if (DBG) Log.d(TAG, "stopRecognition called by: " + listener.asBinder());
- if (mInternalService != null) {
+ if (mInternalService != null && mInternalService.checkPermissions(listener)) {
mInternalService.mHandler.sendMessage(
Message.obtain(mInternalService.mHandler, MSG_STOP_RECOGNITION, listener));
}
@@ -180,6 +179,27 @@ public abstract class HotwordRecognitionService extends Service {
}
/**
+ * Checks whether the caller has sufficient permissions
+ *
+ * @param listener to send the error message to in case of error.
+ * @return {@code true} if the caller has enough permissions, {@code false} otherwise.
+ */
+ private boolean checkPermissions(IHotwordRecognitionListener listener) {
+ if (DBG) Log.d(TAG, "checkPermissions");
+ if (checkCallingOrSelfPermission(android.Manifest.permission.HOTWORD_RECOGNITION) ==
+ PackageManager.PERMISSION_GRANTED) {
+ return true;
+ }
+ try {
+ Log.e(TAG, "Recognition service called without HOTWORD_RECOGNITION permissions");
+ listener.onHotwordError(HotwordRecognizer.ERROR_FAILED);
+ } catch (RemoteException e) {
+ Log.e(TAG, "onHotwordError(ERROR_FAILED) message failed", e);
+ }
+ return false;
+ }
+
+ /**
* This class acts passes on the callbacks received from the Hotword service
* to the listener.
*/
@@ -216,10 +236,11 @@ public abstract class HotwordRecognitionService extends Service {
/**
* Called back when hotword is detected.
- * The action tells the client what action to take, post hotword-detection.
+ *
+ * @param intent for the activity to launch, post hotword detection.
*/
- public void onHotwordRecognized(PendingIntent intent) throws RemoteException {
- mListener.onHotwordRecognized(intent);
+ public void onHotwordRecognized(Intent activityIntent) throws RemoteException {
+ mListener.onHotwordRecognized(activityIntent);
}
/**
diff --git a/core/java/android/speech/hotword/HotwordRecognizer.java b/core/java/android/speech/hotword/HotwordRecognizer.java
index 82cec1017833..939c11d7792f 100644
--- a/core/java/android/speech/hotword/HotwordRecognizer.java
+++ b/core/java/android/speech/hotword/HotwordRecognizer.java
@@ -45,8 +45,7 @@ import java.util.Queue;
*/
public class HotwordRecognizer {
/** DEBUG value to enable verbose debug prints */
- // TODO: Turn off.
- private final static boolean DBG = true;
+ private final static boolean DBG = false;
/** Log messages identifier */
private static final String TAG = "HotwordRecognizer";
@@ -81,6 +80,9 @@ public class HotwordRecognizer {
/** 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 */
private static final int MSG_START = 1;
private static final int MSG_STOP = 2;
@@ -354,7 +356,7 @@ public class HotwordRecognizer {
mInternalListener.onHotwordEvent(msg.arg1, (Bundle) msg.obj);
break;
case MSG_ON_RECOGNIZED:
- mInternalListener.onHotwordRecognized((PendingIntent) msg.obj);
+ mInternalListener.onHotwordRecognized((Intent) msg.obj);
break;
case MSG_ON_ERROR:
mInternalListener.onHotwordError((Integer) msg.obj);
@@ -380,8 +382,8 @@ public class HotwordRecognizer {
}
@Override
- public void onHotwordRecognized(PendingIntent intent) throws RemoteException {
- Message.obtain(mInternalHandler, MSG_ON_RECOGNIZED, intent)
+ public void onHotwordRecognized(Intent activityIntent) throws RemoteException {
+ Message.obtain(mInternalHandler, MSG_ON_RECOGNIZED, activityIntent)
.sendToTarget();
}
diff --git a/core/java/android/speech/hotword/IHotwordRecognitionListener.aidl b/core/java/android/speech/hotword/IHotwordRecognitionListener.aidl
index 49c523328296..4ea2e8e0ecfa 100644
--- a/core/java/android/speech/hotword/IHotwordRecognitionListener.aidl
+++ b/core/java/android/speech/hotword/IHotwordRecognitionListener.aidl
@@ -16,7 +16,7 @@
package android.speech.hotword;
-import android.app.PendingIntent;
+import android.content.Intent;
import android.os.Bundle;
/**
@@ -47,9 +47,10 @@ oneway interface IHotwordRecognitionListener {
/**
* Called back when hotword is detected.
- * The action tells the client what action to take, post hotword-detection.
+ *
+ * @param intent for the activity to launch, post hotword detection.
*/
- void onHotwordRecognized(in PendingIntent intent);
+ void onHotwordRecognized(in Intent intent);
/**
* Called when the HotwordRecognitionService encounters an error.