Merge "API review : use a range of numbers for OEM errors" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
c0f1de7c5c
@@ -10539,6 +10539,7 @@ package android.service.voice {
|
||||
|
||||
public abstract class HotwordDetectionService extends android.app.Service {
|
||||
ctor public HotwordDetectionService();
|
||||
method public static int getMaxCustomInitializationStatus();
|
||||
method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
|
||||
method @Deprecated public void onDetect(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, long, @NonNull android.service.voice.HotwordDetectionService.Callback);
|
||||
method public void onDetect(@NonNull android.service.voice.AlwaysOnHotwordDetector.EventPayload, long, @NonNull android.service.voice.HotwordDetectionService.Callback);
|
||||
@@ -10546,8 +10547,6 @@ package android.service.voice {
|
||||
method public void onDetect(@NonNull android.service.voice.HotwordDetectionService.Callback);
|
||||
method public void onDetect(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, @Nullable android.os.PersistableBundle, @NonNull android.service.voice.HotwordDetectionService.Callback);
|
||||
method public void onUpdateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, long, @Nullable java.util.function.IntConsumer);
|
||||
field public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_1 = 1; // 0x1
|
||||
field public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_2 = 2; // 0x2
|
||||
field public static final int INITIALIZATION_STATUS_SUCCESS = 0; // 0x0
|
||||
field public static final int INITIALIZATION_STATUS_UNKNOWN = 100; // 0x64
|
||||
field public static final String SERVICE_INTERFACE = "android.service.voice.HotwordDetectionService";
|
||||
|
||||
@@ -49,7 +49,6 @@ import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.RemoteException;
|
||||
import android.os.SharedMemory;
|
||||
import android.service.voice.HotwordDetectionService.InitializationStatus;
|
||||
import android.util.Log;
|
||||
import android.util.Slog;
|
||||
|
||||
@@ -531,9 +530,12 @@ public class AlwaysOnHotwordDetector extends AbstractHotwordDetector {
|
||||
* Called when the {@link HotwordDetectionService} is created by the system and given a
|
||||
* short amount of time to report it's initialization state.
|
||||
*
|
||||
* @param status Info about initialization state of {@link HotwordDetectionService}.
|
||||
* @param status Info about initialization state of {@link HotwordDetectionService}; the
|
||||
* allowed values are {@link HotwordDetectionService#INITIALIZATION_STATUS_SUCCESS},
|
||||
* 1<->{@link HotwordDetectionService#getMaxCustomInitializationStatus()},
|
||||
* {@link HotwordDetectionService#INITIALIZATION_STATUS_UNKNOWN}.
|
||||
*/
|
||||
public void onHotwordDetectionServiceInitialized(@InitializationStatus int status) {
|
||||
public void onHotwordDetectionServiceInitialized(int status) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,31 +78,18 @@ public abstract class HotwordDetectionService extends Service {
|
||||
/** @hide */
|
||||
public static final String KEY_INITIALIZATION_STATUS = "initialization_status";
|
||||
|
||||
/** @hide */
|
||||
@Retention(RetentionPolicy.SOURCE)
|
||||
@IntDef(flag = true, prefix = { "INITIALIZATION_STATUS_" }, value = {
|
||||
INITIALIZATION_STATUS_SUCCESS,
|
||||
INITIALIZATION_STATUS_CUSTOM_ERROR_1,
|
||||
INITIALIZATION_STATUS_CUSTOM_ERROR_2,
|
||||
INITIALIZATION_STATUS_UNKNOWN,
|
||||
})
|
||||
public @interface InitializationStatus {}
|
||||
/**
|
||||
* The maximum number of initialization status for some application specific failed reasons.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public static final int MAXIMUM_NUMBER_OF_INITIALIZATION_STATUS_CUSTOM_ERROR = 2;
|
||||
|
||||
/**
|
||||
* Indicates that the updated status is successful.
|
||||
*/
|
||||
public static final int INITIALIZATION_STATUS_SUCCESS = 0;
|
||||
|
||||
/**
|
||||
* Indicates that the updated status is failure for some application specific reasons.
|
||||
*/
|
||||
public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_1 = 1;
|
||||
|
||||
/**
|
||||
* Indicates that the updated status is failure for some application specific reasons.
|
||||
*/
|
||||
public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_2 = 2;
|
||||
|
||||
/**
|
||||
* Indicates that the callback wasn’t invoked within the timeout.
|
||||
* This is used by system.
|
||||
@@ -228,6 +215,19 @@ public abstract class HotwordDetectionService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of initialization status for some application specific failed
|
||||
* reasons.
|
||||
*
|
||||
* Note: The value 0 is reserved for success.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@SystemApi
|
||||
public static int getMaxCustomInitializationStatus() {
|
||||
return MAXIMUM_NUMBER_OF_INITIALIZATION_STATUS_CUSTOM_ERROR;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the device hardware (such as a DSP) detected the hotword, to request second stage
|
||||
* validation before handing over the audio to the {@link AlwaysOnHotwordDetector}.
|
||||
@@ -298,9 +298,10 @@ public abstract class HotwordDetectionService extends Service {
|
||||
* such data to the trusted process.
|
||||
* @param callbackTimeoutMillis Timeout in milliseconds for the operation to invoke the
|
||||
* statusCallback.
|
||||
* @param statusCallback Use this to return the updated result. This is non-null only when the
|
||||
* {@link HotwordDetectionService} is being initialized; and it is null if the state is updated
|
||||
* after that.
|
||||
* @param statusCallback Use this to return the updated result; the allowed values are
|
||||
* {@link #INITIALIZATION_STATUS_SUCCESS}, 1<->{@link #getMaxCustomInitializationStatus()}.
|
||||
* This is non-null only when the {@link HotwordDetectionService} is being initialized; and it
|
||||
* is null if the state is updated after that.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@@ -309,7 +310,7 @@ public abstract class HotwordDetectionService extends Service {
|
||||
@Nullable PersistableBundle options,
|
||||
@Nullable SharedMemory sharedMemory,
|
||||
@DurationMillisLong long callbackTimeoutMillis,
|
||||
@Nullable @InitializationStatus IntConsumer statusCallback) {
|
||||
@Nullable IntConsumer statusCallback) {
|
||||
// TODO: Handle the unimplemented case by throwing?
|
||||
}
|
||||
|
||||
@@ -389,6 +390,10 @@ public abstract class HotwordDetectionService extends Service {
|
||||
if (callback != null) {
|
||||
intConsumer =
|
||||
value -> {
|
||||
if (value > getMaxCustomInitializationStatus()) {
|
||||
throw new IllegalArgumentException(
|
||||
"The initialization status is invalid for " + value);
|
||||
}
|
||||
try {
|
||||
Bundle status = new Bundle();
|
||||
status.putInt(KEY_INITIALIZATION_STATUS, value);
|
||||
|
||||
@@ -28,7 +28,6 @@ import android.media.AudioFormat;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SharedMemory;
|
||||
import android.service.voice.HotwordDetectionService.InitializationStatus;
|
||||
|
||||
/**
|
||||
* Basic functionality for hotword detectors.
|
||||
@@ -166,9 +165,12 @@ public interface HotwordDetector {
|
||||
* Called when the {@link HotwordDetectionService} is created by the system and given a
|
||||
* short amount of time to report it's initialization state.
|
||||
*
|
||||
* @param status Info about initialization state of {@link HotwordDetectionService}.
|
||||
* @param status Info about initialization state of {@link HotwordDetectionService}; the
|
||||
* allowed values are {@link HotwordDetectionService#INITIALIZATION_STATUS_SUCCESS},
|
||||
* 1<->{@link HotwordDetectionService#getMaxCustomInitializationStatus()},
|
||||
* {@link HotwordDetectionService#INITIALIZATION_STATUS_UNKNOWN}.
|
||||
*/
|
||||
void onHotwordDetectionServiceInitialized(@InitializationStatus int status);
|
||||
void onHotwordDetectionServiceInitialized(int status);
|
||||
|
||||
/**
|
||||
* Called with the {@link HotwordDetectionService} is restarted.
|
||||
|
||||
@@ -164,6 +164,11 @@ final class HotwordDetectionConnection {
|
||||
KEY_INITIALIZATION_STATUS,
|
||||
INITIALIZATION_STATUS_UNKNOWN)
|
||||
: INITIALIZATION_STATUS_UNKNOWN;
|
||||
// Add the protection to avoid unexpected status
|
||||
if (status > HotwordDetectionService.getMaxCustomInitializationStatus()
|
||||
&& status != INITIALIZATION_STATUS_UNKNOWN) {
|
||||
status = INITIALIZATION_STATUS_UNKNOWN;
|
||||
}
|
||||
callback.onStatusReported(status);
|
||||
} catch (RemoteException e) {
|
||||
Slog.w(TAG, "Failed to report initialization status: " + e);
|
||||
|
||||
Reference in New Issue
Block a user