Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 363d3c5a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "API review : use a range of numbers for OEM errors" into sc-dev am: c0f1de7c

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14501937

Change-Id: I8bf74ad41be639146773875d5992312f9d3ecaa7
parents 4aa39511 c0f1de7c
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -10539,6 +10539,7 @@ package android.service.voice {
  public abstract class HotwordDetectionService extends android.app.Service {
  public abstract class HotwordDetectionService extends android.app.Service {
    ctor public HotwordDetectionService();
    ctor public HotwordDetectionService();
    method public static int getMaxCustomInitializationStatus();
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    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 @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);
    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.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 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);
    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_SUCCESS = 0; // 0x0
    field public static final int INITIALIZATION_STATUS_UNKNOWN = 100; // 0x64
    field public static final int INITIALIZATION_STATUS_UNKNOWN = 100; // 0x64
    field public static final String SERVICE_INTERFACE = "android.service.voice.HotwordDetectionService";
    field public static final String SERVICE_INTERFACE = "android.service.voice.HotwordDetectionService";
+5 −3
Original line number Original line Diff line number Diff line
@@ -49,7 +49,6 @@ import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.os.SharedMemory;
import android.service.voice.HotwordDetectionService.InitializationStatus;
import android.util.Log;
import android.util.Log;
import android.util.Slog;
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
         * Called when the {@link HotwordDetectionService} is created by the system and given a
         * short amount of time to report it's initialization state.
         * 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) {
        }
        }


        /**
        /**
+28 −23
Original line number Original line Diff line number Diff line
@@ -78,30 +78,17 @@ public abstract class HotwordDetectionService extends Service {
    /** @hide */
    /** @hide */
    public static final String KEY_INITIALIZATION_STATUS = "initialization_status";
    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 {}

    /**
    /**
     * Indicates that the updated status is successful.
     * The maximum number of initialization status for some application specific failed reasons.
     */
     *
    public static final int INITIALIZATION_STATUS_SUCCESS = 0;
     * @hide

    /**
     * Indicates that the updated status is failure for some application specific reasons.
     */
     */
    public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_1 = 1;
    public static final int MAXIMUM_NUMBER_OF_INITIALIZATION_STATUS_CUSTOM_ERROR = 2;


    /**
    /**
     * Indicates that the updated status is failure for some application specific reasons.
     * Indicates that the updated status is successful.
     */
     */
    public static final int INITIALIZATION_STATUS_CUSTOM_ERROR_2 = 2;
    public static final int INITIALIZATION_STATUS_SUCCESS = 0;


    /**
    /**
     * Indicates that the callback wasn’t invoked within the timeout.
     * Indicates that the callback wasn’t invoked within the timeout.
@@ -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
     * 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}.
     * 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.
     * such data to the trusted process.
     * @param callbackTimeoutMillis Timeout in milliseconds for the operation to invoke the
     * @param callbackTimeoutMillis Timeout in milliseconds for the operation to invoke the
     * statusCallback.
     * statusCallback.
     * @param statusCallback Use this to return the updated result. This is non-null only when the
     * @param statusCallback Use this to return the updated result; the allowed values are
     * {@link HotwordDetectionService} is being initialized; and it is null if the state is updated
     * {@link #INITIALIZATION_STATUS_SUCCESS}, 1<->{@link #getMaxCustomInitializationStatus()}.
     * after that.
     * This is non-null only when the {@link HotwordDetectionService} is being initialized; and it
     * is null if the state is updated after that.
     *
     *
     * @hide
     * @hide
     */
     */
@@ -309,7 +310,7 @@ public abstract class HotwordDetectionService extends Service {
            @Nullable PersistableBundle options,
            @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory,
            @Nullable SharedMemory sharedMemory,
            @DurationMillisLong long callbackTimeoutMillis,
            @DurationMillisLong long callbackTimeoutMillis,
            @Nullable @InitializationStatus IntConsumer statusCallback) {
            @Nullable IntConsumer statusCallback) {
        // TODO: Handle the unimplemented case by throwing?
        // TODO: Handle the unimplemented case by throwing?
    }
    }


@@ -389,6 +390,10 @@ public abstract class HotwordDetectionService extends Service {
        if (callback != null) {
        if (callback != null) {
            intConsumer =
            intConsumer =
                    value -> {
                    value -> {
                        if (value > getMaxCustomInitializationStatus()) {
                            throw new IllegalArgumentException(
                                    "The initialization status is invalid for " + value);
                        }
                        try {
                        try {
                            Bundle status = new Bundle();
                            Bundle status = new Bundle();
                            status.putInt(KEY_INITIALIZATION_STATUS, value);
                            status.putInt(KEY_INITIALIZATION_STATUS, value);
+5 −3
Original line number Original line Diff line number Diff line
@@ -28,7 +28,6 @@ import android.media.AudioFormat;
import android.os.ParcelFileDescriptor;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.PersistableBundle;
import android.os.SharedMemory;
import android.os.SharedMemory;
import android.service.voice.HotwordDetectionService.InitializationStatus;


/**
/**
 * Basic functionality for hotword detectors.
 * 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
         * Called when the {@link HotwordDetectionService} is created by the system and given a
         * short amount of time to report it's initialization state.
         * 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.
         * Called with the {@link HotwordDetectionService} is restarted.
+5 −0
Original line number Original line Diff line number Diff line
@@ -164,6 +164,11 @@ final class HotwordDetectionConnection {
                                KEY_INITIALIZATION_STATUS,
                                KEY_INITIALIZATION_STATUS,
                                INITIALIZATION_STATUS_UNKNOWN)
                                INITIALIZATION_STATUS_UNKNOWN)
                                : 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);
                        callback.onStatusReported(status);
                    } catch (RemoteException e) {
                    } catch (RemoteException e) {
                        Slog.w(TAG, "Failed to report initialization status: " + e);
                        Slog.w(TAG, "Failed to report initialization status: " + e);