• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "hstream_capture_stub.h"
17 #include "camera_dynamic_loader.h"
18 #include "camera_server_photo_proxy.h"
19 #include "camera_log.h"
20 #include "camera_photo_proxy.h"
21 #include "camera_service_ipc_interface_code.h"
22 #include "camera_util.h"
23 #include "metadata_utils.h"
24 #include "picture_proxy.h"
25 
26 namespace OHOS {
27 namespace CameraStandard {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)28 int HStreamCaptureStub::OnRemoteRequest(
29     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
30 {
31     DisableJeMalloc();
32     int errCode = -1;
33 
34     CHECK_ERROR_RETURN_RET(data.ReadInterfaceToken() != GetDescriptor(), errCode);
35     errCode = OperatePermissionCheck(code);
36     CHECK_ERROR_RETURN_RET(errCode != CAMERA_OK, errCode);
37     switch (code) {
38         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_START):
39             errCode = HStreamCaptureStub::HandleCapture(data);
40             break;
41         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_CANCEL):
42             errCode = CancelCapture();
43             break;
44         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_CONFIRM):
45             errCode = HStreamCaptureStub::HandleConfirmCapture(data);
46             break;
47         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_SET_CALLBACK):
48             errCode = HStreamCaptureStub::HandleSetCallback(data);
49             break;
50         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_UNSET_CALLBACK):
51             errCode = UnSetCallback();
52             break;
53         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CAPTURE_RELEASE):
54             errCode = Release();
55             break;
56         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_SERVICE_SET_THUMBNAIL):
57             errCode = HandleSetThumbnail(data);
58             break;
59         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_RAW_DELIVERY):
60             errCode = HandleEnableRawDelivery(data);
61             break;
62         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_MOVING_PHOTO):
63             errCode = HandleEnableMovingPhoto(data);
64             break;
65         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_SERVICE_ENABLE_DEFERREDTYPE):
66             errCode = HandleEnableDeferredType(data);
67             break;
68         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_GET_DEFERRED_PHOTO):
69             errCode = IsDeferredPhotoEnabled();
70             break;
71         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_GET_DEFERRED_VIDEO):
72             errCode = IsDeferredVideoEnabled();
73             break;
74         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_SET_VIDEO_CODEC_TYPE):
75             errCode = HandleSetMovingPhotoVideoCodecType(data);
76             break;
77         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_SET_BUFFER_PRODUCER_INFO):
78             errCode = HandleSetBufferProducerInfo(data);
79             break;
80         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_PHOTO_ROTATION):
81             errCode = HandleSetCameraPhotoRotation(data);
82             break;
83         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ADD_MEDIA_LIBRARY_PHOTO_PROXY):
84             errCode = HandleAddMediaLibraryPhotoProxy(data);
85             break;
86         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_CAPTURE_DFX):
87             errCode = HandleAcquireBufferToPrepareProxy(data);
88             break;
89         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_ENABLE_OFFLINE_PHOTO):
90             errCode = HandleEnableOfflinePhoto(data);
91             break;
92         case static_cast<uint32_t>(StreamCaptureInterfaceCode::CAMERA_STREAM_CREATE_MEDIA_LIBRARY_MANAGER):
93             errCode = HandleCreateMediaLibrary(data, reply);
94             break;
95         case static_cast<uint32_t>(
96             StreamCaptureInterfaceCode::CAMERA_STREAM_CREATE_MEDIA_LIBRARY_MANAGER_PICTURE):
97             errCode = HandleCreateMediaLibraryForPicture(data, reply);
98             break;
99         default:
100             MEDIA_ERR_LOG("HStreamCaptureStub request code %{public}u not handled", code);
101             errCode = IPCObjectStub::OnRemoteRequest(code, data, reply, option);
102             break;
103     }
104 
105     return errCode;
106 }
107 
HandleCapture(MessageParcel & data)108 int32_t HStreamCaptureStub::HandleCapture(MessageParcel &data)
109 {
110     std::shared_ptr<OHOS::Camera::CameraMetadata> metadata = nullptr;
111     OHOS::Camera::MetadataUtils::DecodeCameraMetadata(data, metadata);
112 
113     return Capture(metadata);
114 }
115 
HandleConfirmCapture(MessageParcel & data)116 int32_t HStreamCaptureStub::HandleConfirmCapture(MessageParcel &data)
117 {
118     CHECK_ERROR_RETURN_RET(!CheckSystemApp(), CAMERA_NO_PERMISSION);
119     return ConfirmCapture();
120 }
121 
HandleSetThumbnail(MessageParcel & data)122 int32_t HStreamCaptureStub::HandleSetThumbnail(MessageParcel &data)
123 {
124     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
125     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
126         "HStreamCaptureStub HandleCreatePhotoOutput BufferProducer is null");
127     sptr<OHOS::IBufferProducer> producer = iface_cast<OHOS::IBufferProducer>(remoteObj);
128     CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_STUB_INVALID_DATA_ERR,
129         "HStreamCaptureStub HandleSetThumbnail producer is null");
130     bool isEnabled = data.ReadBool();
131     int32_t ret = SetThumbnail(isEnabled, producer);
132     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleSetThumbnail result: %{public}d", ret);
133     return ret;
134 }
135 
HandleEnableRawDelivery(MessageParcel & data)136 int32_t HStreamCaptureStub::HandleEnableRawDelivery(MessageParcel &data)
137 {
138     bool enabled = data.ReadBool();
139     int32_t ret = EnableRawDelivery(enabled);
140     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleEnableRawDelivery result: %{public}d", ret);
141     return ret;
142 }
143 
HandleEnableMovingPhoto(MessageParcel & data)144 int32_t HStreamCaptureStub::HandleEnableMovingPhoto(MessageParcel &data)
145 {
146     bool enabled = data.ReadBool();
147     int32_t ret = EnableMovingPhoto(enabled);
148     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleEnableRawDelivery result: %{public}d", ret);
149     return ret;
150 }
151 
HandleSetBufferProducerInfo(MessageParcel & data)152 int32_t HStreamCaptureStub::HandleSetBufferProducerInfo(MessageParcel &data)
153 {
154     std::string bufferName = data.ReadString();
155     sptr<IRemoteObject> remoteObj = data.ReadRemoteObject();
156     CHECK_ERROR_RETURN_RET_LOG(remoteObj == nullptr, IPC_STUB_INVALID_DATA_ERR,
157         "HStreamCaptureStub HandleSetBufferProducerInfo BufferProducer is null");
158     sptr<OHOS::IBufferProducer> producer = iface_cast<OHOS::IBufferProducer>(remoteObj);
159     CHECK_ERROR_RETURN_RET_LOG(producer == nullptr, IPC_STUB_INVALID_DATA_ERR,
160         "HStreamCaptureStub HandleSetBufferProducerInfo producer is null");
161     int32_t ret = SetBufferProducerInfo(bufferName, producer);
162     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleSetBufferProducerInfo result: %{public}d", ret);
163     return ret;
164 }
165 
HandleEnableDeferredType(MessageParcel & data)166 int32_t HStreamCaptureStub::HandleEnableDeferredType(MessageParcel &data)
167 {
168     CHECK_ERROR_RETURN_RET(!CheckSystemApp(), CAMERA_NO_PERMISSION);
169     int32_t type = data.ReadInt32();
170     int32_t ret = DeferImageDeliveryFor(type);
171     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleEnableDeferredType result: %{public}d", ret);
172     return ret;
173 }
174 
HandleSetMovingPhotoVideoCodecType(MessageParcel & data)175 int32_t HStreamCaptureStub::HandleSetMovingPhotoVideoCodecType(MessageParcel &data)
176 {
177     int32_t type = data.ReadInt32();
178     int32_t ret = SetMovingPhotoVideoCodecType(type);
179     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleSetMovingPhotoVideoCodecType result: %{public}d", ret);
180     return ret;
181 }
182 
HandleSetCallback(MessageParcel & data)183 int32_t HStreamCaptureStub::HandleSetCallback(MessageParcel &data)
184 {
185     auto remoteObject = data.ReadRemoteObject();
186     CHECK_ERROR_RETURN_RET_LOG(remoteObject == nullptr, IPC_STUB_INVALID_DATA_ERR,
187         "HStreamCaptureStub HandleSetCallback StreamCaptureCallback is null");
188 
189     auto callback = iface_cast<IStreamCaptureCallback>(remoteObject);
190     CHECK_ERROR_RETURN_RET_LOG(callback == nullptr, IPC_STUB_INVALID_DATA_ERR,
191         "HStreamCaptureStub HandleSetCallback callback is null");
192     return SetCallback(callback);
193 }
194 
HandleAddMediaLibraryPhotoProxy(MessageParcel & data)195 int32_t HStreamCaptureStub::HandleAddMediaLibraryPhotoProxy(MessageParcel& data)
196 {
197     sptr<CameraPhotoProxy> photoProxy = new CameraPhotoProxy();
198     photoProxy->ReadFromParcel(data);
199     int ret = UpdateMediaLibraryPhotoAssetProxy(photoProxy);
200     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE,
201         "HStreamCaptureStub::HandleAddMediaLibraryPhotoProxy failed : %{public}d", ret);
202     return ret;
203 }
204 
HandleSetCameraPhotoRotation(MessageParcel & data)205 int32_t HStreamCaptureStub::HandleSetCameraPhotoRotation(MessageParcel& data)
206 {
207     bool isEnable = data.ReadBool();
208 
209     int ret = SetCameraPhotoRotation(isEnable);
210     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE, "HStreamCaptureStub::SetCameraPhotoRotation failed : %{public}d", ret);
211     return ret;
212 }
213 
HandleAcquireBufferToPrepareProxy(MessageParcel & data)214 int32_t HStreamCaptureStub::HandleAcquireBufferToPrepareProxy(MessageParcel& data)
215 {
216     int32_t captureId = data.ReadInt32();
217     int32_t ret = AcquireBufferToPrepareProxy(captureId);
218     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE,
219                           "HStreamCaptureStub::HandleAcquireBufferToPrepareProxy failed : %{public}d", ret);
220     return ret;
221 }
222 
HandleEnableOfflinePhoto(MessageParcel & data)223 int32_t HStreamCaptureStub::HandleEnableOfflinePhoto(MessageParcel& data)
224 {
225     bool isEnable = data.ReadBool();
226     int32_t ret = EnableOfflinePhoto(isEnable);
227     CHECK_ERROR_PRINT_LOG(ret != ERR_NONE,
228         "HStreamCaptureStub::HandleEnableOfflinePhoto failed : %{public}d", ret);
229     return ret;
230 }
231 
HandleCreateMediaLibrary(MessageParcel & data,MessageParcel & reply)232 int32_t HStreamCaptureStub::HandleCreateMediaLibrary(MessageParcel& data, MessageParcel &reply)
233 {
234     sptr<CameraPhotoProxy> photoProxy = new CameraPhotoProxy();
235     photoProxy->ReadFromParcel(data);
236     int64_t timestamp = data.ReadInt64();
237     CHECK_ERROR_RETURN_RET_LOG(photoProxy == nullptr, IPC_STUB_INVALID_DATA_ERR,
238         "HStreamCaptureStub HandleCreateMediaLibrary photoProxy is null");
239     std::string uri;
240     int32_t cameraShotType = 0;
241     std::string burstKey;
242     int32_t ret = CreateMediaLibrary(photoProxy, uri, cameraShotType, burstKey, timestamp);
243     CHECK_ERROR_RETURN_RET_LOG((!reply.WriteString(uri) || !reply.WriteInt32(cameraShotType) ||
244         !reply.WriteString(burstKey)), IPC_STUB_WRITE_PARCEL_ERR,
245         "HStreamCaptureStub HandleCreateMediaLibrary Write uri and cameraShotType failed");
246     return ret;
247 }
248 
HandleCreateMediaLibraryForPicture(MessageParcel & data,MessageParcel & reply)249 int32_t HStreamCaptureStub::HandleCreateMediaLibraryForPicture(MessageParcel& data, MessageParcel &reply)
250 {
251     std::shared_ptr<PictureIntf> pictureProxy = PictureProxy::CreatePictureProxy();
252     CHECK_ERROR_RETURN_RET_LOG(pictureProxy == nullptr || pictureProxy.use_count() != 1, IPC_STUB_INVALID_DATA_ERR,
253         "pictureProxy use count is not 1");
254     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleCreateMediaLibraryForPicture Picture::Unmarshalling E");
255     pictureProxy->Unmarshalling(data);
256     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleCreateMediaLibraryForPicture Picture::Unmarshalling X");
257     CHECK_ERROR_RETURN_RET_LOG(pictureProxy == nullptr, IPC_STUB_INVALID_DATA_ERR,
258         "HStreamCaptureStub HandleCreateMediaLibrary picture is null");
259     sptr<CameraPhotoProxy> photoProxy = new CameraPhotoProxy();
260     photoProxy->ReadFromParcel(data);
261     CHECK_ERROR_RETURN_RET_LOG(photoProxy == nullptr, IPC_STUB_INVALID_DATA_ERR,
262         "HStreamCaptureStub HandleCreateMediaLibrary photoProxy is null");
263     int64_t timestamp = data.ReadInt64();
264     std::string uri;
265     int32_t cameraShotType = 0;
266     std::string burstKey;
267     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleCreateMediaLibraryForPicture E");
268     int32_t ret = CreateMediaLibrary(pictureProxy, photoProxy, uri, cameraShotType, burstKey, timestamp);
269     MEDIA_DEBUG_LOG("HStreamCaptureStub HandleCreateMediaLibraryForPicture X");
270     CHECK_ERROR_RETURN_RET_LOG((!(reply.WriteString(uri)) || !(reply.WriteInt32(cameraShotType)) ||
271         !(reply.WriteString(burstKey))), IPC_STUB_WRITE_PARCEL_ERR,
272         "HStreamCaptureStub HandleCreateMediaLibrary Write uri and cameraShotType failed");
273     return ret;
274 }
275 } // namespace CameraStandard
276 } // namespace OHOS
277