1 /*
2  * Copyright (c) 2023  Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef OHOS_DRM_IKEY_SESSION_H
17 #define OHOS_DRM_IKEY_SESSION_H
18 
19 #include "iremote_broker.h"
20 #include "drm_types.h"
21 #include "i_mediadecryptmodule_service.h"
22 #include "i_keysession_service_callback.h"
23 
24 namespace OHOS {
25 namespace DrmStandard {
26 class IMediaKeySessionService : public IRemoteBroker {
27 public:
28     enum ListenerType {
29         LISTENER_DRM_EVENT = 200,
30         LISTENER_PROVISION_REQUIRED = 201,
31         LISTENER_KEY_REQUIRED = 202,
32         LISTENER_KEY_EXPIRED = 203,
33         LISTENER_VENDOR_DEFINED = 204,
34         LISTENER_KEYSESSION_RECLAIMED = 205,
35         LISTENER_EXPIRATION_UPDATE = 206,
36         LISTENER_KEY_CHANGE = 207,
37         LISTENER_KEYSESSION_LOST = 208,
38     };
39 
40     enum MediaKeyType {
41         LICENSETYPE_OFFLINE = 0,
42         LICENSETYPE_ONLINE,
43     };
44 
45     enum OfflineMediaKeyStatus {
46         OFFLINELICENSESTATUS_UNKNOWN = 0,
47         OFFLINELICENSESTATUS_USABLE = 1,
48         OFFLINELICENSESTATUS_INACTIVE = 2,
49     };
50 
51     enum RequestType {
52         REQUEST_TYPE_UNKNOWN = 0,
53         REQUEST_TYPE_INITIAL = 1,
54         REQUEST_TYPE_RENEWAL = 2,
55         REQUEST_TYPE_RELEASE = 3,
56         REQUEST_TYPE_NONE = 4,
57         REQUEST_TYPE_UPDATE = 5,
58     };
59 
60     enum ContentProtectionLevel {
61         CONTENT_PROTECTION_LEVEL_UNKNOWN = 0,
62         CONTENT_PROTECTION_LEVEL_SW_CRYPTO = 1,
63         CONTENT_PROTECTION_LEVEL_HW_CRYPTO = 2,
64         CONTENT_PROTECTION_LEVEL_ENHANCED_HW = 3,
65         CONTENT_PROTECTION_LEVEL_MAX = 4,
66     };
67 
68     struct OptionalData {
69         std::string name;
70         std::string value;
71     };
72 
73     struct MediaKeyRequestInfo {
74         MediaKeyType mediaKeyType;
75         std::string mimeType;
76         std::vector<uint8_t> initData;
77         std::map<std::string, std::string> optionalData;
78     };
79 
80     struct MediaKeyRequest {
81         RequestType requestType;
82         std::vector<uint8_t> mData;
83         std::string mDefaultURL;
84     };
85 
86     virtual ~IMediaKeySessionService() = default;
87     virtual int32_t Release() = 0;
88     virtual int32_t GetMediaDecryptModule(sptr<IMediaDecryptModuleService> &decryptModule) = 0;
89     virtual int32_t GenerateMediaKeyRequest(MediaKeyRequestInfo &licenseRequestInfo, MediaKeyRequest &licenseInfo) = 0;
90     virtual int32_t ProcessMediaKeyResponse(std::vector<uint8_t> &licenseId, std::vector<uint8_t> &licenseResponse) = 0;
91     virtual int32_t GenerateOfflineReleaseRequest(std::vector<uint8_t> &licenseId,
92         std::vector<uint8_t> &releaseRequest) = 0;
93     virtual int32_t ProcessOfflineReleaseResponse(std::vector<uint8_t> &licenseId,
94         std::vector<uint8_t> &releaseReponse) = 0;
95     virtual int32_t CheckMediaKeyStatus(std::map<std::string, std::string> &licenseStatus) = 0;
96     virtual int32_t RestoreOfflineMediaKeys(std::vector<uint8_t> &licenseId) = 0;
97     virtual int32_t ClearMediaKeys() = 0;
98     virtual int32_t GetContentProtectionLevel(IMediaKeySessionService::ContentProtectionLevel *securityLevel) = 0;
99     virtual int32_t RequireSecureDecoderModule(std::string &mimeType, bool *status) = 0;
100     virtual int32_t SetListenerObject(const sptr<IRemoteObject> &object) = 0;
101     virtual int32_t SetCallback(sptr<IMediaKeySessionServiceCallback> &callback) = 0;
102     DECLARE_INTERFACE_DESCRIPTOR(u"IMediaKeySessionService");
103 };
104 } // DrmStandard
105 } // OHOS
106 
107 
108 #endif // OHOS_DRM_IKEY_SESSION_H_