Skip to content

Commit

Permalink
Remove unnecessary DefaultKeyStatus, DefaultKeyRequest and DefaultPro…
Browse files Browse the repository at this point in the history
…visionRequest.

Currently, we have KeyStatus, KeyRequest and ProvisionRequest as interface, so we can use
custom implementation for purpose such as wrapping native objects. However, these interfaces and the corresponding default classes are only used to bundle data, and in all existing implementation (including native code), it's just as efficient to just use the Java default implementation. Therefore we can just get rid of the interfaces, and change
the interfaces into classes with the default implementation.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=206765389
  • Loading branch information
botaydotcom authored and ojw28 committed Aug 1, 2018
1 parent 7ead310 commit 377314a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,101 +105,63 @@ void onKeyStatusChange(
boolean hasNewUsableKey);
}

/**
* @see android.media.MediaDrm.KeyStatus
*/
interface KeyStatus {
/** Returns the status code for the key. */
int getStatusCode();
/** Returns the id for the key. */
byte[] getKeyId();
}

/**
* Default implementation of {@link KeyStatus}.
*/
final class DefaultKeyStatus implements KeyStatus {
/** @see android.media.MediaDrm.KeyStatus */
final class KeyStatus {

private final int statusCode;
private final byte[] keyId;

DefaultKeyStatus(int statusCode, byte[] keyId) {
public KeyStatus(int statusCode, byte[] keyId) {
this.statusCode = statusCode;
this.keyId = keyId;
}

@Override
public int getStatusCode() {
return statusCode;
}

@Override
public byte[] getKeyId() {
return keyId;
}

}

/**
* @see android.media.MediaDrm.KeyRequest
*/
interface KeyRequest {
byte[] getData();
String getDefaultUrl();
}

/**
* Default implementation of {@link KeyRequest}.
*/
final class DefaultKeyRequest implements KeyRequest {
/** @see android.media.MediaDrm.KeyRequest */
final class KeyRequest {

private final byte[] data;
private final String defaultUrl;

public DefaultKeyRequest(byte[] data, String defaultUrl) {
public KeyRequest(byte[] data, String defaultUrl) {
this.data = data;
this.defaultUrl = defaultUrl;
}

@Override
public byte[] getData() {
return data;
}

@Override
public String getDefaultUrl() {
return defaultUrl;
}

}

/**
* @see android.media.MediaDrm.ProvisionRequest
*/
interface ProvisionRequest {
byte[] getData();
String getDefaultUrl();
}

/**
* Default implementation of {@link ProvisionRequest}.
*/
final class DefaultProvisionRequest implements ProvisionRequest {
/** @see android.media.MediaDrm.ProvisionRequest */
final class ProvisionRequest {

private final byte[] data;
private final String defaultUrl;

public DefaultProvisionRequest(byte[] data, String defaultUrl) {
public ProvisionRequest(byte[] data, String defaultUrl) {
this.data = data;
this.defaultUrl = defaultUrl;
}

@Override
public byte[] getData() {
return data;
}

@Override
public String getDefaultUrl() {
return defaultUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,26 @@ public void setOnKeyStatusChangeListener(
if (Util.SDK_INT < 23) {
throw new UnsupportedOperationException();
}

mediaDrm.setOnKeyStatusChangeListener(listener == null ? null
: new MediaDrm.OnKeyStatusChangeListener() {
@Override
public void onKeyStatusChange(@NonNull MediaDrm md, @NonNull byte[] sessionId,
@NonNull List<MediaDrm.KeyStatus> keyInfo, boolean hasNewUsableKey) {
List<KeyStatus> exoKeyInfo = new ArrayList<>();
for (MediaDrm.KeyStatus keyStatus : keyInfo) {
exoKeyInfo.add(new DefaultKeyStatus(keyStatus.getStatusCode(), keyStatus.getKeyId()));
}
listener.onKeyStatusChange(FrameworkMediaDrm.this, sessionId, exoKeyInfo,
hasNewUsableKey);
}
}, null);

mediaDrm.setOnKeyStatusChangeListener(
listener == null
? null
: new MediaDrm.OnKeyStatusChangeListener() {
@Override
public void onKeyStatusChange(
@NonNull MediaDrm md,
@NonNull byte[] sessionId,
@NonNull List<MediaDrm.KeyStatus> keyInfo,
boolean hasNewUsableKey) {
List<KeyStatus> exoKeyInfo = new ArrayList<>();
for (MediaDrm.KeyStatus keyStatus : keyInfo) {
exoKeyInfo.add(new KeyStatus(keyStatus.getStatusCode(), keyStatus.getKeyId()));
}
listener.onKeyStatusChange(
FrameworkMediaDrm.this, sessionId, exoKeyInfo, hasNewUsableKey);
}
},
null);
}

@Override
Expand All @@ -121,8 +127,13 @@ public void closeSession(byte[] sessionId) {
}

@Override
public KeyRequest getKeyRequest(byte[] scope, byte[] init, String mimeType, int keyType,
HashMap<String, String> optionalParameters) throws NotProvisionedException {
public KeyRequest getKeyRequest(
byte[] scope,
byte[] init,
String mimeType,
int keyType,
HashMap<String, String> optionalParameters)
throws NotProvisionedException {

// Prior to L the Widevine CDM required data to be extracted from the PSSH atom. Some Amazon
// devices also required data to be extracted from the PSSH atom for PlayReady.
Expand Down Expand Up @@ -155,7 +166,7 @@ public KeyRequest getKeyRequest(byte[] scope, byte[] init, String mimeType, int
requestData = ClearKeyUtil.adjustRequestData(requestData);
}

return new DefaultKeyRequest(requestData, request.getDefaultUrl());
return new KeyRequest(requestData, request.getDefaultUrl());
}

@Override
Expand All @@ -172,7 +183,7 @@ public byte[] provideKeyResponse(byte[] scope, byte[] response)
@Override
public ProvisionRequest getProvisionRequest() {
final MediaDrm.ProvisionRequest request = mediaDrm.getProvisionRequest();
return new DefaultProvisionRequest(request.getData(), request.getDefaultUrl());
return new ProvisionRequest(request.getData(), request.getDefaultUrl());
}

@Override
Expand Down

0 comments on commit 377314a

Please sign in to comment.