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