OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.media; |
| 6 |
| 7 import android.annotation.TargetApi; |
| 8 import android.os.Build; |
| 9 |
| 10 import org.chromium.base.Callback; |
| 11 import org.chromium.base.annotations.JNINamespace; |
| 12 import org.chromium.base.annotations.MainDex; |
| 13 |
| 14 /** |
| 15 * Origin isolated media drm scope id storage. Isolated origin is guranteed by n
ative |
| 16 * implementation. Thus no origin information is stored here. |
| 17 */ |
| 18 @JNINamespace("media") |
| 19 @MainDex |
| 20 @TargetApi(Build.VERSION_CODES.M) |
| 21 class MediaDrmStorageBridge { |
| 22 private static final long INVALID_NATIVE_MEDIA_DRM_STORAGE_BRIDGE = -1; |
| 23 |
| 24 private long mNativeMediaDrmStorageBridge; |
| 25 |
| 26 /** |
| 27 * Information that need to be persistent on the device. Exposed to JNI. |
| 28 */ |
| 29 @MainDex |
| 30 static class PersistentInfo { |
| 31 // EME session ID, which is generated randomly. |
| 32 private final byte[] mEmeId; |
| 33 |
| 34 // Key set ID used to identify persistent license in MediaDrm. |
| 35 private final byte[] mKeySetId; |
| 36 |
| 37 // Mime type for the license. |
| 38 private final String mMimeType; |
| 39 |
| 40 PersistentInfo(byte[] emeId, byte[] keySetId, String mime) { |
| 41 mEmeId = emeId; |
| 42 mKeySetId = keySetId; |
| 43 mMimeType = mime; |
| 44 } |
| 45 } |
| 46 |
| 47 MediaDrmStorageBridge(long nativeMediaDrmStorageBridge) { |
| 48 mNativeMediaDrmStorageBridge = nativeMediaDrmStorageBridge; |
| 49 assert isNativeMediaDrmStorageValid(); |
| 50 } |
| 51 |
| 52 /** |
| 53 * Called when device provisioning is finished. |
| 54 */ |
| 55 void onProvisioned(Callback<Boolean> cb) { |
| 56 if (isNativeMediaDrmStorageValid()) { |
| 57 nativeOnProvisioned(mNativeMediaDrmStorageBridge, cb); |
| 58 } else { |
| 59 cb.onResult(true); |
| 60 } |
| 61 } |
| 62 |
| 63 /** |
| 64 * Load |emeId|'s storage into memory. |
| 65 */ |
| 66 void loadInfo(byte[] emeId, Callback<PersistentInfo> cb) { |
| 67 if (isNativeMediaDrmStorageValid()) { |
| 68 nativeOnLoadInfo(mNativeMediaDrmStorageBridge, emeId, cb); |
| 69 } else { |
| 70 cb.onResult(null); |
| 71 } |
| 72 } |
| 73 |
| 74 /** |
| 75 * Save persistent information. Override the existing value. |
| 76 */ |
| 77 void saveInfo(PersistentInfo info, Callback<Boolean> cb) { |
| 78 if (isNativeMediaDrmStorageValid()) { |
| 79 nativeOnSaveInfo(mNativeMediaDrmStorageBridge, info, cb); |
| 80 } else { |
| 81 cb.onResult(false); |
| 82 } |
| 83 } |
| 84 |
| 85 /** |
| 86 * Remove persistent information related |emeId|. |
| 87 */ |
| 88 void clearInfo(byte[] emeId, Callback<Boolean> cb) { |
| 89 if (isNativeMediaDrmStorageValid()) { |
| 90 nativeOnClearInfo(mNativeMediaDrmStorageBridge, emeId, cb); |
| 91 } else { |
| 92 cb.onResult(true); |
| 93 } |
| 94 } |
| 95 |
| 96 private boolean isNativeMediaDrmStorageValid() { |
| 97 return mNativeMediaDrmStorageBridge != INVALID_NATIVE_MEDIA_DRM_STORAGE_
BRIDGE; |
| 98 } |
| 99 |
| 100 private native void nativeOnProvisioned(long nativeMediaDrmStorageBridge, Ca
llback<Boolean> cb); |
| 101 private native void nativeOnLoadInfo( |
| 102 long nativeMediaDrmStorageBridge, byte[] sessionId, Callback<Persist
entInfo> cb); |
| 103 private native void nativeOnSaveInfo( |
| 104 long nativeMediaDrmStorageBridge, PersistentInfo info, Callback<Bool
ean> cb); |
| 105 private native void nativeOnClearInfo( |
| 106 long nativeMediaDrmStorageBridge, byte[] sessionId, Callback<Boolean
> cb); |
| 107 } |
OLD | NEW |