OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.media; | 5 package org.chromium.media; |
6 | 6 |
7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.media.MediaCrypto; | 9 import android.media.MediaCrypto; |
10 import android.media.MediaDrm; | 10 import android.media.MediaDrm; |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
905 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { | 905 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { |
906 requestType = request.getRequestType(); | 906 requestType = request.getRequestType(); |
907 } else { | 907 } else { |
908 // Prior to M, getRequestType() is not supported. Do our best guess
here: Assume | 908 // Prior to M, getRequestType() is not supported. Do our best guess
here: Assume |
909 // requests with a URL are renewals and all others are initial reque
sts. | 909 // requests with a URL are renewals and all others are initial reque
sts. |
910 requestType = request.getDefaultUrl().isEmpty() | 910 requestType = request.getDefaultUrl().isEmpty() |
911 ? MediaDrm.KeyRequest.REQUEST_TYPE_INITIAL | 911 ? MediaDrm.KeyRequest.REQUEST_TYPE_INITIAL |
912 : MediaDrm.KeyRequest.REQUEST_TYPE_RENEWAL; | 912 : MediaDrm.KeyRequest.REQUEST_TYPE_RENEWAL; |
913 } | 913 } |
914 | 914 |
915 nativeOnSessionMessage(mNativeMediaDrmBridge, sessionId, requestType, re
quest.getData(), | 915 nativeOnSessionMessage(mNativeMediaDrmBridge, sessionId, requestType, re
quest.getData()); |
916 request.getDefaultUrl()); | |
917 } | 916 } |
918 | 917 |
919 private void onSessionClosed(final byte[] sessionId) { | 918 private void onSessionClosed(final byte[] sessionId) { |
920 if (isNativeMediaDrmBridgeValid()) { | 919 if (isNativeMediaDrmBridgeValid()) { |
921 nativeOnSessionClosed(mNativeMediaDrmBridge, sessionId); | 920 nativeOnSessionClosed(mNativeMediaDrmBridge, sessionId); |
922 } | 921 } |
923 } | 922 } |
924 | 923 |
925 private void onSessionKeysChange( | 924 private void onSessionKeysChange( |
926 final byte[] sessionId, final Object[] keysInfo, final boolean hasAd
ditionalUsableKey) { | 925 final byte[] sessionId, final Object[] keysInfo, final boolean hasAd
ditionalUsableKey) { |
927 if (isNativeMediaDrmBridgeValid()) { | 926 if (isNativeMediaDrmBridgeValid()) { |
928 nativeOnSessionKeysChange( | 927 nativeOnSessionKeysChange( |
929 mNativeMediaDrmBridge, sessionId, keysInfo, hasAdditionalUsa
bleKey); | 928 mNativeMediaDrmBridge, sessionId, keysInfo, hasAdditionalUsa
bleKey); |
930 } | 929 } |
931 } | 930 } |
932 | 931 |
933 private void onSessionExpirationUpdate(final byte[] sessionId, final long ex
pirationTime) { | 932 private void onSessionExpirationUpdate(final byte[] sessionId, final long ex
pirationTime) { |
934 if (isNativeMediaDrmBridgeValid()) { | 933 if (isNativeMediaDrmBridgeValid()) { |
935 nativeOnSessionExpirationUpdate(mNativeMediaDrmBridge, sessionId, ex
pirationTime); | 934 nativeOnSessionExpirationUpdate(mNativeMediaDrmBridge, sessionId, ex
pirationTime); |
936 } | 935 } |
937 } | 936 } |
938 | 937 |
939 private void onLegacySessionError(final byte[] sessionId, final String error
Message) { | |
940 if (isNativeMediaDrmBridgeValid()) { | |
941 nativeOnLegacySessionError(mNativeMediaDrmBridge, sessionId, errorMe
ssage); | |
942 } | |
943 } | |
944 | |
945 private void onResetDeviceCredentialsCompleted(final boolean success) { | 938 private void onResetDeviceCredentialsCompleted(final boolean success) { |
946 if (isNativeMediaDrmBridgeValid()) { | 939 if (isNativeMediaDrmBridgeValid()) { |
947 nativeOnResetDeviceCredentialsCompleted(mNativeMediaDrmBridge, succe
ss); | 940 nativeOnResetDeviceCredentialsCompleted(mNativeMediaDrmBridge, succe
ss); |
948 } | 941 } |
949 } | 942 } |
950 | 943 |
951 @MainDex | 944 @MainDex |
952 private class EventListener implements MediaDrm.OnEventListener { | 945 private class EventListener implements MediaDrm.OnEventListener { |
953 @Override | 946 @Override |
954 public void onEvent( | 947 public void onEvent( |
(...skipping 17 matching lines...) Expand all Loading... |
972 try { | 965 try { |
973 request = getKeyRequest(sessionId, data, mime, null); | 966 request = getKeyRequest(sessionId, data, mime, null); |
974 } catch (android.media.NotProvisionedException e) { | 967 } catch (android.media.NotProvisionedException e) { |
975 Log.e(TAG, "Device not provisioned", e); | 968 Log.e(TAG, "Device not provisioned", e); |
976 startProvisioning(); | 969 startProvisioning(); |
977 return; | 970 return; |
978 } | 971 } |
979 if (request != null) { | 972 if (request != null) { |
980 onSessionMessage(sessionId, request); | 973 onSessionMessage(sessionId, request); |
981 } else { | 974 } else { |
982 onLegacySessionError(sessionId, | |
983 "MediaDrm EVENT_KEY_REQUIRED: Failed to generate
request."); | |
984 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | 975 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
985 onSessionKeysChange(sessionId, | 976 onSessionKeysChange(sessionId, |
986 getDummyKeysInfo(MediaDrm.KeyStatus.STATUS_I
NTERNAL_ERROR) | 977 getDummyKeysInfo(MediaDrm.KeyStatus.STATUS_I
NTERNAL_ERROR) |
987 .toArray(), | 978 .toArray(), |
988 false); | 979 false); |
989 } | 980 } |
990 Log.e(TAG, "EventListener: getKeyRequest failed."); | 981 Log.e(TAG, "EventListener: getKeyRequest failed."); |
991 return; | 982 return; |
992 } | 983 } |
993 break; | 984 break; |
994 case MediaDrm.EVENT_KEY_EXPIRED: | 985 case MediaDrm.EVENT_KEY_EXPIRED: |
995 Log.d(TAG, "MediaDrm.EVENT_KEY_EXPIRED"); | 986 Log.d(TAG, "MediaDrm.EVENT_KEY_EXPIRED"); |
996 onLegacySessionError(sessionId, "MediaDrm EVENT_KEY_EXPIRED.
"); | |
997 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { | 987 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) { |
998 onSessionKeysChange(sessionId, | 988 onSessionKeysChange(sessionId, |
999 getDummyKeysInfo(MediaDrm.KeyStatus.STATUS_EXPIR
ED).toArray(), | 989 getDummyKeysInfo(MediaDrm.KeyStatus.STATUS_EXPIR
ED).toArray(), |
1000 false); | 990 false); |
1001 } | 991 } |
1002 break; | 992 break; |
1003 case MediaDrm.EVENT_VENDOR_DEFINED: | 993 case MediaDrm.EVENT_VENDOR_DEFINED: |
1004 Log.d(TAG, "MediaDrm.EVENT_VENDOR_DEFINED"); | 994 Log.d(TAG, "MediaDrm.EVENT_VENDOR_DEFINED"); |
1005 assert false; // Should never happen. | 995 assert false; // Should never happen. |
1006 break; | 996 break; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1048 | 1038 |
1049 private native void nativeOnStartProvisioning( | 1039 private native void nativeOnStartProvisioning( |
1050 long nativeMediaDrmBridge, String defaultUrl, byte[] requestData); | 1040 long nativeMediaDrmBridge, String defaultUrl, byte[] requestData); |
1051 | 1041 |
1052 private native void nativeOnPromiseResolved(long nativeMediaDrmBridge, long
promiseId); | 1042 private native void nativeOnPromiseResolved(long nativeMediaDrmBridge, long
promiseId); |
1053 private native void nativeOnPromiseResolvedWithSession( | 1043 private native void nativeOnPromiseResolvedWithSession( |
1054 long nativeMediaDrmBridge, long promiseId, byte[] sessionId); | 1044 long nativeMediaDrmBridge, long promiseId, byte[] sessionId); |
1055 private native void nativeOnPromiseRejected( | 1045 private native void nativeOnPromiseRejected( |
1056 long nativeMediaDrmBridge, long promiseId, String errorMessage); | 1046 long nativeMediaDrmBridge, long promiseId, String errorMessage); |
1057 | 1047 |
1058 private native void nativeOnSessionMessage(long nativeMediaDrmBridge, byte[]
sessionId, | 1048 private native void nativeOnSessionMessage( |
1059 int requestType, byte[] message, String destinationUrl); | 1049 long nativeMediaDrmBridge, byte[] sessionId, int requestType, byte[]
message); |
1060 private native void nativeOnSessionClosed(long nativeMediaDrmBridge, byte[]
sessionId); | 1050 private native void nativeOnSessionClosed(long nativeMediaDrmBridge, byte[]
sessionId); |
1061 private native void nativeOnSessionKeysChange(long nativeMediaDrmBridge, byt
e[] sessionId, | 1051 private native void nativeOnSessionKeysChange(long nativeMediaDrmBridge, byt
e[] sessionId, |
1062 Object[] keysInfo, boolean hasAdditionalUsableKey); | 1052 Object[] keysInfo, boolean hasAdditionalUsableKey); |
1063 private native void nativeOnSessionExpirationUpdate( | 1053 private native void nativeOnSessionExpirationUpdate( |
1064 long nativeMediaDrmBridge, byte[] sessionId, long expirationTime); | 1054 long nativeMediaDrmBridge, byte[] sessionId, long expirationTime); |
1065 private native void nativeOnLegacySessionError( | |
1066 long nativeMediaDrmBridge, byte[] sessionId, String errorMessage); | |
1067 | 1055 |
1068 private native void nativeOnResetDeviceCredentialsCompleted( | 1056 private native void nativeOnResetDeviceCredentialsCompleted( |
1069 long nativeMediaDrmBridge, boolean success); | 1057 long nativeMediaDrmBridge, boolean success); |
1070 } | 1058 } |
OLD | NEW |