• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "remote_request_code.h"
17 #include "drm_log.h"
18 #include "drm_error_code.h"
19 #include "mediakeysystemfactory_service_proxy.h"
20 
21 namespace OHOS {
22 namespace DrmStandard {
MediaKeySystemFactoryServiceProxy(const sptr<IRemoteObject> & impl)23 MediaKeySystemFactoryServiceProxy::MediaKeySystemFactoryServiceProxy(const sptr<IRemoteObject> &impl)
24     : IRemoteProxy<IMediaKeySystemFactoryService>(impl)
25 {
26 }
27 
SetListenerObject(const sptr<IRemoteObject> & object)28 int32_t MediaKeySystemFactoryServiceProxy::SetListenerObject(const sptr<IRemoteObject> &object)
29 {
30     DRM_INFO_LOG("SetListenerObject enter.");
31     MessageParcel data;
32     MessageParcel reply;
33     MessageOption option;
34 
35     data.WriteInterfaceToken(GetDescriptor());
36 
37     if (!data.WriteRemoteObject(object)) {
38         DRM_ERR_LOG("WriteRemoteObject failed.");
39         return IPC_PROXY_ERR;
40     }
41 
42     int ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_SET_LISTENER_OBJ, data, reply, option);
43     if (ret != 0) {
44         DRM_ERR_LOG("Set listener obj failed, error: %{public}d", ret);
45         return IPC_PROXY_ERR;
46     }
47     DRM_INFO_LOG("SetListenerObject exit.");
48     return 0;
49 }
50 
IsMediaKeySystemSupported(std::string & uuid,bool * isSupported)51 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, bool *isSupported)
52 {
53     DRM_INFO_LOG("one param enter.");
54     MessageParcel data;
55     MessageParcel reply;
56     MessageOption option;
57 
58     if (!data.WriteInterfaceToken(GetDescriptor())) {
59         DRM_ERR_LOG(
60             "One param Write interface token failed.");
61         return IPC_PROXY_ERR;
62     }
63 
64     if (!data.WriteInt32(ARGS_NUM_ONE)) {
65         DRM_ERR_LOG("One param Write paramNum failed.");
66         return IPC_PROXY_ERR;
67     }
68 
69     if (!data.WriteString(uuid)) {
70         DRM_ERR_LOG("Write uuid failed.");
71         return IPC_PROXY_ERR;
72     }
73 
74     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SUPPORTED, data, reply, option);
75     if (ret != 0) {
76         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
77         return ret;
78     }
79 
80     *isSupported = reply.ReadBool();
81     return ret;
82 }
83 
IsMediaKeySystemSupported(std::string & uuid,std::string & mimeType,bool * isSupported)84 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, std::string &mimeType,
85     bool *isSupported)
86 {
87     DRM_INFO_LOG("Two param enter.");
88     MessageParcel data;
89     MessageParcel reply;
90     MessageOption option;
91 
92     if (!data.WriteInterfaceToken(GetDescriptor())) {
93         DRM_ERR_LOG("Two params Write interface token failed.");
94         return IPC_PROXY_ERR;
95     }
96 
97     if (!data.WriteInt32(ARGS_NUM_TWO)) {
98         DRM_ERR_LOG("Two params Write paramNum failed.");
99         return IPC_PROXY_ERR;
100     }
101 
102     if (!data.WriteString(uuid)) {
103         DRM_ERR_LOG("Two params Write uuid failed.");
104         return IPC_PROXY_ERR;
105     }
106 
107     if (!data.WriteString(mimeType)) {
108         DRM_ERR_LOG("Two params Write mimeType failed.");
109         return IPC_PROXY_ERR;
110     }
111 
112     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SUPPORTED, data, reply, option);
113     if (ret != 0) {
114         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
115         return ret;
116     }
117 
118     *isSupported = reply.ReadBool();
119     return ret;
120 }
121 
IsMediaKeySystemSupported(std::string & uuid,std::string & mimeType,int32_t securityLevel,bool * isSupported)122 int32_t MediaKeySystemFactoryServiceProxy::IsMediaKeySystemSupported(std::string &uuid, std::string &mimeType,
123     int32_t securityLevel, bool *isSupported)
124 {
125     DRM_INFO_LOG("Three param called, enter.");
126     MessageParcel data;
127     MessageParcel reply;
128     MessageOption option;
129 
130     if (!data.WriteInterfaceToken(GetDescriptor())) {
131         DRM_ERR_LOG("Three params Write interface token failed.");
132         return IPC_PROXY_ERR;
133     }
134 
135     if (!data.WriteInt32(ARGS_NUM_THREE)) {
136         DRM_ERR_LOG("Three params Write paramNum failed.");
137         return IPC_PROXY_ERR;
138     }
139 
140     if (!data.WriteString(uuid)) {
141         DRM_ERR_LOG("Three params Write uuid failed.");
142         return IPC_PROXY_ERR;
143     }
144 
145     if (!data.WriteString(mimeType)) {
146         DRM_ERR_LOG("Three params Write mimeType failed.");
147         return IPC_PROXY_ERR;
148     }
149 
150     if (!data.WriteInt32(securityLevel)) {
151         DRM_ERR_LOG("Three params Write securityLevel failed.");
152         return IPC_PROXY_ERR;
153     }
154 
155     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_IS_MEDIA_KEY_SYSTEM_SUPPORTED, data, reply, option);
156     if (ret != 0) {
157         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
158         return ret;
159     }
160 
161     *isSupported = reply.ReadBool();
162     return ret;
163 }
164 
GetMediaKeySystems(std::map<std::string,std::string> & keySystemNames)165 int32_t MediaKeySystemFactoryServiceProxy::GetMediaKeySystems(std::map<std::string, std::string> &keySystemNames)
166 {
167     DRM_INFO_LOG("GetMediaKeySystems enter.");
168     MessageParcel data;
169     MessageParcel reply;
170     MessageOption option;
171 
172     if (!data.WriteInterfaceToken(MediaKeySystemFactoryServiceProxy::GetDescriptor())) {
173         DRM_ERR_LOG("Write interface token failed.");
174         return IPC_PROXY_ERR;
175     }
176     int32_t ret =
177         MediaKeySystemFactoryServiceProxy::Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_GET_MEDIA_KEYSYSTEM_NAME,
178         data, reply, option);
179     if (ret != 0) {
180         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
181         return ret;
182     }
183     int32_t mediaKeySystemNameMapSize = reply.ReadInt32();
184     DRM_CHECK_AND_RETURN_RET_LOG(mediaKeySystemNameMapSize <= MAX_MEDIA_KEY_SYSTEM_NUMBER, DRM_INNER_ERR_MEMORY_ERROR,
185         "The number of mediaKeySystem is too large.");
186     for (int32_t i = 0; i < mediaKeySystemNameMapSize; i++) {
187         std::string name = reply.ReadString();
188         std::string uuid = reply.ReadString();
189         keySystemNames.insert(std::make_pair(name, uuid));
190     }
191     return ret;
192 }
193 
GetMediaKeySystemUuid(std::string & name,std::string & uuid)194 int32_t MediaKeySystemFactoryServiceProxy::GetMediaKeySystemUuid(std::string &name, std::string &uuid)
195 {
196     DRM_INFO_LOG("GetMediaKeySystemUuid enter.");
197     MessageParcel data;
198     MessageParcel reply;
199     MessageOption option;
200 
201     if (!data.WriteInterfaceToken(MediaKeySystemFactoryServiceProxy::GetDescriptor())) {
202         DRM_ERR_LOG("Write interface token failed.");
203         return IPC_PROXY_ERR;
204     }
205     if (!data.WriteString(name)) {
206         DRM_ERR_LOG("Write configName failed.");
207         return IPC_PROXY_ERR;
208     }
209     int32_t ret =
210         MediaKeySystemFactoryServiceProxy::Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_GET_MEDIA_KEYSYSTEM_UUID,
211         data, reply, option);
212     if (ret != 0) {
213         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
214         return ret;
215     }
216     uuid = reply.ReadString();
217     return ret;
218 }
219 
CreateMediaKeySystem(std::string & name,sptr<IMediaKeySystemService> & mediaKeySystemProxy)220 int32_t MediaKeySystemFactoryServiceProxy::CreateMediaKeySystem(std::string &name,
221     sptr<IMediaKeySystemService> &mediaKeySystemProxy)
222 {
223     DRM_INFO_LOG("CreateMediaKeySystem enter.");
224     MessageParcel data;
225     MessageParcel reply;
226     MessageOption option;
227     if (!data.WriteInterfaceToken(GetDescriptor())) {
228         DRM_ERR_LOG("Write interface token failed.");
229         return IPC_PROXY_ERR;
230     }
231 
232     if (!data.WriteString(name)) {
233         DRM_ERR_LOG("Write format failed.");
234         return IPC_PROXY_ERR;
235     }
236 
237     int32_t ret = Remote()->SendRequest(MEDIA_KEY_SYSTEM_FACTORY_CREATE_MEDIA_KEYSYSTEM, data, reply, option);
238     if (ret != 0) {
239         DRM_ERR_LOG("SendRequest failed, errcode: %{public}d", ret);
240         return ret;
241     }
242 
243     auto remoteObject = reply.ReadRemoteObject();
244     if (remoteObject != nullptr) {
245         mediaKeySystemProxy = iface_cast<IMediaKeySystemService>(remoteObject);
246     } else {
247         DRM_ERR_LOG("mediaKeySystemProxy is nullptr");
248         ret = IPC_PROXY_ERR;
249     }
250     return ret;
251 }
252 } // DrmStandard
253 } // OHOS