1 /*
2  * Copyright (C) 2017 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 #include <mediadrm/IDrm.h>
18 #include <mediadrm/DrmStatus.h>
19 
20 #ifndef DRM_HAL_H_
21 #define DRM_HAL_H_
22 
23 namespace android {
24 
25 struct DrmHal : public IDrm {
26     DrmHal();
27     virtual ~DrmHal();
28     virtual DrmStatus initCheck() const;
29     virtual DrmStatus isCryptoSchemeSupported(const uint8_t uuid[16], const String8& mimeType,
30                                               DrmPlugin::SecurityLevel securityLevel, bool* result);
31     virtual DrmStatus createPlugin(const uint8_t uuid[16],
32                                    const String8 &appPackageName);
33     virtual DrmStatus destroyPlugin();
34     virtual DrmStatus openSession(DrmPlugin::SecurityLevel securityLevel,
35             Vector<uint8_t> &sessionId);
36     virtual DrmStatus closeSession(Vector<uint8_t> const &sessionId);
37     virtual DrmStatus
38         getKeyRequest(Vector<uint8_t> const &sessionId,
39                       Vector<uint8_t> const &initData,
40                       String8 const &mimeType, DrmPlugin::KeyType keyType,
41                       KeyedVector<String8, String8> const &optionalParameters,
42                       Vector<uint8_t> &request, String8 &defaultUrl,
43                       DrmPlugin::KeyRequestType *keyRequestType);
44     virtual DrmStatus provideKeyResponse(Vector<uint8_t> const &sessionId,
45                                          Vector<uint8_t> const &response,
46                                          Vector<uint8_t> &keySetId);
47     virtual DrmStatus removeKeys(Vector<uint8_t> const &keySetId);
48     virtual DrmStatus restoreKeys(Vector<uint8_t> const &sessionId,
49                                   Vector<uint8_t> const &keySetId);
50     virtual DrmStatus queryKeyStatus(Vector<uint8_t> const &sessionId,
51                                      KeyedVector<String8, String8> &infoMap) const;
52     virtual DrmStatus getProvisionRequest(String8 const &certType,
53                                           String8 const &certAuthority,
54                                           Vector<uint8_t> &request,
55                                           String8 &defaultUrl);
56     virtual DrmStatus provideProvisionResponse(Vector<uint8_t> const &response,
57                                                Vector<uint8_t> &certificate,
58                                                Vector<uint8_t> &wrappedKey);
59     virtual DrmStatus getSecureStops(List<Vector<uint8_t>> &secureStops);
60     virtual DrmStatus getSecureStopIds(List<Vector<uint8_t>> &secureStopIds);
61     virtual DrmStatus getSecureStop(Vector<uint8_t> const &ssid, Vector<uint8_t> &secureStop);
62     virtual DrmStatus releaseSecureStops(Vector<uint8_t> const &ssRelease);
63     virtual DrmStatus removeSecureStop(Vector<uint8_t> const &ssid);
64     virtual DrmStatus removeAllSecureStops();
65     virtual DrmStatus getHdcpLevels(DrmPlugin::HdcpLevel *connectedLevel,
66             DrmPlugin::HdcpLevel *maxLevel) const;
67     virtual DrmStatus getNumberOfSessions(uint32_t *currentSessions,
68             uint32_t *maxSessions) const;
69     virtual DrmStatus getSecurityLevel(Vector<uint8_t> const &sessionId,
70             DrmPlugin::SecurityLevel *level) const;
71     virtual DrmStatus getOfflineLicenseKeySetIds(List<Vector<uint8_t>> &keySetIds) const;
72     virtual DrmStatus removeOfflineLicense(Vector<uint8_t> const &keySetId);
73     virtual DrmStatus getOfflineLicenseState(Vector<uint8_t> const &keySetId,
74             DrmPlugin::OfflineLicenseState *licenseState) const;
75     virtual DrmStatus getPropertyString(String8 const &name, String8 &value) const;
76     virtual DrmStatus getPropertyByteArray(String8 const &name,
77                                            Vector<uint8_t> &value) const;
78     virtual DrmStatus setPropertyString(String8 const &name,
79                                         String8 const &value ) const;
80     virtual DrmStatus setPropertyByteArray(String8 const &name,
81                                            Vector<uint8_t> const &value) const;
82     virtual DrmStatus getMetrics(const sp<IDrmMetricsConsumer> &consumer);
83     virtual DrmStatus setCipherAlgorithm(Vector<uint8_t> const &sessionId,
84                                          String8 const &algorithm);
85     virtual DrmStatus setMacAlgorithm(Vector<uint8_t> const &sessionId,
86                                       String8 const &algorithm);
87     virtual DrmStatus encrypt(Vector<uint8_t> const &sessionId,
88                               Vector<uint8_t> const &keyId,
89                               Vector<uint8_t> const &input,
90                               Vector<uint8_t> const &iv,
91                               Vector<uint8_t> &output);
92     virtual DrmStatus decrypt(Vector<uint8_t> const &sessionId,
93                               Vector<uint8_t> const &keyId,
94                               Vector<uint8_t> const &input,
95                               Vector<uint8_t> const &iv,
96                               Vector<uint8_t> &output);
97     virtual DrmStatus sign(Vector<uint8_t> const &sessionId,
98                            Vector<uint8_t> const &keyId,
99                            Vector<uint8_t> const &message,
100                            Vector<uint8_t> &signature);
101     virtual DrmStatus verify(Vector<uint8_t> const &sessionId,
102                              Vector<uint8_t> const &keyId,
103                              Vector<uint8_t> const &message,
104                              Vector<uint8_t> const &signature,
105                              bool &match);
106     virtual DrmStatus signRSA(Vector<uint8_t> const &sessionId,
107                               String8 const &algorithm,
108                               Vector<uint8_t> const &message,
109                               Vector<uint8_t> const &wrappedKey,
110                               Vector<uint8_t> &signature);
111     virtual DrmStatus setListener(const sp<IDrmClient>& listener);
112     virtual DrmStatus requiresSecureDecoder(const char *mime, bool *required) const;
113     virtual DrmStatus requiresSecureDecoder(const char *mime,
114                                             DrmPlugin::SecurityLevel securityLevel,
115                                             bool *required) const;
116     virtual DrmStatus setPlaybackId(
117             Vector<uint8_t> const &sessionId,
118             const char *playbackId);
119     virtual DrmStatus getLogMessages(Vector<drm::V1_4::LogMessage> &logs) const;
120     virtual DrmStatus getSupportedSchemes(std::vector<uint8_t> &schemes) const;
121 
122 private:
123     sp<IDrm> mDrmHalHidl;
124     sp<IDrm> mDrmHalAidl;
125     DISALLOW_EVIL_CONSTRUCTORS(DrmHal);
126 };
127 
128 } // namespace android
129 
130 #endif  // DRM_HAL_H_