1 /*
2 * Copyright (c) 2021-2022 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 "hcamera_device_proxy.h"
17 #include "camera_log.h"
18 #include "metadata_utils.h"
19 #include "camera_service_ipc_interface_code.h"
20
21 namespace OHOS {
22 namespace CameraStandard {
HCameraDeviceProxy(const sptr<IRemoteObject> & impl)23 HCameraDeviceProxy::HCameraDeviceProxy(const sptr<IRemoteObject> &impl)
24 : IRemoteProxy<ICameraDeviceService>(impl) { }
25
~HCameraDeviceProxy()26 HCameraDeviceProxy::~HCameraDeviceProxy()
27 {
28 MEDIA_INFO_LOG("~HCameraDeviceProxy is called");
29 }
30
closeDelayed()31 int32_t HCameraDeviceProxy::closeDelayed()
32 {
33 MEDIA_INFO_LOG("HCameraDeviceProxy::closeDelayed() start");
34 MessageParcel data;
35 MessageParcel reply;
36 MessageOption option;
37 data.WriteInterfaceToken(GetDescriptor());
38 data.WriteBool(false);
39 int error = Remote()->SendRequest(
40 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_DELAYED_CLOSE), data, reply, option);
41 if (error != ERR_NONE) {
42 MEDIA_ERR_LOG("HCameraDeviceProxy closeDelayed failed, error: %{public}d", error);
43 }
44 return error;
45 }
46
Open()47 int32_t HCameraDeviceProxy::Open()
48 {
49 MessageParcel data;
50 MessageParcel reply;
51 MessageOption option;
52
53 data.WriteInterfaceToken(GetDescriptor());
54 data.WriteBool(false);
55 int error = Remote()->SendRequest(
56 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_OPEN), data, reply, option);
57 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy Open failed, error: %{public}d", error);
58 return error;
59 }
60
OpenSecureCamera(uint64_t * secureSeqId)61 int32_t HCameraDeviceProxy::OpenSecureCamera(uint64_t* secureSeqId)
62 {
63 MessageParcel data;
64 MessageParcel reply;
65 MessageOption option;
66
67 data.WriteInterfaceToken(GetDescriptor());
68 data.WriteBool(true);
69 int error = Remote()->SendRequest(
70 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_OPEN), data, reply, option);
71 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy Open failed, error: %{public}d", error);
72 *secureSeqId = reply.ReadInt64();
73 return error;
74 }
75
Open(int32_t concurrentTypeofcamera)76 int32_t HCameraDeviceProxy::Open(int32_t concurrentTypeofcamera)
77 {
78 MessageParcel data;
79 MessageParcel reply;
80 MessageOption option;
81
82 data.WriteInterfaceToken(GetDescriptor());
83 data.WriteInt32(concurrentTypeofcamera);
84 int error = Remote()->SendRequest(
85 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_OPEN_CONCURRENT), data, reply, option);
86 if (error != ERR_NONE) {
87 MEDIA_ERR_LOG("HCameraDeviceProxy Open failed, error: %{public}d", error);
88 }
89 return error;
90 }
91
Close()92 int32_t HCameraDeviceProxy::Close()
93 {
94 MessageParcel data;
95 MessageParcel reply;
96 MessageOption option;
97
98 data.WriteInterfaceToken(GetDescriptor());
99 int error = Remote()->SendRequest(
100 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_CLOSE), data, reply, option);
101 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy Close failed, error: %{public}d", error);
102
103 return error;
104 }
105
Release()106 int32_t HCameraDeviceProxy::Release()
107 {
108 MessageParcel data;
109 MessageParcel reply;
110 MessageOption option;
111
112 data.WriteInterfaceToken(GetDescriptor());
113 int error = Remote()->SendRequest(
114 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_RELEASE), data, reply, option);
115 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy Release failed, error: %{public}d", error);
116
117 return error;
118 }
119
SetCallback(sptr<ICameraDeviceServiceCallback> & callback)120 int32_t HCameraDeviceProxy::SetCallback(sptr<ICameraDeviceServiceCallback>& callback)
121 {
122 MessageParcel data;
123 MessageParcel reply;
124 MessageOption option;
125
126 CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_PROXY_ERR, "HCameraDeviceProxy SetCallback callback is null");
127
128 data.WriteInterfaceToken(GetDescriptor());
129 data.WriteRemoteObject(callback->AsObject());
130
131 int error = Remote()->SendRequest(
132 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_SET_CALLBACK), data, reply, option);
133 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy SetCallback failed, error: %{public}d", error);
134
135 return error;
136 }
137
UnSetCallback()138 int32_t HCameraDeviceProxy::UnSetCallback()
139 {
140 MessageParcel data;
141 MessageParcel reply;
142 MessageOption option;
143 data.WriteInterfaceToken(GetDescriptor());
144 int error = Remote()->SendRequest(
145 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_UNSET_CALLBACK), data, reply, option);
146 if (error != ERR_NONE) {
147 MEDIA_ERR_LOG("HCameraDeviceProxy UnSetCallback failed, error: %{public}d", error);
148 }
149
150 return error;
151 }
152
UpdateSetting(const std::shared_ptr<Camera::CameraMetadata> & settings)153 int32_t HCameraDeviceProxy::UpdateSetting(const std::shared_ptr<Camera::CameraMetadata> &settings)
154 {
155 MessageParcel data;
156 MessageParcel reply;
157 MessageOption option;
158
159 data.WriteInterfaceToken(GetDescriptor());
160 CHECK_ERROR_RETURN_RET_LOG(!(Camera::MetadataUtils::EncodeCameraMetadata(settings, data)), IPC_PROXY_ERR,
161 "HCameraDeviceProxy UpdateSetting EncodeCameraMetadata failed");
162
163 int error = Remote()->SendRequest(
164 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_UPDATE_SETTNGS), data, reply, option);
165 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy UpdateSetting failed, error: %{public}d", error);
166
167 return error;
168 }
169
SetUsedAsPosition(uint8_t value)170 int32_t HCameraDeviceProxy::SetUsedAsPosition(uint8_t value)
171 {
172 MessageParcel data;
173 MessageParcel reply;
174 MessageOption option;
175
176 data.WriteInterfaceToken(GetDescriptor());
177 CHECK_ERROR_RETURN_RET_LOG(!data.WriteUint8(value), IPC_PROXY_ERR,
178 "HCameraDeviceProxy SetUsedAsPosition Encode failed");
179
180 int error = Remote()->SendRequest(
181 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_SET_USED_POS), data, reply, option);
182 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy SetUsedAsPosition failed, error: %{public}d", error);
183
184 return error;
185 }
186
GetStatus(std::shared_ptr<OHOS::Camera::CameraMetadata> & metaIn,std::shared_ptr<OHOS::Camera::CameraMetadata> & metaOut)187 int32_t HCameraDeviceProxy::GetStatus(std::shared_ptr<OHOS::Camera::CameraMetadata> &metaIn,
188 std::shared_ptr<OHOS::Camera::CameraMetadata> &metaOut)
189 {
190 MessageParcel data;
191 MessageParcel reply;
192 MessageOption option;
193
194 data.WriteInterfaceToken(GetDescriptor());
195 CHECK_ERROR_RETURN_RET_LOG(!(Camera::MetadataUtils::EncodeCameraMetadata(metaIn, data)), IPC_PROXY_ERR,
196 "HCameraDeviceProxy UpdateSetting EncodeCameraMetadata failed");
197
198 int error = Remote()->SendRequest(
199 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_GET_STATUS), data, reply, option);
200 if (error != ERR_NONE) {
201 MEDIA_ERR_LOG("HCameraDeviceProxy GetStatus failed, error: %{public}d", error);
202 } else {
203 Camera::MetadataUtils::DecodeCameraMetadata(reply, metaOut);
204 }
205
206 return error;
207 }
208
GetEnabledResults(std::vector<int32_t> & results)209 int32_t HCameraDeviceProxy::GetEnabledResults(std::vector<int32_t> &results)
210 {
211 MessageParcel data;
212 MessageParcel reply;
213 MessageOption option;
214
215 data.WriteInterfaceToken(GetDescriptor());
216 int error = Remote()->SendRequest(
217 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_GET_ENABLED_RESULT), data, reply, option);
218 CHECK_ERROR_RETURN_RET_LOG(error != ERR_NONE, IPC_PROXY_ERR,
219 "HCameraDeviceProxy GetEnabledResults failed, error: %{public}d", error);
220
221 reply.ReadInt32Vector(&results);
222
223 return error;
224 }
225
EnableResult(std::vector<int32_t> & results)226 int32_t HCameraDeviceProxy::EnableResult(std::vector<int32_t> &results)
227 {
228 MessageParcel data;
229 MessageParcel reply;
230 MessageOption option;
231
232 data.WriteInterfaceToken(GetDescriptor());
233 data.WriteInt32Vector(results);
234
235 int error = Remote()->SendRequest(
236 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_ENABLED_RESULT), data, reply, option);
237 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy EnableResult failed, error: %{public}d", error);
238
239 return error;
240 }
241
DisableResult(std::vector<int32_t> & results)242 int32_t HCameraDeviceProxy::DisableResult(std::vector<int32_t> &results)
243 {
244 MessageParcel data;
245 MessageParcel reply;
246 MessageOption option;
247
248 data.WriteInterfaceToken(GetDescriptor());
249 data.WriteInt32Vector(results);
250
251 int error = Remote()->SendRequest(
252 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_DISABLED_RESULT), data, reply, option);
253 CHECK_ERROR_PRINT_LOG(error != ERR_NONE, "HCameraDeviceProxy DisableResult failed, error: %{public}d", error);
254
255 return error;
256 }
257
SetDeviceRetryTime()258 int32_t HCameraDeviceProxy::SetDeviceRetryTime()
259 {
260 MessageParcel data;
261 MessageParcel reply;
262 MessageOption option;
263
264 data.WriteInterfaceToken(GetDescriptor());
265
266 int error = Remote()->SendRequest(
267 static_cast<uint32_t>(CameraDeviceInterfaceCode::CAMERA_DEVICE_SET_DEVICE_RETRY_TIME),
268 data, reply, option);
269 return error;
270 }
271 } // namespace CameraStandard
272 } // namespace OHOS
273