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

Commit 3ec10291 authored by Charles Chen's avatar Charles Chen
Browse files

[API] Introduce VisualQueryDetectedResult

Introduce the new data class to encapsulate detection results from the
VisualQueryDetectionService and update paired API calls for future
extension.

Bug: 318617199
Test: atest CtsVoiceInteractionTestCases
Flag: ACONFIG android.service.voice.flags.allow_complex_results_egress_from_vqds NEXTFOOD
Change-Id: I9bebb71b1064e2b81a37f584c7af13a9ed8a4759
parent f5d37c93
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -13351,6 +13351,19 @@ package android.service.voice {
    field public static final int ERROR_CODE_UNKNOWN = 0; // 0x0
  }
  @FlaggedApi("android.service.voice.flags.allow_complex_results_egress_from_vqds") public final class VisualQueryDetectedResult implements android.os.Parcelable {
    method public int describeContents();
    method @NonNull public String getPartialQuery();
    method public void writeToParcel(@NonNull android.os.Parcel, int);
    field @NonNull public static final android.os.Parcelable.Creator<android.service.voice.VisualQueryDetectedResult> CREATOR;
  }
  public static final class VisualQueryDetectedResult.Builder {
    ctor public VisualQueryDetectedResult.Builder();
    method @NonNull public android.service.voice.VisualQueryDetectedResult build();
    method @NonNull public android.service.voice.VisualQueryDetectedResult.Builder setPartialQuery(@NonNull String);
  }
  public abstract class VisualQueryDetectionService extends android.app.Service implements android.service.voice.SandboxedDetectionInitializer {
    ctor public VisualQueryDetectionService();
    method public final void finishQuery() throws java.lang.IllegalStateException;
@@ -13362,6 +13375,7 @@ package android.service.voice {
    method public void onUpdateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, long, @Nullable java.util.function.IntConsumer);
    method public final void rejectQuery() throws java.lang.IllegalStateException;
    method public final void streamQuery(@NonNull String) throws java.lang.IllegalStateException;
    method @FlaggedApi("android.service.voice.flags.allow_complex_results_egress_from_vqds") public final void streamQuery(@NonNull android.service.voice.VisualQueryDetectedResult);
    field public static final String SERVICE_INTERFACE = "android.service.voice.VisualQueryDetectionService";
  }
