am b05b4086: Merge "Add permission checks and unhide the Hotword recognition APIs" into klp-dev
* commit 'b05b408614767fb60295830d6bf557b33252498e': Add permission checks and unhide the Hotword recognition APIs
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.speech.hotword;
|
package android.speech.hotword;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
@@ -47,9 +46,10 @@ public interface HotwordRecognitionListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called back when hotword is detected.
|
* 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.
|
* Called when the HotwordRecognitionService encounters an error.
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import android.annotation.SdkConstant.SdkConstantType;
|
|||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.IBinder;
|
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 provides a base class for hotword detection service implementations.
|
||||||
* This class should be extended only if you wish to implement a new hotword recognizer.
|
* This class should be extended only if you wish to implement a new hotword recognizer.
|
||||||
* {@hide}
|
|
||||||
*/
|
*/
|
||||||
public abstract class HotwordRecognitionService extends Service {
|
public abstract class HotwordRecognitionService extends Service {
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +45,7 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
private static final String TAG = "HotwordRecognitionService";
|
private static final String TAG = "HotwordRecognitionService";
|
||||||
|
|
||||||
/** Debugging flag */
|
/** Debugging flag */
|
||||||
// TODO: Turn off.
|
private static final boolean DBG = false;
|
||||||
private static final boolean DBG = true;
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -160,7 +159,7 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
|
|
||||||
public void startHotwordRecognition(IHotwordRecognitionListener listener) {
|
public void startHotwordRecognition(IHotwordRecognitionListener listener) {
|
||||||
if (DBG) Log.d(TAG, "startRecognition called by: " + listener.asBinder());
|
if (DBG) Log.d(TAG, "startRecognition called by: " + listener.asBinder());
|
||||||
if (mInternalService != null) {
|
if (mInternalService != null && mInternalService.checkPermissions(listener)) {
|
||||||
mInternalService.mHandler.sendMessage(
|
mInternalService.mHandler.sendMessage(
|
||||||
Message.obtain(mInternalService.mHandler, MSG_START_RECOGNITION, listener));
|
Message.obtain(mInternalService.mHandler, MSG_START_RECOGNITION, listener));
|
||||||
}
|
}
|
||||||
@@ -168,7 +167,7 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
|
|
||||||
public void stopHotwordRecognition(IHotwordRecognitionListener listener) {
|
public void stopHotwordRecognition(IHotwordRecognitionListener listener) {
|
||||||
if (DBG) Log.d(TAG, "stopRecognition called by: " + listener.asBinder());
|
if (DBG) Log.d(TAG, "stopRecognition called by: " + listener.asBinder());
|
||||||
if (mInternalService != null) {
|
if (mInternalService != null && mInternalService.checkPermissions(listener)) {
|
||||||
mInternalService.mHandler.sendMessage(
|
mInternalService.mHandler.sendMessage(
|
||||||
Message.obtain(mInternalService.mHandler, MSG_STOP_RECOGNITION, listener));
|
Message.obtain(mInternalService.mHandler, MSG_STOP_RECOGNITION, listener));
|
||||||
}
|
}
|
||||||
@@ -179,6 +178,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
|
* This class acts passes on the callbacks received from the Hotword service
|
||||||
* to the listener.
|
* to the listener.
|
||||||
@@ -216,10 +236,11 @@ public abstract class HotwordRecognitionService extends Service {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called back when hotword is detected.
|
* 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 {
|
public void onHotwordRecognized(Intent activityIntent) throws RemoteException {
|
||||||
mListener.onHotwordRecognized(intent);
|
mListener.onHotwordRecognized(activityIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -45,8 +45,7 @@ import java.util.Queue;
|
|||||||
*/
|
*/
|
||||||
public class HotwordRecognizer {
|
public class HotwordRecognizer {
|
||||||
/** DEBUG value to enable verbose debug prints */
|
/** DEBUG value to enable verbose debug prints */
|
||||||
// TODO: Turn off.
|
private final static boolean DBG = false;
|
||||||
private final static boolean DBG = true;
|
|
||||||
|
|
||||||
/** Log messages identifier */
|
/** Log messages identifier */
|
||||||
private static final String TAG = "HotwordRecognizer";
|
private static final String TAG = "HotwordRecognizer";
|
||||||
@@ -81,6 +80,9 @@ public class HotwordRecognizer {
|
|||||||
/** The service received concurrent start calls */
|
/** The service received concurrent start calls */
|
||||||
public static final int ERROR_SERVICE_ALREADY_STARTED = 6;
|
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;
|
||||||
@@ -354,7 +356,7 @@ public class HotwordRecognizer {
|
|||||||
mInternalListener.onHotwordEvent(msg.arg1, (Bundle) msg.obj);
|
mInternalListener.onHotwordEvent(msg.arg1, (Bundle) msg.obj);
|
||||||
break;
|
break;
|
||||||
case MSG_ON_RECOGNIZED:
|
case MSG_ON_RECOGNIZED:
|
||||||
mInternalListener.onHotwordRecognized((PendingIntent) msg.obj);
|
mInternalListener.onHotwordRecognized((Intent) msg.obj);
|
||||||
break;
|
break;
|
||||||
case MSG_ON_ERROR:
|
case MSG_ON_ERROR:
|
||||||
mInternalListener.onHotwordError((Integer) msg.obj);
|
mInternalListener.onHotwordError((Integer) msg.obj);
|
||||||
@@ -380,8 +382,8 @@ public class HotwordRecognizer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHotwordRecognized(PendingIntent intent) throws RemoteException {
|
public void onHotwordRecognized(Intent activityIntent) throws RemoteException {
|
||||||
Message.obtain(mInternalHandler, MSG_ON_RECOGNIZED, intent)
|
Message.obtain(mInternalHandler, MSG_ON_RECOGNIZED, activityIntent)
|
||||||
.sendToTarget();
|
.sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
package android.speech.hotword;
|
package android.speech.hotword;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,9 +47,10 @@ oneway interface IHotwordRecognitionListener {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Called back when hotword is detected.
|
* 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.
|
* Called when the HotwordRecognitionService encounters an error.
|
||||||
|
|||||||
@@ -2444,6 +2444,13 @@
|
|||||||
android:description="@string/permdesc_accessNetworkConditions"
|
android:description="@string/permdesc_accessNetworkConditions"
|
||||||
android:protectionLevel="signature|system" />
|
android:protectionLevel="signature|system" />
|
||||||
|
|
||||||
|
<!-- Allows an application to request HotwordRecognition.
|
||||||
|
@hide This is not a third-party API (intended for system apps). -->
|
||||||
|
<permission android:name="android.permission.HOTWORD_RECOGNITION"
|
||||||
|
android:label="@string/permlab_hotwordRecognition"
|
||||||
|
android:description="@string/permdesc_hotwordRecognition"
|
||||||
|
android:protectionLevel="signature|system" />
|
||||||
|
|
||||||
<!-- The system process is explicitly the only one allowed to launch the
|
<!-- The system process is explicitly the only one allowed to launch the
|
||||||
confirmation UI for full backup/restore -->
|
confirmation UI for full backup/restore -->
|
||||||
<uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/>
|
<uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/>
|
||||||
|
|||||||
@@ -1911,6 +1911,11 @@
|
|||||||
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
<string name="permdesc_accessNetworkConditions">Allows an application to listen for observations on network conditions. Should never be needed for normal apps.</string>
|
<string name="permdesc_accessNetworkConditions">Allows an application to listen for observations on network conditions. Should never be needed for normal apps.</string>
|
||||||
|
|
||||||
|
<!-- Title of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permlab_hotwordRecognition">request hotword recognition</string>
|
||||||
|
<!-- Description of an application permission, listed so the user can choose whether they want to allow the application to do this. -->
|
||||||
|
<string name="permdesc_hotwordRecognition">Allows an application to request for hotword recognition. Should never be needed for normal apps.</string>
|
||||||
|
|
||||||
<!-- Policy administration -->
|
<!-- Policy administration -->
|
||||||
|
|
||||||
<!-- Title of policy access to limiting the user's password choices -->
|
<!-- Title of policy access to limiting the user's password choices -->
|
||||||
|
|||||||
Reference in New Issue
Block a user