Statically import Assertions
methods in FakeExoMediaDrm
PiperOrigin-RevId: 613578959
This commit is contained in:
parent
a604600126
commit
0ff80d7da0
@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package androidx.media3.test.utils;
|
package androidx.media3.test.utils;
|
||||||
|
|
||||||
|
import static androidx.media3.common.util.Assertions.checkArgument;
|
||||||
|
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||||
import static androidx.media3.common.util.Assertions.checkState;
|
import static androidx.media3.common.util.Assertions.checkState;
|
||||||
|
|
||||||
import android.media.DeniedByServerException;
|
import android.media.DeniedByServerException;
|
||||||
@ -30,7 +32,6 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
import androidx.media3.common.DrmInitData;
|
import androidx.media3.common.DrmInitData;
|
||||||
import androidx.media3.common.util.Assertions;
|
|
||||||
import androidx.media3.common.util.UnstableApi;
|
import androidx.media3.common.util.UnstableApi;
|
||||||
import androidx.media3.common.util.Util;
|
import androidx.media3.common.util.Util;
|
||||||
import androidx.media3.decoder.CryptoConfig;
|
import androidx.media3.decoder.CryptoConfig;
|
||||||
@ -268,7 +269,7 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] openSession() throws MediaDrmException {
|
public byte[] openSession() throws MediaDrmException {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
if (!throwNotProvisionedExceptionFromGetKeyRequest && provisionsReceived < provisionsRequired) {
|
if (!throwNotProvisionedExceptionFromGetKeyRequest && provisionsReceived < provisionsRequired) {
|
||||||
throwNotProvisionedException();
|
throwNotProvisionedException();
|
||||||
}
|
}
|
||||||
@ -294,9 +295,9 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void closeSession(byte[] sessionId) {
|
public void closeSession(byte[] sessionId) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
// TODO: Store closed session IDs too?
|
// TODO: Store closed session IDs too?
|
||||||
Assertions.checkState(openSessionIds.remove(toByteList(sessionId)));
|
checkState(openSessionIds.remove(toByteList(sessionId)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -306,16 +307,16 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
int keyType,
|
int keyType,
|
||||||
@Nullable HashMap<String, String> optionalParameters)
|
@Nullable HashMap<String, String> optionalParameters)
|
||||||
throws NotProvisionedException {
|
throws NotProvisionedException {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
if (keyType == KEY_TYPE_OFFLINE || keyType == KEY_TYPE_RELEASE) {
|
if (keyType == KEY_TYPE_OFFLINE || keyType == KEY_TYPE_RELEASE) {
|
||||||
throw new UnsupportedOperationException("Offline key requests are not supported.");
|
throw new UnsupportedOperationException("Offline key requests are not supported.");
|
||||||
}
|
}
|
||||||
Assertions.checkArgument(keyType == KEY_TYPE_STREAMING, "Unrecognised keyType: " + keyType);
|
checkArgument(keyType == KEY_TYPE_STREAMING, "Unrecognised keyType: " + keyType);
|
||||||
if (throwNotProvisionedExceptionFromGetKeyRequest && provisionsReceived < provisionsRequired) {
|
if (throwNotProvisionedExceptionFromGetKeyRequest && provisionsReceived < provisionsRequired) {
|
||||||
throwNotProvisionedException();
|
throwNotProvisionedException();
|
||||||
}
|
}
|
||||||
Assertions.checkState(openSessionIds.contains(toByteList(scope)));
|
checkState(openSessionIds.contains(toByteList(scope)));
|
||||||
Assertions.checkNotNull(schemeDatas);
|
checkNotNull(schemeDatas);
|
||||||
KeyRequestData requestData =
|
KeyRequestData requestData =
|
||||||
new KeyRequestData(
|
new KeyRequestData(
|
||||||
schemeDatas,
|
schemeDatas,
|
||||||
@ -332,7 +333,7 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
@Override
|
@Override
|
||||||
public byte[] provideKeyResponse(byte[] scope, byte[] response)
|
public byte[] provideKeyResponse(byte[] scope, byte[] response)
|
||||||
throws NotProvisionedException, DeniedByServerException {
|
throws NotProvisionedException, DeniedByServerException {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
List<Byte> responseAsList = Bytes.asList(response);
|
List<Byte> responseAsList = Bytes.asList(response);
|
||||||
if (responseAsList.equals(KEY_DENIED_RESPONSE)) {
|
if (responseAsList.equals(KEY_DENIED_RESPONSE)) {
|
||||||
throw new DeniedByServerException("Key request denied");
|
throw new DeniedByServerException("Key request denied");
|
||||||
@ -353,13 +354,13 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ProvisionRequest getProvisionRequest() {
|
public ProvisionRequest getProvisionRequest() {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
return FAKE_PROVISION_REQUEST;
|
return FAKE_PROVISION_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void provideProvisionResponse(byte[] response) throws DeniedByServerException {
|
public void provideProvisionResponse(byte[] response) throws DeniedByServerException {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
if (Bytes.asList(response).equals(VALID_PROVISION_RESPONSE)) {
|
if (Bytes.asList(response).equals(VALID_PROVISION_RESPONSE)) {
|
||||||
provisionsReceived++;
|
provisionsReceived++;
|
||||||
}
|
}
|
||||||
@ -367,8 +368,8 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, String> queryKeyStatus(byte[] sessionId) {
|
public Map<String, String> queryKeyStatus(byte[] sessionId) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
Assertions.checkState(openSessionIds.contains(toByteList(sessionId)));
|
checkState(openSessionIds.contains(toByteList(sessionId)));
|
||||||
return ImmutableMap.of(
|
return ImmutableMap.of(
|
||||||
KEY_STATUS_KEY,
|
KEY_STATUS_KEY,
|
||||||
sessionIdsWithValidKeys.contains(toByteList(sessionId))
|
sessionIdsWithValidKeys.contains(toByteList(sessionId))
|
||||||
@ -383,7 +384,7 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void acquire() {
|
public void acquire() {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
referenceCount++;
|
referenceCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -400,14 +401,14 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public PersistableBundle getMetrics() {
|
public PersistableBundle getMetrics() {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPropertyString(String propertyName) {
|
public String getPropertyString(String propertyName) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
@Nullable String value = stringProperties.get(propertyName);
|
@Nullable String value = stringProperties.get(propertyName);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalArgumentException("Unrecognized propertyName: " + propertyName);
|
throw new IllegalArgumentException("Unrecognized propertyName: " + propertyName);
|
||||||
@ -417,7 +418,7 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] getPropertyByteArray(String propertyName) {
|
public byte[] getPropertyByteArray(String propertyName) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
@Nullable byte[] value = byteProperties.get(propertyName);
|
@Nullable byte[] value = byteProperties.get(propertyName);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalArgumentException("Unrecognized propertyName: " + propertyName);
|
throw new IllegalArgumentException("Unrecognized propertyName: " + propertyName);
|
||||||
@ -427,20 +428,20 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPropertyString(String propertyName, String value) {
|
public void setPropertyString(String propertyName, String value) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
stringProperties.put(propertyName, value);
|
stringProperties.put(propertyName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setPropertyByteArray(String propertyName, byte[] value) {
|
public void setPropertyByteArray(String propertyName, byte[] value) {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
byteProperties.put(propertyName, value);
|
byteProperties.put(propertyName, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CryptoConfig createCryptoConfig(byte[] sessionId) throws MediaCryptoException {
|
public CryptoConfig createCryptoConfig(byte[] sessionId) throws MediaCryptoException {
|
||||||
Assertions.checkState(referenceCount > 0);
|
checkState(referenceCount > 0);
|
||||||
Assertions.checkState(openSessionIds.contains(toByteList(sessionId)));
|
checkState(openSessionIds.contains(toByteList(sessionId)));
|
||||||
return new FakeCryptoConfig();
|
return new FakeCryptoConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,9 +604,9 @@ public final class FakeExoMediaDrm implements ExoMediaDrm {
|
|||||||
this.type = in.readInt();
|
this.type = in.readInt();
|
||||||
|
|
||||||
ImmutableMap.Builder<String, String> optionalParameters = new ImmutableMap.Builder<>();
|
ImmutableMap.Builder<String, String> optionalParameters = new ImmutableMap.Builder<>();
|
||||||
List<String> optionalParameterKeys = Assertions.checkNotNull(in.createStringArrayList());
|
List<String> optionalParameterKeys = checkNotNull(in.createStringArrayList());
|
||||||
List<String> optionalParameterValues = Assertions.checkNotNull(in.createStringArrayList());
|
List<String> optionalParameterValues = checkNotNull(in.createStringArrayList());
|
||||||
Assertions.checkArgument(optionalParameterKeys.size() == optionalParameterValues.size());
|
checkArgument(optionalParameterKeys.size() == optionalParameterValues.size());
|
||||||
for (int i = 0; i < optionalParameterKeys.size(); i++) {
|
for (int i = 0; i < optionalParameterKeys.size(); i++) {
|
||||||
optionalParameters.put(optionalParameterKeys.get(i), optionalParameterValues.get(i));
|
optionalParameters.put(optionalParameterKeys.get(i), optionalParameterValues.get(i));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user