@@ -13390,6 +13404,7 @@ package android.service.voice {
  public static interface VisualQueryDetector.Callback {
    method public void onFailure(@NonNull android.service.voice.VisualQueryDetectionServiceFailure);
    method public void onQueryDetected(@NonNull String);
    method @FlaggedApi("android.service.voice.flags.allow_complex_results_egress_from_vqds") public default void onQueryDetected(@NonNull android.service.voice.VisualQueryDetectedResult);
    method public void onQueryFinished();
    method public void onQueryRejected();
    method public void onUnknownFailure(@NonNull String);
+7 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.service.voice;

import android.service.voice.VisualQueryDetectedResult;

/**
 * Callback for returning the detected result from the {@link VisualQueryDetectionService}.
 *
@@ -41,6 +43,11 @@ oneway interface IDetectorSessionVisualQueryDetectionCallback {
     */
    void onQueryDetected(in String partialQuery);

    /**
     * Called when the detected result is streamed.
     */
    void onResultDetected(in VisualQueryDetectedResult partialResult);

    /**
     * Called when the detected result is valid.
     */
+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.service.voice;

import android.service.voice.VisualQueryDetectionServiceFailure;
import android.service.voice.VisualQueryDetectedResult;

/**
 * Callback for returning the detected result from the VisualQueryDetectionService.
@@ -30,6 +31,11 @@ oneway interface IVisualQueryDetectionVoiceInteractionCallback {
     */
    void onQueryDetected(in String partialQuery);

    /**
     * Called when the detected result is streamed.
     */
    void onResultDetected(in VisualQueryDetectedResult partialResult);

    /**
     * Called when the detected result is valid.
     */
+19 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.voice;

parcelable VisualQueryDetectedResult;
+238 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.voice;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.os.Parcel;
import android.os.Parcelable;
import android.service.voice.flags.Flags;

import com.android.internal.util.DataClass;

import java.util.Objects;

/**
 * Represents a result supporting the visual query detection.
 *
 * @hide
 */
@DataClass(
        genConstructor = false,
        genBuilder = true,
        genEqualsHashCode = true,
        genHiddenConstDefs = true,
        genParcelable = true,
        genToString = true
)
@SystemApi
@FlaggedApi(Flags.FLAG_ALLOW_COMPLEX_RESULTS_EGRESS_FROM_VQDS)
public final class VisualQueryDetectedResult implements Parcelable {

    /**
     * Text query being associated with the detection result.
     **/
    @NonNull
    private final String mPartialQuery;

    private static String defaultPartialQuery() {
        return "";
    }

    /**
     * Provides an instance of {@link Builder} with state corresponding to this instance.
     *
     * @hide
     */
    public Builder buildUpon() {
        return new Builder().setPartialQuery(mPartialQuery);
    }


    // Code below generated by codegen v1.0.23.
    //
    // DO NOT MODIFY!
    // CHECKSTYLE:OFF Generated code
    //
    // To regenerate run:
    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/service/voice/VisualQueryDetectedResult.java
    //
    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
    //   Settings > Editor > Code Style > Formatter Control
    //@formatter:off


    @DataClass.Generated.Member
    /* package-private */ VisualQueryDetectedResult(
            @NonNull String partialQuery) {
        this.mPartialQuery = partialQuery;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mPartialQuery);

        // onConstructed(); // You can define this method to get a callback
    }

    /**
     * Text query being associated with the detection result. *
     */
    @DataClass.Generated.Member
    public @NonNull String getPartialQuery() {
        return mPartialQuery;
    }

    @Override
    @DataClass.Generated.Member
    public String toString() {
        // You can override field toString logic by defining methods like:
        // String fieldNameToString() { ... }

        return "VisualQueryDetectedResult { " +
                "partialQuery = " + mPartialQuery +
        " }";
    }

    @Override
    @DataClass.Generated.Member
    public boolean equals(@Nullable Object o) {
        // You can override field equality logic by defining either of the methods like:
        // boolean fieldNameEquals(VisualQueryDetectedResult other) { ... }
        // boolean fieldNameEquals(FieldType otherValue) { ... }

        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        @SuppressWarnings("unchecked")
        VisualQueryDetectedResult that = (VisualQueryDetectedResult) o;
        //noinspection PointlessBooleanExpression
        return true
                && Objects.equals(mPartialQuery, that.mPartialQuery);
    }

    @Override
    @DataClass.Generated.Member
    public int hashCode() {
        // You can override field hashCode logic by defining methods like:
        // int fieldNameHashCode() { ... }

        int _hash = 1;
        _hash = 31 * _hash + Objects.hashCode(mPartialQuery);
        return _hash;
    }

    @Override
    @DataClass.Generated.Member
    public void writeToParcel(@NonNull Parcel dest, int flags) {
        // You can override field parcelling by defining methods like:
        // void parcelFieldName(Parcel dest, int flags) { ... }

        dest.writeString(mPartialQuery);
    }

    @Override
    @DataClass.Generated.Member
    public int describeContents() { return 0; }

    /** @hide */
    @SuppressWarnings({"unchecked", "RedundantCast"})
    @DataClass.Generated.Member
    /* package-private */ VisualQueryDetectedResult(@NonNull Parcel in) {
        // You can override field unparcelling by defining methods like:
        // static FieldType unparcelFieldName(Parcel in) { ... }

        String partialQuery = in.readString();

        this.mPartialQuery = partialQuery;
        com.android.internal.util.AnnotationValidations.validate(
                NonNull.class, null, mPartialQuery);

        // onConstructed(); // You can define this method to get a callback
    }

    @DataClass.Generated.Member
    public static final @NonNull Parcelable.Creator<VisualQueryDetectedResult> CREATOR
            = new Parcelable.Creator<VisualQueryDetectedResult>() {
        @Override
        public VisualQueryDetectedResult[] newArray(int size) {
            return new VisualQueryDetectedResult[size];
        }

        @Override
        public VisualQueryDetectedResult createFromParcel(@NonNull Parcel in) {
            return new VisualQueryDetectedResult(in);
        }
    };

    /**
     * A builder for {@link VisualQueryDetectedResult}
     */
    @SuppressWarnings("WeakerAccess")
    @DataClass.Generated.Member
    public static final class Builder {

        private @NonNull String mPartialQuery;

        private long mBuilderFieldsSet = 0L;

        public Builder() {
        }

        /**
         * Text query being associated with the detection result. *
         */
        @DataClass.Generated.Member
        public @NonNull Builder setPartialQuery(@NonNull String value) {
            checkNotUsed();
            mBuilderFieldsSet |= 0x1;
            mPartialQuery = value;
            return this;
        }

        /** Builds the instance. This builder should not be touched after calling this! */
        public @NonNull VisualQueryDetectedResult build() {
            checkNotUsed();
            mBuilderFieldsSet |= 0x2; // Mark builder used

            if ((mBuilderFieldsSet & 0x1) == 0) {
                mPartialQuery = defaultPartialQuery();
            }
            VisualQueryDetectedResult o = new VisualQueryDetectedResult(
                    mPartialQuery);
            return o;
        }

        private void checkNotUsed() {
            if ((mBuilderFieldsSet & 0x2) != 0) {
                throw new IllegalStateException(
                        "This Builder should not be reused. Use a new Builder instance instead");
            }
        }
    }

    @DataClass.Generated(
            time = 1704944313642L,
            codegenVersion = "1.0.23",
            sourceFile = "frameworks/base/core/java/android/service/voice/VisualQueryDetectedResult.java",
            inputSignatures = "private final @android.annotation.NonNull java.lang.String mPartialQuery\nprivate static  java.lang.String defaultPartialQuery()\npublic  android.service.voice.VisualQueryDetectedResult.Builder buildUpon()\nclass VisualQueryDetectedResult extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false, genBuilder=true, genEqualsHashCode=true, genHiddenConstDefs=true, genParcelable=true, genToString=true)")
    @Deprecated
    private void __metadata() {}


    //@formatter:on
    // End of generated code

}
Loading