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

Commit 772d8969 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi Committed by Android (Google) Code Review
Browse files

Merge "AudioAttributes: test API for injecting a test identifier" into main

parents 505ead4a 15d2ebec
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -1965,8 +1965,14 @@ package android.media {

  public final class AudioAttributes implements android.os.Parcelable {
    method public static int[] getSdkUsages();
    method public long getTestId();
    method @NonNull public static String usageToXsdString(int);
    method public static int xsdStringToUsage(@NonNull String);
    field public static final long VALUE_TEST_ID_NONE = -9223372036854775808L; // 0x8000000000000000L
  }

  public static class AudioAttributes.Builder {
    method @NonNull public android.media.AudioAttributes.Builder setTestId(long);
  }

  public final class AudioDeviceInfo {
+50 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
// TODO switch from HIDL imports to AIDL
@@ -38,6 +39,8 @@ import android.util.Log;
import android.util.SparseIntArray;
import android.util.proto.ProtoOutputStream;

import androidx.annotation.IntRange;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
@@ -698,6 +701,21 @@ public final class AudioAttributes implements Parcelable {
        return (mFlags & FLAG_CONTENT_SPATIALIZED) != 0;
    }

    /**
     * @hide
     * Returns the test identifier value set with {@link Builder#setTestId(long)}.
     * @return the test ID value, or {@link #VALUE_TEST_ID_NONE} is none found
     */
    @TestApi
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature.
    public long getTestId() {
        if (mBundle == null) {
            return VALUE_TEST_ID_NONE;
        }
        return mBundle.getLong(KEY_TEST_ID, VALUE_TEST_ID_NONE);
    }


    /** @hide */
    @IntDef(flag = false, value = {
            SPATIALIZATION_BEHAVIOR_AUTO,
@@ -1337,6 +1355,24 @@ public final class AudioAttributes implements Parcelable {
            mFlags |= FLAG_CALL_REDIRECTION;
            return this;
        }

        /**
         * @hide
         * Sets a test identifier in the attributes
         * @param testId value of the identifier
         * @return the same Builder instance.
         */
        @TestApi
        @SuppressLint("UnflaggedApi") // @TestApi without associated feature
        public @NonNull Builder setTestId(@IntRange(from = 0L) long testId) {
            if (testId < 0) {
                throw new IllegalArgumentException("Test ID value must be 0 or greater");
            }
            final Bundle testBundle = new Bundle(1);
            testBundle.putLong(KEY_TEST_ID, testId);
            addBundle(testBundle);
            return this;
        }
    };

    @Override
@@ -1353,6 +1389,20 @@ public final class AudioAttributes implements Parcelable {
     */
    public final static int FLATTEN_TAGS = 0x1;

    /**
     * Key in the Bundle to access the test ID value
     */
    private static final String KEY_TEST_ID = "key_test_id";
    /**
     * @hide
     * Value when no test ID value was given in {@link Builder#setTestId(long)}
     * @see #getTestId()
     * @see Builder#setTestId(long)
     */
    @TestApi
    @SuppressLint("UnflaggedApi") // @TestApi without associated feature
    public static final long VALUE_TEST_ID_NONE = Long.MIN_VALUE;

    private final static int ATTR_PARCEL_IS_NULL_BUNDLE = -1977;
    private final static int ATTR_PARCEL_IS_VALID_BUNDLE = 1980;

+5 −0
Original line number Diff line number Diff line
@@ -444,6 +444,11 @@ public final class AudioPlaybackConfiguration implements Parcelable {
        } else {
            builder.setUsage(in.mPlayerAttr.getUsage());
        }
        // only copy the test ID if present, not the whole Bundle
        final long testId = in.mPlayerAttr.getTestId();
        if (testId != AudioAttributes.VALUE_TEST_ID_NONE) {
            builder.setTestId(testId);
        }
        anonymCopy.mPlayerAttr = builder.build();
        // anonymized data
        anonymCopy.mPlayerType = PLAYER_TYPE_UNKNOWN;