blob: a64e3f2a7cf0c846a0bd1c9cb69d7ccb25f73ab2 [file] [log] [blame]
Jeff Tinker8a0c80f2013-02-08 10:20:44 -08001/*
2 * Copyright 2013, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _ANDROID_MEDIA_DRM_H_
18#define _ANDROID_MEDIA_DRM_H_
19
20#include "jni.h"
21
22#include <media/stagefright/foundation/ABase.h>
Marco Nelissena2eedd5d2019-09-27 11:19:36 -070023#include <mediadrm/IDrm.h>
Robert Shih3a523902019-08-15 14:48:11 -070024#include <mediadrm/IDrmClient.h>
25#include <hidl/HidlSupport.h>
Jeff Tinker8a0c80f2013-02-08 10:20:44 -080026#include <utils/Errors.h>
27#include <utils/RefBase.h>
28
Robert Shih9d4e2d42019-11-08 13:51:49 -080029namespace {
30
Robert Shih620f4a62021-02-15 03:28:42 -080031enum {
32 // TODO(b/180483929): use reverse jni e.g. android_media_MediaDrm_native_init
33 // KEEP IN SYNC with MediaDrm$ErrorCodes in MediaDrm.java!
34 JERROR_DRM_UNKNOWN = 0,
35 JERROR_DRM_NO_LICENSE = 1,
36 JERROR_DRM_LICENSE_EXPIRED = 2,
37 JERROR_DRM_RESOURCE_BUSY = 3,
38 JERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION = 4,
39 JERROR_DRM_SESSION_NOT_OPENED = 5,
40 JERROR_DRM_CANNOT_HANDLE = 6,
41 JERROR_DRM_INSUFFICIENT_SECURITY = 7,
42 JERROR_DRM_FRAME_TOO_LARGE = 8,
43 JERROR_DRM_SESSION_LOST_STATE = 9,
44 JERROR_DRM_CERTIFICATE_MALFORMED = 10,
45 JERROR_DRM_CERTIFICATE_MISSING = 11,
46 JERROR_DRM_CRYPTO_LIBRARY = 12,
47 JERROR_DRM_GENERIC_OEM = 13,
48 JERROR_DRM_GENERIC_PLUGIN = 14,
49 JERROR_DRM_INIT_DATA = 15,
50 JERROR_DRM_KEY_NOT_LOADED = 16,
51 JERROR_DRM_LICENSE_PARSE = 17,
52 JERROR_DRM_LICENSE_POLICY = 18,
53 JERROR_DRM_LICENSE_RELEASE = 19,
54 JERROR_DRM_LICENSE_REQUEST_REJECTED = 20,
55 JERROR_DRM_LICENSE_RESTORE = 21,
56 JERROR_DRM_LICENSE_STATE = 22,
57 JERROR_DRM_MEDIA_FRAMEWORK = 23,
58 JERROR_DRM_PROVISIONING_CERTIFICATE = 24,
59 JERROR_DRM_PROVISIONING_CONFIG = 25,
60 JERROR_DRM_PROVISIONING_PARSE = 26,
Robert Shiha37ae8e2021-03-03 03:35:12 -080061 JERROR_DRM_PROVISIONING_REQUEST_REJECTED = 27,
62 JERROR_DRM_PROVISIONING_RETRY = 28,
63 JERROR_DRM_RESOURCE_CONTENTION = 29,
64 JERROR_DRM_SECURE_STOP_RELEASE = 30,
65 JERROR_DRM_STORAGE_READ = 31,
66 JERROR_DRM_STORAGE_WRITE = 32,
67 JERROR_DRM_ZERO_SUBSAMPLES = 33,
Robert Shih620f4a62021-02-15 03:28:42 -080068};
69
Robert Shih9d4e2d42019-11-08 13:51:49 -080070struct ListenerArgs {
71 jbyteArray jSessionId;
72 jbyteArray jData;
73 jlong jExpirationTime;
74 jobject jKeyStatusList;
75 jboolean jHasNewUsableKey;
76};
77
78}
79
Jeff Tinker8a0c80f2013-02-08 10:20:44 -080080namespace android {
81
Jeff Tinker54cfbd62013-04-02 13:14:59 -070082class DrmListener: virtual public RefBase
83{
84public:
85 virtual void notify(DrmPlugin::EventType eventType, int extra,
Robert Shih9d4e2d42019-11-08 13:51:49 -080086 const ListenerArgs *args) = 0;
Jeff Tinker54cfbd62013-04-02 13:14:59 -070087};
88
Robert Shih0d057e52019-11-12 12:46:48 -080089struct JDrm : public IDrmClient {
Jeff Tinker5de2e902019-01-25 23:09:36 -080090 static status_t IsCryptoSchemeSupported(const uint8_t uuid[16],
91 const String8 &mimeType,
92 DrmPlugin::SecurityLevel level,
93 bool *isSupported);
Jeff Tinker8a0c80f2013-02-08 10:20:44 -080094
Edwin Wong4d1d84e2017-01-04 09:37:49 -080095 JDrm(JNIEnv *env, jobject thiz, const uint8_t uuid[16], const String8 &appPackageName);
Jeff Tinker8a0c80f2013-02-08 10:20:44 -080096
97 status_t initCheck() const;
Jeff Tinker8a0c80f2013-02-08 10:20:44 -080098 sp<IDrm> getDrm() { return mDrm; }
99
Robert Shih3a523902019-08-15 14:48:11 -0700100 void sendEvent(
101 DrmPlugin::EventType eventType,
102 const hardware::hidl_vec<uint8_t> &sessionId,
103 const hardware::hidl_vec<uint8_t> &data) override;
104
105 void sendExpirationUpdate(
106 const hardware::hidl_vec<uint8_t> &sessionId,
107 int64_t expiryTimeInMS) override;
108
109 void sendKeysChange(
110 const hardware::hidl_vec<uint8_t> &sessionId,
111 const std::vector<DrmKeyStatus> &keyStatusList,
112 bool hasNewUsableKey) override;
113
114 void sendSessionLostState(
115 const hardware::hidl_vec<uint8_t> &sessionId) override;
116
Jeff Tinker54cfbd62013-04-02 13:14:59 -0700117 status_t setListener(const sp<DrmListener>& listener);
118
Jeff Tinker600071c2014-04-11 16:11:15 -0700119 void disconnect();
120
Jeff Tinker8a0c80f2013-02-08 10:20:44 -0800121protected:
122 virtual ~JDrm();
123
124private:
125 jweak mObject;
126 sp<IDrm> mDrm;
127
Jeff Tinker54cfbd62013-04-02 13:14:59 -0700128 sp<DrmListener> mListener;
129 Mutex mNotifyLock;
130 Mutex mLock;
131
Jeff Tinker8a0c80f2013-02-08 10:20:44 -0800132 static sp<IDrm> MakeDrm();
Edwin Wong4d1d84e2017-01-04 09:37:49 -0800133 static sp<IDrm> MakeDrm(const uint8_t uuid[16], const String8 &appPackageName);
Jeff Tinker8a0c80f2013-02-08 10:20:44 -0800134
Robert Shih9d4e2d42019-11-08 13:51:49 -0800135 void notify(DrmPlugin::EventType, int extra, const ListenerArgs *args);
Robert Shih3a523902019-08-15 14:48:11 -0700136
Jeff Tinker8a0c80f2013-02-08 10:20:44 -0800137 DISALLOW_EVIL_CONSTRUCTORS(JDrm);
138};
139
Robert Shih620f4a62021-02-15 03:28:42 -0800140jint MediaErrorToJavaError(status_t err);
141
Jeff Tinker8a0c80f2013-02-08 10:20:44 -0800142} // namespace android
143
144#endif // _ANDROID_MEDIA_DRM_H_