diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-08-24 21:51:17 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-08-24 21:51:17 +0000 |
commit | ae1cdcfd48e6fb0467606fa7ad5c97fcf7cce0f7 (patch) | |
tree | 5c357346005dbb8a9e4cddad7521a397fb5c7ad9 | |
parent | 831001de82cb72efaa9dd0a7f42fb1676d000e49 (diff) | |
parent | 903c152df1f2a0e20c783652768269a76f6d13c6 (diff) | |
download | cts-ae1cdcfd48e6fb0467606fa7ad5c97fcf7cce0f7.tar.gz |
Snap for 8989579 from 903c152df1f2a0e20c783652768269a76f6d13c6 to mainline-conscrypt-releaseaml_con_331115000aml_con_331011010
Change-Id: Ibb9eb47b9891335a11ed9c6533306281b0d67c3a
6 files changed, 407 insertions, 945 deletions
diff --git a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java index eb7528c1729..1d42357f71e 100644 --- a/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java +++ b/hostsidetests/appcompat/strictjavapackages/src/android/compat/sjp/cts/StrictJavaPackagesTest.java @@ -238,7 +238,8 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test { "Landroid/app/sdksandbox/ISdkSandboxManager;", "Landroid/app/sdksandbox/ISdkSandboxLifecycleCallback;", "Landroid/app/sdksandbox/ISendDataCallback;", - "Landroid/app/sdksandbox/ISharedPreferencesSyncCallback;" + "Landroid/app/sdksandbox/ISharedPreferencesSyncCallback;", + "Landroid/app/sdksandbox/ISdkToServiceCallback;" ); private static final String FEATURE_WEARABLE = "android.hardware.type.watch"; @@ -737,7 +738,9 @@ public class StrictJavaPackagesTest extends BaseHostJUnit4Test { "Lcom/android/sdksandbox/ILoadSdkInSandboxCallback;", "Lcom/android/sdksandbox/IRequestSurfacePackageFromSdkCallback;", "Lcom/android/sdksandbox/ISdkSandboxManagerToSdkSandboxCallback;", - "Lcom/android/sdksandbox/ISdkSandboxService;" + "Lcom/android/sdksandbox/ISdkSandboxService;", + "Lcom/android/sdksandbox/SandboxLatencyInfo-IA;", + "Lcom/android/sdksandbox/SandboxLatencyInfo;" ); private static final ImmutableMap<String, ImmutableSet<String>> FULL_APK_IN_APEX_BURNDOWN = diff --git a/tests/media/src/android/mediav2/cts/CodecTestBase.java b/tests/media/src/android/mediav2/cts/CodecTestBase.java index d58f9bf3e85..9d1d839c47d 100644 --- a/tests/media/src/android/mediav2/cts/CodecTestBase.java +++ b/tests/media/src/android/mediav2/cts/CodecTestBase.java @@ -30,7 +30,9 @@ import android.media.MediaCodecInfo.CodecProfileLevel; import android.media.MediaCodecList; import android.media.MediaExtractor; import android.media.MediaFormat; +import android.media.MediaMuxer; import android.os.Build; +import android.os.Bundle; import android.os.PersistableBundle; import android.os.SystemProperties; import android.util.Log; @@ -604,30 +606,14 @@ abstract class CodecTestBase { CODEC_DEFAULT, // Default codec must support CODEC_OPTIONAL // Codec support is optional } + + static final ArrayList<String> HDR_INFO_IN_BITSTREAM_CODECS = new ArrayList<>(); static final String HDR_STATIC_INFO = - "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42 40 e8 03 64 00 e8 03 2c 01"; - static final String[] HDR_DYNAMIC_INFO = new String[]{ - "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + - "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + - "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + - "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00", - - "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + - "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + - "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + - "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00", - - "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + - "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + - "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + - "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00", - - "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + - "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + - "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + - "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00", - }; - boolean mTestDynamicMetadata = false; + "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; + static final String HDR_STATIC_INCORRECT_INFO = + "00 d0 84 80 3e c2 33 c4 86 10 27 d0 07 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; + static final HashMap<Integer, String> HDR_DYNAMIC_INFO = new HashMap<>(); + static final HashMap<Integer, String> HDR_DYNAMIC_INCORRECT_INFO = new HashMap<>(); static final String CODEC_PREFIX_KEY = "codec-prefix"; static final String MEDIA_TYPE_PREFIX_KEY = "media-type-prefix"; static final String MIME_SEL_KEY = "mime-sel"; @@ -783,6 +769,45 @@ abstract class CodecTestBase { mProfileMap.put(MediaFormat.MIMETYPE_VIDEO_VP9, VP9_PROFILES); mProfileMap.put(MediaFormat.MIMETYPE_VIDEO_AV1, AV1_PROFILES); mProfileMap.put(MediaFormat.MIMETYPE_AUDIO_AAC, AAC_PROFILES); + + HDR_INFO_IN_BITSTREAM_CODECS.add(MediaFormat.MIMETYPE_VIDEO_AV1); + HDR_INFO_IN_BITSTREAM_CODECS.add(MediaFormat.MIMETYPE_VIDEO_AVC); + HDR_INFO_IN_BITSTREAM_CODECS.add(MediaFormat.MIMETYPE_VIDEO_HEVC); + + HDR_DYNAMIC_INFO.put(0, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00"); + HDR_DYNAMIC_INFO.put(4, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00"); + HDR_DYNAMIC_INFO.put(12, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00"); + HDR_DYNAMIC_INFO.put(22, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00"); + + + HDR_DYNAMIC_INCORRECT_INFO.put(0, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 00"); + HDR_DYNAMIC_INCORRECT_INFO.put(4, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0a 00 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 01"); + HDR_DYNAMIC_INCORRECT_INFO.put(12, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 02"); + HDR_DYNAMIC_INCORRECT_INFO.put(22, "b5 00 3c 00 01 04 00 40 00 0c 80 4e 20 27 10 00" + + "0e 80 00 24 08 00 00 28 00 00 50 00 28 c8 00 c9" + + "90 02 aa 58 05 ca d0 0c 0a f8 16 83 18 9c 18 00" + + "40 78 13 64 d5 7c 2e 2c c3 59 de 79 6e c3 c2 03"); } static int[] combine(int[] first, int[] second) { @@ -1361,6 +1386,12 @@ abstract class CodecTestBase { return Arrays.copyOfRange(tempArray, 0, i); } + void insertHdrDynamicInfo(byte[] info) { + final Bundle params = new Bundle(); + params.putByteArray(MediaFormat.KEY_HDR10_PLUS_INFO, info); + mCodec.setParameters(params); + } + boolean isFormatSimilar(MediaFormat inpFormat, MediaFormat outFormat) { if (inpFormat == null || outFormat == null) return false; String inpMime = inpFormat.getString(MediaFormat.KEY_MIME); @@ -1419,41 +1450,26 @@ abstract class CodecTestBase { } } - void validateHDRStaticMetaData(MediaFormat fmt, ByteBuffer hdrStaticRef) { - ByteBuffer hdrStaticInfo = fmt.getByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO, null); - assertNotNull("No HDR static metadata present in format : " + fmt, hdrStaticInfo); - if (!hdrStaticRef.equals(hdrStaticInfo)) { + void validateHDRInfo(MediaFormat fmt, String hdrInfoKey, ByteBuffer hdrInfoRef) { + ByteBuffer hdrInfo = fmt.getByteBuffer(hdrInfoKey, null); + assertNotNull("No " + hdrInfoKey + " present in format : " + fmt, hdrInfo); + if (!hdrInfoRef.equals(hdrInfo)) { StringBuilder refString = new StringBuilder(""); StringBuilder testString = new StringBuilder(""); - byte[] ref = new byte[hdrStaticRef.capacity()]; - hdrStaticRef.get(ref); - byte[] test = new byte[hdrStaticInfo.capacity()]; - hdrStaticInfo.get(test); - for (int i = 0; i < Math.min(ref.length, test.length); i++) { + byte[] ref = new byte[hdrInfoRef.capacity()]; + hdrInfoRef.get(ref); + hdrInfoRef.rewind(); + byte[] test = new byte[hdrInfo.capacity()]; + hdrInfo.get(test); + hdrInfo.rewind(); + for (int i = 0; i < ref.length; i++) { refString.append(String.format("%2x ", ref[i])); - testString.append(String.format("%2x ", test[i])); } - fail("hdr static info mismatch" + "\n" + "ref static info : " + refString + "\n" + - "test static info : " + testString); - } - } - - void validateHDRDynamicMetaData(MediaFormat fmt, ByteBuffer hdrDynamicRef) { - ByteBuffer hdrDynamicInfo = fmt.getByteBuffer(MediaFormat.KEY_HDR10_PLUS_INFO, null); - assertNotNull("No HDR dynamic metadata present in format : " + fmt, hdrDynamicInfo); - if (!hdrDynamicRef.equals(hdrDynamicInfo)) { - StringBuilder refString = new StringBuilder(""); - StringBuilder testString = new StringBuilder(""); - byte[] ref = new byte[hdrDynamicRef.capacity()]; - hdrDynamicRef.get(ref); - byte[] test = new byte[hdrDynamicInfo.capacity()]; - hdrDynamicInfo.get(test); - for (int i = 0; i < Math.min(ref.length, test.length); i++) { - refString.append(String.format("%2x ", ref[i])); + for (int i = 0; i < test.length; i++) { testString.append(String.format("%2x ", test[i])); } - fail("hdr dynamic info mismatch" + "\n" + "ref dynamic info : " + refString + "\n" + - "test dynamic info : " + testString); + fail(hdrInfoKey + " mismatch in codec " + mCodecName + "\nref info : " + refString + + "\n test info : " + testString); } } @@ -1675,15 +1691,8 @@ class CodecDecoderTestBase extends CodecTestBase { int height = format.getInteger(MediaFormat.KEY_HEIGHT); int stride = format.getInteger(MediaFormat.KEY_STRIDE); mOutputBuff.checksum(buf, info.size, width, height, stride, bytesPerSample); - - if (mTestDynamicMetadata) { - validateHDRDynamicMetaData(mCodec.getOutputFormat(), ByteBuffer - .wrap(loadByteArrayFromString(HDR_DYNAMIC_INFO[mOutputCount]))); - - } } } - if ((info.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) { mSawOutputEOS = true; } @@ -1803,57 +1812,18 @@ class CodecDecoderTestBase extends CodecTestBase { mCodec.release(); mExtractor.release(); } - - void validateHDRStaticMetaData(String parent, String name, ByteBuffer HDRStatic, - boolean ignoreContainerStaticInfo) - throws IOException, InterruptedException { - mOutputBuff = new OutputManager(); - MediaFormat format = setUpSource(parent, name); - if (ignoreContainerStaticInfo) { - format.removeKey(MediaFormat.KEY_HDR_STATIC_INFO); - } - mCodec = MediaCodec.createByCodecName(mCodecName); - configureCodec(format, true, true, false); - mCodec.start(); - doWork(10); - queueEOS(); - waitForAllOutputs(); - validateHDRStaticMetaData(mCodec.getOutputFormat(), HDRStatic); - mCodec.stop(); - mCodec.release(); - mExtractor.release(); - } - - void validateHDRDynamicMetaData(String parent, String name, boolean ignoreContainerDynamicInfo) - throws IOException, InterruptedException { - mOutputBuff = new OutputManager(); - MediaFormat format = setUpSource(parent, name); - if (ignoreContainerDynamicInfo) { - format.removeKey(MediaFormat.KEY_HDR10_PLUS_INFO); - } - mCodec = MediaCodec.createByCodecName(mCodecName); - configureCodec(format, true, true, false); - mCodec.start(); - doWork(10); - queueEOS(); - waitForAllOutputs(); - mCodec.stop(); - mCodec.release(); - mExtractor.release(); - } } class CodecEncoderTestBase extends CodecTestBase { private static final String LOG_TAG = CodecEncoderTestBase.class.getSimpleName(); // files are in WorkDir.getMediaDirString(); - private static final String INPUT_AUDIO_FILE = "bbb_2ch_44kHz_s16le.raw"; - private static final String INPUT_VIDEO_FILE = "bbb_cif_yuv420p_30fps.yuv"; + protected static final String INPUT_AUDIO_FILE = "bbb_2ch_44kHz_s16le.raw"; + protected static final String INPUT_VIDEO_FILE = "bbb_cif_yuv420p_30fps.yuv"; protected static final String INPUT_AUDIO_FILE_HBD = "audio/sd_2ch_48kHz_f32le.raw"; protected static final String INPUT_VIDEO_FILE_HBD = "cosmat_cif_24fps_yuv420p16le.yuv"; - - private final int INP_FRM_WIDTH = 352; - private final int INP_FRM_HEIGHT = 288; + protected final int INP_FRM_WIDTH = 352; + protected final int INP_FRM_HEIGHT = 288; final String mMime; final int[] mBitrates; @@ -2212,3 +2182,241 @@ class CodecEncoderTestBase extends CodecTestBase { return cdtb.mOutputBuff.getBuffer(); } } + +class HDRDecoderTestBase extends CodecDecoderTestBase { + private static final String LOG_TAG = HDRDecoderTestBase.class.getSimpleName(); + + private ByteBuffer mHdrStaticInfoRef; + private ByteBuffer mHdrStaticInfoStream; + private ByteBuffer mHdrStaticInfoContainer; + private Map<Integer, String> mHdrDynamicInfoRef; + private Map<Integer, String> mHdrDynamicInfoStream; + private Map<Integer, String> mHdrDynamicInfoContainer; + private String mHdrDynamicInfoCurrent; + + public HDRDecoderTestBase(String decoder, String mime, String testFile) { + super(decoder, mime, testFile); + } + + void enqueueInput(int bufferIndex) { + if (mHdrDynamicInfoContainer != null && mHdrDynamicInfoContainer.containsKey(mInputCount) && + mExtractor.getSampleSize() != -1) { + insertHdrDynamicInfo( + loadByteArrayFromString(mHdrDynamicInfoContainer.get(mInputCount))); + } + super.enqueueInput(bufferIndex); + } + + void dequeueOutput(int bufferIndex, MediaCodec.BufferInfo info) { + if (info.size > 0 && mHdrDynamicInfoRef != null) { + MediaFormat format = mCodec.getOutputFormat(bufferIndex); + if (mHdrDynamicInfoRef.containsKey(mOutputCount)) { + mHdrDynamicInfoCurrent = mHdrDynamicInfoRef.get(mOutputCount); + } + validateHDRInfo(format, MediaFormat.KEY_HDR10_PLUS_INFO, + ByteBuffer.wrap(loadByteArrayFromString(mHdrDynamicInfoCurrent))); + } + super.dequeueOutput(bufferIndex, info); + } + + void validateHDRInfo(String hdrStaticInfoStream, String hdrStaticInfoContainer, + Map<Integer, String> hdrDynamicInfoStream, + Map<Integer, String> hdrDynamicInfoContainer) throws IOException, + InterruptedException { + mHdrStaticInfoStream = hdrStaticInfoStream != null ? + ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoStream)) : null; + mHdrStaticInfoContainer = hdrStaticInfoContainer != null ? + ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoContainer)) : null; + mHdrStaticInfoRef = mHdrStaticInfoStream == null ? mHdrStaticInfoContainer : + mHdrStaticInfoStream; + mHdrDynamicInfoStream = hdrDynamicInfoStream; + mHdrDynamicInfoContainer = hdrDynamicInfoContainer; + mHdrDynamicInfoRef = hdrDynamicInfoStream == null ? hdrDynamicInfoContainer : + hdrDynamicInfoStream; + + assertTrue("reference hdr10/hdr10+ info is not supplied for validation", + mHdrDynamicInfoRef != null || mHdrStaticInfoRef != null); + + if (mHdrDynamicInfoStream != null || mHdrDynamicInfoContainer != null) { + Assume.assumeNotNull("Test is only applicable to codecs that have HDR10+ profiles", + mProfileHdr10PlusMap.get(mMime)); + } + if (mHdrStaticInfoStream != null || mHdrStaticInfoContainer != null) { + Assume.assumeNotNull("Test is only applicable to codecs that have HDR10 profiles", + mProfileHdr10Map.get(mMime)); + } + + File fObj = new File(mTestFile); + String parent = fObj.getParent(); + if (parent != null) parent += File.separator; + else parent = mInpPrefix; + Preconditions.assertTestFileExists(parent + fObj.getName()); + // For decoders, if you intend to supply hdr10+ info using external means like json, make + // sure that info that is being supplied is in sync with SEI info + if (mHdrDynamicInfoStream != null && mHdrDynamicInfoContainer != null) { + assertEquals("Container hdr10+ info size and elementary stream SEI hdr10+ " + + "info size are unequal", mHdrDynamicInfoStream.size(), + mHdrDynamicInfoContainer.size()); + for (Map.Entry<Integer, String> element : mHdrDynamicInfoStream.entrySet()) { + assertTrue("Container hdr10+ info and elementary stream SEI hdr10+ " + + "info frame positions are not in sync", + mHdrDynamicInfoContainer.containsKey(element.getKey())); + } + } + mOutputBuff = new OutputManager(); + MediaFormat format = setUpSource(parent, fObj.getName()); + if (mHdrDynamicInfoStream != null || mHdrDynamicInfoContainer != null) { + format.setInteger(MediaFormat.KEY_PROFILE, mProfileHdr10PlusMap.get(mMime)[0]); + } else { + format.setInteger(MediaFormat.KEY_PROFILE, mProfileHdr10Map.get(mMime)[0]); + } + ArrayList<MediaFormat> formatList = new ArrayList<>(); + formatList.add(format); + Assume.assumeTrue(mCodecName + " does not support HDR10/HDR10+ profile", + areFormatsSupported(mCodecName, mMime, formatList)); + mCodec = MediaCodec.createByCodecName(mCodecName); + configureCodec(format, false, true, false); + mCodec.start(); + doWork(Integer.MAX_VALUE); + queueEOS(); + waitForAllOutputs(); + if (mHdrStaticInfoRef != null) { + validateHDRInfo(mCodec.getOutputFormat(), MediaFormat.KEY_HDR_STATIC_INFO, + mHdrStaticInfoRef); + } + mCodec.stop(); + mCodec.release(); + mExtractor.release(); + } +} + +class HDREncoderTestBase extends CodecEncoderTestBase { + private static final String LOG_TAG = HDREncoderTestBase.class.getSimpleName(); + + private ByteBuffer mHdrStaticInfo; + private Map<Integer, String> mHdrDynamicInfo; + + private MediaMuxer mMuxer; + private int mTrackID = -1; + + public HDREncoderTestBase(String encoderName, String mediaType, int bitrate, int width, + int height) { + super(encoderName, mediaType, new int[]{bitrate}, new int[]{width}, new int[]{height}); + } + + void enqueueInput(int bufferIndex) { + if (mHdrDynamicInfo != null && mHdrDynamicInfo.containsKey(mInputCount)) { + insertHdrDynamicInfo(loadByteArrayFromString(mHdrDynamicInfo.get(mInputCount))); + } + super.enqueueInput(bufferIndex); + } + + void dequeueOutput(int bufferIndex, MediaCodec.BufferInfo info) { + MediaFormat bufferFormat = mCodec.getOutputFormat(bufferIndex); + if (info.size > 0) { + ByteBuffer buf = mCodec.getOutputBuffer(bufferIndex); + if (mMuxer != null) { + if (mTrackID == -1) { + mTrackID = mMuxer.addTrack(bufferFormat); + mMuxer.start(); + } + mMuxer.writeSampleData(mTrackID, buf, info); + } + } + super.dequeueOutput(bufferIndex, info); + } + + void validateHDRInfo(String hdrStaticInfo, Map<Integer, String> hdrDynamicInfo) + throws IOException, InterruptedException { + mHdrStaticInfo = hdrStaticInfo != null ? + ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfo)) : null; + mHdrDynamicInfo = hdrDynamicInfo; + + setUpParams(1); + + MediaFormat format = mFormats.get(0); + format.setInteger(MediaFormat.KEY_COLOR_FORMAT, COLOR_FormatYUVP010); + format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_LIMITED); + format.setInteger(MediaFormat.KEY_COLOR_STANDARD, MediaFormat.COLOR_STANDARD_BT2020); + format.setInteger(MediaFormat.KEY_COLOR_TRANSFER, MediaFormat.COLOR_TRANSFER_ST2084); + int profile = (mHdrDynamicInfo != null) ? mProfileHdr10PlusMap.get(mMime)[0] : + mProfileHdr10Map.get(mMime)[0]; + format.setInteger(MediaFormat.KEY_PROFILE, profile); + + if (mHdrStaticInfo != null) { + format.setByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO, mHdrStaticInfo); + } + Assume.assumeTrue(mCodecName + " does not support HDR10/HDR10+ profile " + profile, + areFormatsSupported(mCodecName, mMime, mFormats)); + Assume.assumeTrue(mCodecName + " does not support color format COLOR_FormatYUVP010", + hasSupportForColorFormat(mCodecName, mMime, COLOR_FormatYUVP010)); + + mBytesPerSample = 2; + setUpSource(INPUT_VIDEO_FILE_HBD); + + int frameLimit = 4; + if (mHdrDynamicInfo != null) { + Integer lastHdr10PlusFrame = + Collections.max(HDR_DYNAMIC_INFO.entrySet(), Map.Entry.comparingByKey()) + .getKey(); + frameLimit = lastHdr10PlusFrame + 10; + } + int maxNumFrames = mInputData.length / (INP_FRM_WIDTH * INP_FRM_HEIGHT * mBytesPerSample); + assertTrue("HDR info tests require input file with at least " + frameLimit + + " frames. " + INPUT_VIDEO_FILE_HBD + " has " + maxNumFrames + " frames.", + frameLimit <= maxNumFrames); + + mOutputBuff = new OutputManager(); + mCodec = MediaCodec.createByCodecName(mCodecName); + File tmpFile; + int muxerFormat; + if (mMime.equals(MediaFormat.MIMETYPE_VIDEO_VP9)) { + muxerFormat = MediaMuxer.OutputFormat.MUXER_OUTPUT_WEBM; + tmpFile = File.createTempFile("tmp10bit", ".webm"); + } else { + muxerFormat = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4; + tmpFile = File.createTempFile("tmp10bit", ".mp4"); + } + mMuxer = new MediaMuxer(tmpFile.getAbsolutePath(), muxerFormat); + configureCodec(format, true, true, true); + mCodec.start(); + doWork(frameLimit); + queueEOS(); + waitForAllOutputs(); + if (mTrackID != -1) { + mMuxer.stop(); + mTrackID = -1; + } + if (mMuxer != null) { + mMuxer.release(); + mMuxer = null; + } + String log = String.format("format: %s \n codec: %s:: ", format, mCodecName); + assertTrue(log + "unexpected error", !mAsyncHandle.hasSeenError()); + assertTrue(log + "no input sent", 0 != mInputCount); + assertTrue(log + "output received", 0 != mOutputCount); + + MediaFormat fmt = mCodec.getOutputFormat(); + + mCodec.stop(); + mCodec.release(); + if (mHdrStaticInfo != null) { + // verify if the out fmt contains HDR Static info as expected + validateHDRInfo(fmt, MediaFormat.KEY_HDR_STATIC_INFO, mHdrStaticInfo); + } + + // verify if the muxed file contains HDR Dynamic info as expected + MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS); + String decoder = codecList.findDecoderForFormat(format); + assertNotNull("Device advertises support for encoding " + format + " but not decoding it", + decoder); + + HDRDecoderTestBase decoderTest = new HDRDecoderTestBase(decoder, mMime, + tmpFile.getAbsolutePath()); + decoderTest.validateHDRInfo(hdrStaticInfo, hdrStaticInfo, mHdrDynamicInfo, mHdrDynamicInfo); + if (HDR_INFO_IN_BITSTREAM_CODECS.contains(mMime)) { + decoderTest.validateHDRInfo(hdrStaticInfo, null, mHdrDynamicInfo, null); + } + tmpFile.delete(); + } +} diff --git a/tests/media/src/android/mediav2/cts/DecoderHDRInfoTest.java b/tests/media/src/android/mediav2/cts/DecoderHDRInfoTest.java index 3dd28aa48c3..4994a9bc987 100644 --- a/tests/media/src/android/mediav2/cts/DecoderHDRInfoTest.java +++ b/tests/media/src/android/mediav2/cts/DecoderHDRInfoTest.java @@ -22,6 +22,8 @@ import android.os.Build; import androidx.test.filters.SdkSuppress; import androidx.test.filters.SmallTest; +import com.android.compatibility.common.util.CddTest; + import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; @@ -29,34 +31,34 @@ import org.junit.runners.Parameterized; import java.io.IOException; import java.nio.ByteBuffer; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; +import java.util.Map; /** - * Test to validate hdr static metadata in decoders + * Test to validate hdr static info in decoders */ @RunWith(Parameterized.class) // P010 support was added in Android T, hence limit the following tests to Android T and above @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU, codeName = "Tiramisu") -public class DecoderHDRInfoTest extends CodecDecoderTestBase { +public class DecoderHDRInfoTest extends HDRDecoderTestBase { private static final String LOG_TAG = DecoderHDRInfoTest.class.getSimpleName(); - private static final String HDR_STATIC_INFO = - "00 d0 84 80 3e c2 33 c4 86 4c 1d b8 0b 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; - private static final String HDR_STATIC_INCORRECT_INFO = - "00 d0 84 80 3e c2 33 c4 86 10 27 d0 07 13 3d 42 40 a0 0f 32 00 10 27 df 0d"; - private final ByteBuffer mHDRStaticInfoStream; - private final ByteBuffer mHDRStaticInfoContainer; + private String mHDRStaticInfoStream; + private String mHDRStaticInfoContainer; + private Map<Integer, String> mHDRDynamicInfoStream; + private Map<Integer, String> mHDRDynamicInfoContainer; public DecoderHDRInfoTest(String codecName, String mediaType, String testFile, - String hdrStaticInfoStream, String hdrStaticInfoContainer) { + String hdrStaticInfoStream, String hdrStaticInfoContainer, + Map<Integer, String> HDRDynamicInfoStream, + Map<Integer, String> HDRDynamicInfoContainer) { super(codecName, mediaType, testFile); - mHDRStaticInfoStream = hdrStaticInfoStream != null ? - ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoStream)) : null; - mHDRStaticInfoContainer = hdrStaticInfoContainer != null ? - ByteBuffer.wrap(loadByteArrayFromString(hdrStaticInfoContainer)) : null; + mHDRStaticInfoStream = hdrStaticInfoStream; + mHDRStaticInfoContainer = hdrStaticInfoContainer; + mHDRDynamicInfoStream = HDRDynamicInfoStream; + mHDRDynamicInfoContainer = HDRDynamicInfoContainer; } @Parameterized.Parameters(name = "{index}({0}_{1})") @@ -65,64 +67,50 @@ public class DecoderHDRInfoTest extends CodecDecoderTestBase { final boolean needAudio = false; final boolean needVideo = true; final List<Object[]> exhaustiveArgsList = Arrays.asList(new Object[][]{ - // codecMediaType, testFile, hdrInfo in stream, hdrInfo in container + // codecMediaType, testFile, hdrStaticInfo in stream, hdrStaticInfo in container, + // hdrDynamicInfo in stream, hdrDynamicInfo in container {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_stream_and_container_correct_hevc.mkv", - HDR_STATIC_INFO, HDR_STATIC_INFO}, + HDR_STATIC_INFO, HDR_STATIC_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_stream_correct_container_incorrect_hevc.mkv", - HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO}, + HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_only_stream_hevc.mkv", - HDR_STATIC_INFO, null}, + HDR_STATIC_INFO, null, null, null}, {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10_only_container_hevc.mkv", - null, HDR_STATIC_INFO}, + null, HDR_STATIC_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_VP9, "cosmat_352x288_hdr10_only_container_vp9.mkv", - null, HDR_STATIC_INFO}, + null, HDR_STATIC_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_stream_and_container_correct_av1.mkv", - HDR_STATIC_INFO, HDR_STATIC_INFO}, + HDR_STATIC_INFO, HDR_STATIC_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_stream_correct_container_incorrect_av1.mkv", - HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO}, + HDR_STATIC_INFO, HDR_STATIC_INCORRECT_INFO, null, null}, {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_only_stream_av1.mkv", - HDR_STATIC_INFO, null}, + HDR_STATIC_INFO, null, null, null}, {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10_only_container_av1.mkv", - null, HDR_STATIC_INFO}, + null, HDR_STATIC_INFO, null, null}, + {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10plus_hevc.mp4", + null, null, HDR_DYNAMIC_INFO, null}, + {MediaFormat.MIMETYPE_VIDEO_HEVC, "cosmat_352x288_hdr10plus_hevc.mp4", + null, null, HDR_DYNAMIC_INFO, HDR_DYNAMIC_INCORRECT_INFO}, + {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10plus_av1.mkv", + null, null, HDR_DYNAMIC_INFO, null}, + {MediaFormat.MIMETYPE_VIDEO_AV1, "cosmat_352x288_hdr10plus_av1.mkv", + null, null, HDR_DYNAMIC_INFO, HDR_DYNAMIC_INCORRECT_INFO}, + {MediaFormat.MIMETYPE_VIDEO_VP9, "cosmat_352x288_hdr10_only_container_vp9.mkv", + null, null, null, HDR_DYNAMIC_INFO}, + }); return prepareParamList(exhaustiveArgsList, isEncoder, needAudio, needVideo, false); } @SmallTest @Test(timeout = PER_TEST_TIMEOUT_SMALL_TEST_MS) - public void testHDRMetadata() throws IOException, InterruptedException { - int[] Hdr10Profiles = mProfileHdr10Map.get(mMime); - Assume.assumeNotNull("Test is only applicable to codecs that have HDR10 profiles", - Hdr10Profiles); - MediaFormat format = setUpSource(mTestFile); - mExtractor.release(); - ArrayList<MediaFormat> formats = new ArrayList<>(); - formats.add(format); - - // When HDR metadata isn't present in the container, but included in the bitstream, - // extractors may not be able to populate HDR10/HDR10+ profiles correctly. - // In such cases, override the profile - if (mHDRStaticInfoContainer == null && mHDRStaticInfoStream != null) { - int profile = Hdr10Profiles[0]; - format.setInteger(MediaFormat.KEY_PROFILE, profile); - } - Assume.assumeTrue(areFormatsSupported(mCodecName, mMime, formats)); - - if (mHDRStaticInfoContainer != null) { - validateHDRStaticMetaData(format, mHDRStaticInfoContainer); - } - - validateHDRStaticMetaData(mInpPrefix, mTestFile, - mHDRStaticInfoStream == null ? mHDRStaticInfoContainer : mHDRStaticInfoStream, - false); - if (mHDRStaticInfoStream != null) { - if (EncoderHDRInfoTest.mCheckESList.contains(mMime)) { - validateHDRStaticMetaData(mInpPrefix, mTestFile, mHDRStaticInfoStream, true); - } - } + @CddTest(requirements = {"5.3.5/C-3-1", "5.3.7/C-4-1", "5.3.9"}) + public void testHDRInfo() throws IOException, InterruptedException { + validateHDRInfo(mHDRStaticInfoStream, mHDRStaticInfoContainer, mHDRDynamicInfoStream, + mHDRDynamicInfoContainer); } } diff --git a/tests/media/src/android/mediav2/cts/EncoderHDRInfoTest.java b/tests/media/src/android/mediav2/cts/EncoderHDRInfoTest.java index 26c6eb55920..66916e52df8 100644 --- a/tests/media/src/android/mediav2/cts/EncoderHDRInfoTest.java +++ b/tests/media/src/android/mediav2/cts/EncoderHDRInfoTest.java @@ -21,84 +21,59 @@ import android.media.MediaCodecList; import android.media.MediaFormat; import android.media.MediaMuxer; import android.os.Build; -import android.os.Bundle; +import android.util.Log; import androidx.test.filters.SdkSuppress; import androidx.test.filters.SmallTest; +import com.android.compatibility.common.util.CddTest; + +import org.junit.After; import org.junit.Assume; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; +import java.util.Map; import static android.media.MediaCodecInfo.CodecCapabilities.COLOR_FormatYUVP010; -import static android.media.MediaCodecInfo.CodecProfileLevel.*; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; /** - * Test to validate hdr static and dynamic metadata in encoders + * HDR10 Metadata is an aid for a display device to show the content in an optimal manner. It + * contains the HDR content and mastering device properties that are used by the display device + * to map the content according to its own color gamut and peak brightness. This information is + * part of the elementary stream. Generally this information is placed at scene change intervals + * or even at every frame level. If the encoder is configured with hdr info, then it is + * expected to place this information in the elementary stream as-is. This test validates the + * same. The test feeds per-frame or per-scene info at various points and expects the encoder + * to place the hdr info in the elementary stream at exactly those points + * + * Restrict hdr info test for Android T and above */ @RunWith(Parameterized.class) // P010 support was added in Android T, hence limit the following tests to Android T and above @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU, codeName = "Tiramisu") -public class EncoderHDRInfoTest extends CodecEncoderTestBase { +public class EncoderHDRInfoTest extends HDREncoderTestBase { private static final String LOG_TAG = EncoderHDRInfoTest.class.getSimpleName(); - private MediaMuxer mMuxer; - private int mTrackID = -1; - static final ArrayList<String> mCheckESList = new ArrayList<>(); - - static { - mCheckESList.add(MediaFormat.MIMETYPE_VIDEO_AV1); - mCheckESList.add(MediaFormat.MIMETYPE_VIDEO_AVC); - mCheckESList.add(MediaFormat.MIMETYPE_VIDEO_HEVC); - } + private String mHDRStaticInfo; + private Map<Integer, String> mHDRDynamicInfo; - public EncoderHDRInfoTest(String encoderName, String mediaType, int bitrate, int width, - int height, boolean testDynamicMetadata) { - super(encoderName, mediaType, new int[]{bitrate}, new int[]{width}, new int[]{height}); - mTestDynamicMetadata = testDynamicMetadata; - } - - void enqueueInput(int bufferIndex) { - if(mTestDynamicMetadata){ - final Bundle params = new Bundle(); - byte[] info = loadByteArrayFromString(HDR_DYNAMIC_INFO[mInputCount]); - params.putByteArray(MediaFormat.KEY_HDR10_PLUS_INFO, info); - mCodec.setParameters(params); - if (mInputCount >= HDR_DYNAMIC_INFO.length) { - mSawInputEOS = true; - } - } - super.enqueueInput(bufferIndex); - } - void dequeueOutput(int bufferIndex, MediaCodec.BufferInfo info) { - MediaFormat bufferFormat = mCodec.getOutputFormat(bufferIndex); - if (info.size > 0) { - ByteBuffer buf = mCodec.getOutputBuffer(bufferIndex); - if (mMuxer != null) { - if (mTrackID == -1) { - mTrackID = mMuxer.addTrack(bufferFormat); - mMuxer.start(); - } - mMuxer.writeSampleData(mTrackID, buf, info); - } - } - super.dequeueOutput(bufferIndex, info); - // verify if the out fmt contains HDR Dynamic metadata as expected - if (mTestDynamicMetadata && mOutputCount > 0) { - validateHDRDynamicMetaData(bufferFormat, - ByteBuffer.wrap(loadByteArrayFromString(HDR_DYNAMIC_INFO[mOutputCount - 1]))); - } + public EncoderHDRInfoTest(String encoderName, String mediaType, int bitrate, + int width, int height, String HDRStaticInfo, + Map<Integer, String> HDRDynamicInfo) { + super(encoderName, mediaType, bitrate, width, height); + mHDRStaticInfo = HDRStaticInfo; + mHDRDynamicInfo = HDRDynamicInfo; } @Parameterized.Parameters(name = "{index}({0}_{1})") @@ -106,111 +81,28 @@ public class EncoderHDRInfoTest extends CodecEncoderTestBase { final boolean isEncoder = true; final boolean needAudio = false; final boolean needVideo = true; - - final List<Object[]> exhaustiveArgsList = Arrays.asList(new Object[][]{ - {MediaFormat.MIMETYPE_VIDEO_AV1, 512000, 352, 288, false}, - {MediaFormat.MIMETYPE_VIDEO_VP9, 512000, 352, 288, false}, - {MediaFormat.MIMETYPE_VIDEO_HEVC, 512000, 352, 288, false}, - - {MediaFormat.MIMETYPE_VIDEO_AV1, 512000, 352, 288, true}, - {MediaFormat.MIMETYPE_VIDEO_VP9, 512000, 352, 288, true}, - {MediaFormat.MIMETYPE_VIDEO_HEVC, 512000, 352, 288, true}, - }); + final String[] mediaTypes = new String[]{ + MediaFormat.MIMETYPE_VIDEO_AV1, + MediaFormat.MIMETYPE_VIDEO_HEVC, + MediaFormat.MIMETYPE_VIDEO_VP9 + }; + + final List<Object[]> exhaustiveArgsList = new ArrayList<>(); + for (String mediaType : mediaTypes) { + // mediaType, bitrate, width, height, hdrStaticInfo, hdrDynamicInfo + exhaustiveArgsList.add(new Object[]{mediaType, 512000, 352, 288, HDR_STATIC_INFO, + null}); + exhaustiveArgsList.add(new Object[]{mediaType, 512000, 352, 288, null, + HDR_DYNAMIC_INFO}); + } return prepareParamList(exhaustiveArgsList, isEncoder, needAudio, needVideo, false); } @SmallTest @Test(timeout = PER_TEST_TIMEOUT_SMALL_TEST_MS) - public void testHDRMetadata() throws IOException, InterruptedException { - int profile; - setUpParams(1); - MediaFormat format = mFormats.get(0); - final ByteBuffer hdrStaticInfo = ByteBuffer.wrap(loadByteArrayFromString(HDR_STATIC_INFO)); - if (mTestDynamicMetadata) { - profile = mProfileHdr10PlusMap.getOrDefault(mMime, new int[]{-1})[0]; - } else { - profile = mProfileHdr10Map.getOrDefault(mMime, new int[]{-1})[0]; - } - format.setInteger(MediaFormat.KEY_PROFILE, profile); - format.setInteger(MediaFormat.KEY_COLOR_FORMAT, COLOR_FormatYUVP010); - format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_LIMITED); - format.setInteger(MediaFormat.KEY_COLOR_STANDARD, MediaFormat.COLOR_STANDARD_BT2020); - format.setInteger(MediaFormat.KEY_COLOR_TRANSFER, MediaFormat.COLOR_TRANSFER_ST2084); - format.setByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO, hdrStaticInfo); - mFormats.clear(); - mFormats.add(format); - Assume.assumeTrue(mCodecName + " does not support this HDR profile", - areFormatsSupported(mCodecName, mMime, mFormats)); - Assume.assumeTrue(mCodecName + " does not support color format COLOR_FormatYUVP010", - hasSupportForColorFormat(mCodecName, mMime, COLOR_FormatYUVP010)); - mBytesPerSample = 2; - setUpSource(INPUT_VIDEO_FILE_HBD); - mOutputBuff = new OutputManager(); - mCodec = MediaCodec.createByCodecName(mCodecName); - mOutputBuff.reset(); - String log = String.format("format: %s \n codec: %s:: ", format, mCodecName); - File tmpFile; - int muxerFormat; - if (mMime.equals(MediaFormat.MIMETYPE_VIDEO_VP9)) { - muxerFormat = MediaMuxer.OutputFormat.MUXER_OUTPUT_WEBM; - tmpFile = File.createTempFile("tmp10bit", ".webm"); - } else { - muxerFormat = MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4; - tmpFile = File.createTempFile("tmp10bit", ".mp4"); - } - mMuxer = new MediaMuxer(tmpFile.getAbsolutePath(), muxerFormat); - configureCodec(format, true, true, true); - mCodec.start(); - doWork(4); - queueEOS(); - waitForAllOutputs(); - if (mTrackID != -1) { - mMuxer.stop(); - mTrackID = -1; - } - if (mMuxer != null) { - mMuxer.release(); - mMuxer = null; - } - assertTrue(log + "unexpected error", !mAsyncHandle.hasSeenError()); - assertTrue(log + "no input sent", 0 != mInputCount); - assertTrue(log + "output received", 0 != mOutputCount); - - MediaFormat fmt = mCodec.getOutputFormat(); - mCodec.stop(); - mCodec.release(); - - // verify if the out fmt contains HDR Static metadata as expected - validateHDRStaticMetaData(fmt, hdrStaticInfo); - - // verify if the muxed file contains HDR metadata as expected - MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS); - String decoder = codecList.findDecoderForFormat(format); - assertNotNull("Device advertises support for encoding " + format.toString() + - " but not decoding it", decoder); - CodecDecoderTestBase cdtb = - new CodecDecoderTestBase(decoder, mMime, tmpFile.getAbsolutePath()); - String parent = tmpFile.getParent(); - if (parent != null) parent += File.separator; - else parent = ""; - cdtb.validateHDRStaticMetaData(parent, tmpFile.getName(), hdrStaticInfo, false); - if (mTestDynamicMetadata) { - cdtb.validateHDRDynamicMetaData(parent, tmpFile.getName(), false); - } - - // if HDR static metadata can also be signalled via elementary stream then verify if - // the elementary stream contains HDR static data as expected - if (mCheckESList.contains(mMime)) { - cdtb.validateHDRStaticMetaData(parent, tmpFile.getName(), hdrStaticInfo, true); - - // since HDR static metadata is signalled via elementary stream then verify if - // the elementary stream contains HDR static data as expected - if (mTestDynamicMetadata) { - cdtb.validateHDRDynamicMetaData(parent, tmpFile.getName(), true); - } - } - - tmpFile.delete(); + @CddTest(requirements = {"5.12/C-6-4"}) + public void testHDRInfo() throws IOException, InterruptedException { + validateHDRInfo(mHDRStaticInfo, mHDRDynamicInfo); } } diff --git a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java index 55eb2556d32..474d48840aa 100644 --- a/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java +++ b/tests/tests/wifi/src/android/net/wifi/cts/WifiManagerTest.java @@ -3911,6 +3911,14 @@ public class WifiManagerTest extends WifiJUnit3TestBase { @SdkSuppress(minSdkVersion = Build.VERSION_CODES.TIRAMISU) public void testActiveCountryCodeChangedCallback() throws Exception { + if (!hasLocationFeature()) { + // skip the test if location is not supported + return; + } + if (!isLocationEnabled()) { + fail("Please enable location for this test - since country code is not available" + + " when location is disabled!"); + } TestActiveCountryCodeChangedCallback testCountryCodeChangedCallback = new TestActiveCountryCodeChangedCallback(); TestExecutor executor = new TestExecutor(); diff --git a/tests/uwb/src/android/uwb/cts/RangingSessionTest.java b/tests/uwb/src/android/uwb/cts/RangingSessionTest.java deleted file mode 100644 index ef651da34da..00000000000 --- a/tests/uwb/src/android/uwb/cts/RangingSessionTest.java +++ /dev/null @@ -1,637 +0,0 @@ -/* - * Copyright (C) 2021 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.uwb.cts; - -import static android.uwb.RangingSession.Callback.REASON_BAD_PARAMETERS; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyInt; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doAnswer; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; - -import android.content.AttributionSource; -import android.os.PersistableBundle; -import android.os.Process; -import android.os.RemoteException; -import android.uwb.IUwbAdapter; -import android.uwb.RangingReport; -import android.uwb.RangingSession; -import android.uwb.SessionHandle; -import android.uwb.UwbAddress; - -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.SmallTest; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; - -import java.util.concurrent.Executor; - -/** - * Test of {@link RangingSession}. - */ -@SmallTest -@RunWith(AndroidJUnit4.class) -public class RangingSessionTest { - private static final Executor EXECUTOR = UwbTestUtils.getExecutor(); - private static final PersistableBundle PARAMS = new PersistableBundle(); - private static final UwbAddress UWB_ADDRESS = UwbAddress.fromBytes(new byte[] {0x00, 0x56}); - private static final @RangingSession.Callback.Reason int REASON = - RangingSession.Callback.REASON_GENERIC_ERROR; - private static final int UID = Process.myUid(); - private static final String PACKAGE_NAME = "com.uwb.test"; - private static final AttributionSource ATTRIBUTION_SOURCE = - new AttributionSource.Builder(UID).setPackageName(PACKAGE_NAME).build(); - private static final int HANDLE_ID = 12; - private static final int PID = Process.myPid(); - - @Test - public void testOnRangingOpened_OnOpenSuccessCalled() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - verifyOpenState(session, false); - - session.onRangingOpened(); - verifyOpenState(session, true); - - // Verify that the onOpenSuccess callback was invoked - verify(callback, times(1)).onOpened(eq(session)); - verify(callback, times(0)).onClosed(anyInt(), any()); - } - - @Test - public void testOnRangingOpened_OnServiceDiscoveredConnectedCalled() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - verifyOpenState(session, false); - - session.onRangingOpened(); - verifyOpenState(session, true); - - // Verify that the onOpenSuccess callback was invoked - verify(callback, times(1)).onOpened(eq(session)); - verify(callback, times(0)).onClosed(anyInt(), any()); - - session.onServiceDiscovered(PARAMS); - verify(callback, times(1)).onServiceDiscovered(eq(PARAMS)); - - session.onServiceConnected(PARAMS); - verify(callback, times(1)).onServiceConnected(eq(PARAMS)); - } - - - @Test - public void testOnRangingOpened_CannotOpenClosedSession() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - - session.onRangingOpened(); - verifyOpenState(session, true); - verify(callback, times(1)).onOpened(eq(session)); - verify(callback, times(0)).onClosed(anyInt(), any()); - - session.onRangingClosed(REASON, PARAMS); - verifyOpenState(session, false); - verify(callback, times(1)).onOpened(eq(session)); - verify(callback, times(1)).onClosed(anyInt(), any()); - - // Now invoke the ranging started callback and ensure the session remains closed - session.onRangingOpened(); - verifyOpenState(session, false); - verify(callback, times(1)).onOpened(eq(session)); - verify(callback, times(1)).onClosed(anyInt(), any()); - } - - @Test - public void testOnRangingClosed_OnClosedCalledWhenSessionNotOpen() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - verifyOpenState(session, false); - - session.onRangingClosed(REASON, PARAMS); - verifyOpenState(session, false); - - // Verify that the onOpenSuccess callback was invoked - verify(callback, times(0)).onOpened(eq(session)); - verify(callback, times(1)).onClosed(anyInt(), any()); - } - - @Test - public void testOnRangingClosed_OnClosedCalled() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - session.onRangingStarted(PARAMS); - session.onRangingClosed(REASON, PARAMS); - verify(callback, times(1)).onClosed(anyInt(), any()); - - verifyOpenState(session, false); - session.onRangingClosed(REASON, PARAMS); - verify(callback, times(2)).onClosed(anyInt(), any()); - } - - @Test - public void testOnRangingResult_OnReportReceivedCalled() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - verifyOpenState(session, false); - - session.onRangingStarted(PARAMS); - verifyOpenState(session, true); - - RangingReport report = UwbTestUtils.getRangingReports(1); - session.onRangingResult(report); - verify(callback, times(1)).onReportReceived(eq(report)); - } - - @Test - public void testStart_CannotStartIfAlreadyStarted() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new StartAnswer(session)).when(adapter).startRanging(any(), any()); - session.onRangingOpened(); - - session.start(PARAMS); - verify(callback, times(1)).onStarted(any()); - - // Calling start again should throw an illegal state - verifyThrowIllegalState(() -> session.start(PARAMS)); - verify(callback, times(1)).onStarted(any()); - } - - @Test - public void testStop_CannotStopIfAlreadyStopped() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new StartAnswer(session)).when(adapter).startRanging(any(), any()); - doAnswer(new StopAnswer(session)).when(adapter).stopRanging(any()); - session.onRangingOpened(); - session.start(PARAMS); - - verifyNoThrowIllegalState(session::stop); - verify(callback, times(1)).onStopped(anyInt(), any()); - - // Calling stop again should throw an illegal state - verifyThrowIllegalState(session::stop); - verify(callback, times(1)).onStopped(anyInt(), any()); - } - - @Test - public void testStop_CannotStopIfOpenFailed() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new StartAnswer(session)).when(adapter).startRanging(any(), any()); - doAnswer(new StopAnswer(session)).when(adapter).stopRanging(any()); - session.onRangingOpened(); - session.start(PARAMS); - - verifyNoThrowIllegalState(() -> session.onRangingOpenFailed(REASON_BAD_PARAMETERS, PARAMS)); - verify(callback, times(1)).onOpenFailed( - REASON_BAD_PARAMETERS, PARAMS); - - // Calling stop again should throw an illegal state - verifyThrowIllegalState(session::stop); - verify(callback, times(0)).onStopped(anyInt(), any()); - } - - @Test - public void testCallbacks_OnlyWhenOpened() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new OpenAnswer(session)).when(adapter).openRanging( - any(), any(), any(), any(), any()); - doAnswer(new StartAnswer(session)).when(adapter).startRanging(any(), any()); - doAnswer(new ReconfigureAnswer(session)).when(adapter).reconfigureRanging(any(), any()); - doAnswer(new PauseAnswer(session)).when(adapter).pause(any(), any()); - doAnswer(new ResumeAnswer(session)).when(adapter).resume(any(), any()); - doAnswer(new ControleeAddAnswer(session)).when(adapter).addControlee(any(), any()); - doAnswer(new ControleeRemoveAnswer(session)).when(adapter).removeControlee(any(), any()); - doAnswer(new DataSendAnswer(session)).when(adapter).sendData(any(), any(), any(), any()); - doAnswer(new StopAnswer(session)).when(adapter).stopRanging(any()); - doAnswer(new CloseAnswer(session)).when(adapter).closeRanging(any()); - - verifyThrowIllegalState(() -> session.reconfigure(PARAMS)); - verify(callback, times(0)).onReconfigured(any()); - verifyOpenState(session, false); - - session.onRangingOpened(); - verifyOpenState(session, true); - verify(callback, times(1)).onOpened(any()); - verifyNoThrowIllegalState(() -> session.reconfigure(PARAMS)); - verify(callback, times(1)).onReconfigured(any()); - verifyThrowIllegalState(() -> session.pause(PARAMS)); - verify(callback, times(0)).onPaused(any()); - verifyThrowIllegalState(() -> session.resume(PARAMS)); - verify(callback, times(0)).onResumed(any()); - verifyNoThrowIllegalState(() -> session.addControlee(PARAMS)); - verify(callback, times(1)).onControleeAdded(any()); - verifyNoThrowIllegalState(() -> session.removeControlee(PARAMS)); - verify(callback, times(1)).onControleeRemoved(any()); - verifyThrowIllegalState(() -> session.sendData( - UWB_ADDRESS, PARAMS, new byte[] {0x05, 0x1})); - verify(callback, times(0)).onDataSent(any(), any()); - - session.onRangingStartFailed(REASON_BAD_PARAMETERS, PARAMS); - verifyOpenState(session, true); - verify(callback, times(1)).onStartFailed( - REASON_BAD_PARAMETERS, PARAMS); - - session.onRangingStarted(PARAMS); - verifyOpenState(session, true); - verifyNoThrowIllegalState(() -> session.reconfigure(PARAMS)); - verify(callback, times(2)).onReconfigured(any()); - verifyNoThrowIllegalState(() -> session.reconfigure(null)); - verify(callback, times(1)).onReconfigureFailed( - eq(REASON_BAD_PARAMETERS), any()); - verifyNoThrowIllegalState(() -> session.pause(PARAMS)); - verify(callback, times(1)).onPaused(any()); - verifyNoThrowIllegalState(() -> session.pause(null)); - verify(callback, times(1)).onPauseFailed( - eq(REASON_BAD_PARAMETERS), any()); - verifyNoThrowIllegalState(() -> session.resume(PARAMS)); - verify(callback, times(1)).onResumed(any()); - verifyNoThrowIllegalState(() -> session.resume(null)); - verify(callback, times(1)).onResumeFailed( - eq(REASON_BAD_PARAMETERS), any()); - verifyNoThrowIllegalState(() -> session.addControlee(PARAMS)); - verify(callback, times(2)).onControleeAdded(any()); - verifyNoThrowIllegalState(() -> session.addControlee(null)); - verify(callback, times(1)).onControleeAddFailed( - eq(REASON_BAD_PARAMETERS), any()); - verifyNoThrowIllegalState(() -> session.removeControlee(PARAMS)); - verify(callback, times(2)).onControleeRemoved(any()); - verifyNoThrowIllegalState(() -> session.removeControlee(null)); - verify(callback, times(1)).onControleeRemoveFailed( - eq(REASON_BAD_PARAMETERS), any()); - verifyNoThrowIllegalState(() -> session.sendData( - UWB_ADDRESS, PARAMS, new byte[] {0x05, 0x1})); - verify(callback, times(1)).onDataSent(any(), any()); - verifyNoThrowIllegalState(() -> session.sendData( - null, PARAMS, new byte[] {0x05, 0x1})); - verify(callback, times(1)).onDataSendFailed( - eq(null), eq(REASON_BAD_PARAMETERS), any()); - - session.onDataReceived(UWB_ADDRESS, PARAMS, new byte[] {0x5, 0x7}); - verify(callback, times(1)).onDataReceived( - UWB_ADDRESS, PARAMS, new byte[] {0x5, 0x7}); - session.onDataReceiveFailed(UWB_ADDRESS, REASON_BAD_PARAMETERS, PARAMS); - verify(callback, times(1)).onDataReceiveFailed( - UWB_ADDRESS, REASON_BAD_PARAMETERS, PARAMS); - - session.stop(); - verifyOpenState(session, true); - verify(callback, times(1)).onStopped(REASON, PARAMS); - - verifyNoThrowIllegalState(() -> session.reconfigure(PARAMS)); - verify(callback, times(3)).onReconfigured(any()); - verifyThrowIllegalState(() -> session.pause(PARAMS)); - verify(callback, times(1)).onPaused(any()); - verifyThrowIllegalState(() -> session.resume(PARAMS)); - verify(callback, times(1)).onResumed(any()); - verifyNoThrowIllegalState(() -> session.addControlee(PARAMS)); - verify(callback, times(3)).onControleeAdded(any()); - verifyNoThrowIllegalState(() -> session.removeControlee(PARAMS)); - verify(callback, times(3)).onControleeRemoved(any()); - verifyThrowIllegalState(() -> session.sendData( - UWB_ADDRESS, PARAMS, new byte[] {0x05, 0x1})); - verify(callback, times(1)).onDataSent(any(), any()); - - session.close(); - verifyOpenState(session, false); - verify(callback, times(1)).onClosed(REASON, PARAMS); - - verifyThrowIllegalState(() -> session.reconfigure(PARAMS)); - verify(callback, times(3)).onReconfigured(any()); - verifyThrowIllegalState(() -> session.pause(PARAMS)); - verify(callback, times(1)).onPaused(any()); - verifyThrowIllegalState(() -> session.resume(PARAMS)); - verify(callback, times(1)).onResumed(any()); - verifyThrowIllegalState(() -> session.addControlee(PARAMS)); - verify(callback, times(3)).onControleeAdded(any()); - verifyThrowIllegalState(() -> session.removeControlee(PARAMS)); - verify(callback, times(3)).onControleeRemoved(any()); - verifyThrowIllegalState(() -> session.sendData( - UWB_ADDRESS, PARAMS, new byte[] {0x05, 0x1})); - verify(callback, times(1)).onDataSent(any(), any()); - } - - @Test - public void testClose_NoCallbackUntilInvoked() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - session.onRangingOpened(); - - // Calling close multiple times should invoke closeRanging until the session receives - // the onClosed callback. - int totalCallsBeforeOnRangingClosed = 3; - for (int i = 1; i <= totalCallsBeforeOnRangingClosed; i++) { - session.close(); - verifyOpenState(session, true); - verify(adapter, times(i)).closeRanging(handle); - verify(callback, times(0)).onClosed(anyInt(), any()); - } - - // After onClosed is invoked, then the adapter should no longer be called for each call to - // the session's close. - final int totalCallsAfterOnRangingClosed = 2; - for (int i = 1; i <= totalCallsAfterOnRangingClosed; i++) { - session.onRangingClosed(REASON, PARAMS); - verifyOpenState(session, false); - verify(adapter, times(totalCallsBeforeOnRangingClosed)).closeRanging(handle); - verify(callback, times(i)).onClosed(anyInt(), any()); - } - } - - @Test - public void testClose_OnClosedCalled() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new CloseAnswer(session)).when(adapter).closeRanging(any()); - session.onRangingOpened(); - - session.close(); - verify(callback, times(1)).onClosed(anyInt(), any()); - } - - @Test - public void testClose_CannotInteractFurther() throws RemoteException { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - doAnswer(new CloseAnswer(session)).when(adapter).closeRanging(any()); - session.close(); - - verifyThrowIllegalState(() -> session.start(PARAMS)); - verifyThrowIllegalState(() -> session.reconfigure(PARAMS)); - verifyThrowIllegalState(() -> session.stop()); - verifyNoThrowIllegalState(() -> session.close()); - } - - @Test - public void testOnRangingResult_OnReportReceivedCalledWhenOpen() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - - assertFalse(session.isOpen()); - session.onRangingStarted(PARAMS); - assertTrue(session.isOpen()); - - // Verify that the onReportReceived callback was invoked - RangingReport report = UwbTestUtils.getRangingReports(1); - session.onRangingResult(report); - verify(callback, times(1)).onReportReceived(report); - } - - @Test - public void testOnRangingResult_OnReportReceivedNotCalledWhenNotOpen() { - SessionHandle handle = new SessionHandle(HANDLE_ID, ATTRIBUTION_SOURCE, PID); - RangingSession.Callback callback = mock(RangingSession.Callback.class); - IUwbAdapter adapter = mock(IUwbAdapter.class); - RangingSession session = new RangingSession(EXECUTOR, callback, adapter, handle); - - assertFalse(session.isOpen()); - - // Verify that the onReportReceived callback was invoked - RangingReport report = UwbTestUtils.getRangingReports(1); - session.onRangingResult(report); - verify(callback, times(0)).onReportReceived(report); - } - - private void verifyOpenState(RangingSession session, boolean expected) { - assertEquals(expected, session.isOpen()); - } - - private void verifyThrowIllegalState(Runnable runnable) { - try { - runnable.run(); - fail(); - } catch (IllegalStateException e) { - // Pass - } - } - - private void verifyNoThrowIllegalState(Runnable runnable) { - try { - runnable.run(); - } catch (IllegalStateException e) { - fail(); - } - } - - abstract class AdapterAnswer implements Answer { - protected RangingSession mSession; - - protected AdapterAnswer(RangingSession session) { - mSession = session; - } - } - - class OpenAnswer extends AdapterAnswer { - OpenAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onRangingOpened(); - } else { - mSession.onRangingOpenFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class StartAnswer extends AdapterAnswer { - StartAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onRangingStarted(PARAMS); - } else { - mSession.onRangingStartFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class ReconfigureAnswer extends AdapterAnswer { - ReconfigureAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onRangingReconfigured(PARAMS); - } else { - mSession.onRangingReconfigureFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class PauseAnswer extends AdapterAnswer { - PauseAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onRangingPaused(PARAMS); - } else { - mSession.onRangingPauseFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class ResumeAnswer extends AdapterAnswer { - ResumeAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onRangingResumed(PARAMS); - } else { - mSession.onRangingResumeFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class ControleeAddAnswer extends AdapterAnswer { - ControleeAddAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onControleeAdded(PARAMS); - } else { - mSession.onControleeAddFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class ControleeRemoveAnswer extends AdapterAnswer { - ControleeRemoveAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - PersistableBundle argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onControleeRemoved(PARAMS); - } else { - mSession.onControleeRemoveFailed(REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class DataSendAnswer extends AdapterAnswer { - DataSendAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - UwbAddress argParams = invocation.getArgument(1); - if (argParams != null) { - mSession.onDataSent(UWB_ADDRESS, PARAMS); - } else { - mSession.onDataSendFailed(null, REASON_BAD_PARAMETERS, PARAMS); - } - return null; - } - } - - class StopAnswer extends AdapterAnswer { - StopAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - mSession.onRangingStopped(REASON, PARAMS); - return null; - } - } - - class CloseAnswer extends AdapterAnswer { - CloseAnswer(RangingSession session) { - super(session); - } - - @Override - public Object answer(InvocationOnMock invocation) { - mSession.onRangingClosed(REASON, PARAMS); - return null; - } - } -} |