Loading core/java/android/speech/hotword/HotwordRecognitionListener.java +3 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package android.speech.hotword; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; Loading Loading @@ -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. Loading core/java/android/speech/hotword/HotwordRecognitionService.java +29 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { /** Loading @@ -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; Loading Loading @@ -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)); } Loading @@ -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)); } Loading @@ -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 * to the listener. Loading Loading @@ -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); } /** Loading core/java/android/speech/hotword/HotwordRecognizer.java +7 −5 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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(); } Loading core/java/android/speech/hotword/IHotwordRecognitionListener.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package android.speech.hotword; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; /** Loading Loading @@ -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. Loading core/res/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -2444,6 +2444,13 @@ android:description="@string/permdesc_accessNetworkConditions" 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 confirmation UI for full backup/restore --> <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/> Loading Loading
core/java/android/speech/hotword/HotwordRecognitionListener.java +3 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package android.speech.hotword; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; Loading Loading @@ -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. Loading
core/java/android/speech/hotword/HotwordRecognitionService.java +29 −8 Original line number Diff line number Diff line Loading @@ -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; Loading @@ -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 { /** Loading @@ -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; Loading Loading @@ -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)); } Loading @@ -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)); } Loading @@ -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 * to the listener. Loading Loading @@ -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); } /** Loading
core/java/android/speech/hotword/HotwordRecognizer.java +7 −5 Original line number Diff line number Diff line Loading @@ -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"; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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(); } Loading
core/java/android/speech/hotword/IHotwordRecognitionListener.aidl +4 −3 Original line number Diff line number Diff line Loading @@ -16,7 +16,7 @@ package android.speech.hotword; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; /** Loading Loading @@ -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. Loading
core/res/AndroidManifest.xml +7 −0 Original line number Diff line number Diff line Loading @@ -2444,6 +2444,13 @@ android:description="@string/permdesc_accessNetworkConditions" 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 confirmation UI for full backup/restore --> <uses-permission android:name="android.permission.CONFIRM_FULL_BACKUP"/> Loading