Loading core/api/test-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -2396,6 +2396,7 @@ package android.service.watchdog { package android.speech { public class SpeechRecognizer { method @MainThread @NonNull public static android.speech.SpeechRecognizer createOnDeviceTestingSpeechRecognizer(@NonNull android.content.Context); method @RequiresPermission(android.Manifest.permission.MANAGE_SPEECH_RECOGNITION) public void setTemporaryOnDeviceRecognizer(@Nullable android.content.ComponentName); } Loading core/java/android/speech/SpeechRecognizer.java +27 −22 Original line number Diff line number Diff line Loading @@ -260,23 +260,7 @@ public class SpeechRecognizer { ComponentName componentName = ComponentName.unflattenFromString( context.getString(R.string.config_defaultOnDeviceSpeechRecognitionService)); if (componentName == null) { return false; } List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices( new Intent(RecognitionService.SERVICE_INTERFACE), 0); if (resolveInfos == null) { return false; } for (ResolveInfo ri : resolveInfos) { if (ri.serviceInfo != null && componentName.equals(ri.serviceInfo.getComponentName())) { return true; } } return false; return componentName != null; } /** Loading Loading @@ -354,20 +338,41 @@ public class SpeechRecognizer { * notifications will be received. * * @param context in which to create {@code SpeechRecognizer} * @return a new on-device {@code SpeechRecognizer}. * @throws UnsupportedOperationException iff {@link #isOnDeviceRecognitionAvailable(Context)} * is false * @return a new on-device {@code SpeechRecognizer}. */ @NonNull @MainThread public static SpeechRecognizer createOnDeviceSpeechRecognizer(@NonNull final Context context) { if (!isOnDeviceRecognitionAvailable(context)) { throw new UnsupportedOperationException("On-device recognition is not available"); } return lenientlyCreateOnDeviceSpeechRecognizer(context); } /** * Helper method to create on-device SpeechRecognizer in tests even when the device does not * support on-device speech recognition. * * @hide */ @TestApi @NonNull @MainThread public static SpeechRecognizer createOnDeviceTestingSpeechRecognizer( @NonNull final Context context) { return lenientlyCreateOnDeviceSpeechRecognizer(context); } @NonNull @MainThread private static SpeechRecognizer lenientlyCreateOnDeviceSpeechRecognizer( @NonNull final Context context) { if (context == null) { throw new IllegalArgumentException("Context cannot be null"); } checkIsCalledFromMainThread(); if (!isOnDeviceRecognitionAvailable(context)) { throw new UnsupportedOperationException("On-device recognition is not available"); } return new SpeechRecognizer(context, /* onDevice */ true); } Loading Loading
core/api/test-current.txt +1 −0 Original line number Diff line number Diff line Loading @@ -2396,6 +2396,7 @@ package android.service.watchdog { package android.speech { public class SpeechRecognizer { method @MainThread @NonNull public static android.speech.SpeechRecognizer createOnDeviceTestingSpeechRecognizer(@NonNull android.content.Context); method @RequiresPermission(android.Manifest.permission.MANAGE_SPEECH_RECOGNITION) public void setTemporaryOnDeviceRecognizer(@Nullable android.content.ComponentName); } Loading
core/java/android/speech/SpeechRecognizer.java +27 −22 Original line number Diff line number Diff line Loading @@ -260,23 +260,7 @@ public class SpeechRecognizer { ComponentName componentName = ComponentName.unflattenFromString( context.getString(R.string.config_defaultOnDeviceSpeechRecognitionService)); if (componentName == null) { return false; } List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices( new Intent(RecognitionService.SERVICE_INTERFACE), 0); if (resolveInfos == null) { return false; } for (ResolveInfo ri : resolveInfos) { if (ri.serviceInfo != null && componentName.equals(ri.serviceInfo.getComponentName())) { return true; } } return false; return componentName != null; } /** Loading Loading @@ -354,20 +338,41 @@ public class SpeechRecognizer { * notifications will be received. * * @param context in which to create {@code SpeechRecognizer} * @return a new on-device {@code SpeechRecognizer}. * @throws UnsupportedOperationException iff {@link #isOnDeviceRecognitionAvailable(Context)} * is false * @return a new on-device {@code SpeechRecognizer}. */ @NonNull @MainThread public static SpeechRecognizer createOnDeviceSpeechRecognizer(@NonNull final Context context) { if (!isOnDeviceRecognitionAvailable(context)) { throw new UnsupportedOperationException("On-device recognition is not available"); } return lenientlyCreateOnDeviceSpeechRecognizer(context); } /** * Helper method to create on-device SpeechRecognizer in tests even when the device does not * support on-device speech recognition. * * @hide */ @TestApi @NonNull @MainThread public static SpeechRecognizer createOnDeviceTestingSpeechRecognizer( @NonNull final Context context) { return lenientlyCreateOnDeviceSpeechRecognizer(context); } @NonNull @MainThread private static SpeechRecognizer lenientlyCreateOnDeviceSpeechRecognizer( @NonNull final Context context) { if (context == null) { throw new IllegalArgumentException("Context cannot be null"); } checkIsCalledFromMainThread(); if (!isOnDeviceRecognitionAvailable(context)) { throw new UnsupportedOperationException("On-device recognition is not available"); } return new SpeechRecognizer(context, /* onDevice */ true); } Loading