1 /*
2 * Copyright (c) 2025 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 #include "photo_asset_proxy.h"
16 #include "camera_log.h"
17 #include "photo_proxy.h"
18 namespace OHOS {
19 namespace CameraStandard {
20 typedef PhotoAssetIntf* (*CreatePhotoAssetIntf)(int32_t, int32_t);
GetPhotoAssetProxy(int32_t shootType,int32_t callingUid)21 std::shared_ptr<PhotoAssetProxy> PhotoAssetProxy::GetPhotoAssetProxy(int32_t shootType, int32_t callingUid)
22 {
23 auto dynamiclib = CameraDynamicLoader::GetDynamiclib(MEDIA_LIB_SO);
24 CHECK_ERROR_RETURN_RET_LOG(
25 dynamiclib == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get dynamiclib fail");
26 CreatePhotoAssetIntf createPhotoAssetIntf = (CreatePhotoAssetIntf)dynamiclib->GetFunction("createPhotoAssetIntf");
27 CHECK_ERROR_RETURN_RET_LOG(
28 createPhotoAssetIntf == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get createPhotoAssetIntf fail");
29 PhotoAssetIntf* photoAssetIntf = createPhotoAssetIntf(shootType, callingUid);
30 CHECK_ERROR_RETURN_RET_LOG(
31 photoAssetIntf == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get photoAssetIntf fail");
32 std::shared_ptr<PhotoAssetProxy> photoAssetProxy =
33 std::make_shared<PhotoAssetProxy>(dynamiclib, std::shared_ptr<PhotoAssetIntf>(photoAssetIntf));
34 return photoAssetProxy;
35 }
36
PhotoAssetProxy(std::shared_ptr<Dynamiclib> mediaLibraryLib,std::shared_ptr<PhotoAssetIntf> photoAssetIntf)37 PhotoAssetProxy::PhotoAssetProxy(
38 std::shared_ptr<Dynamiclib> mediaLibraryLib, std::shared_ptr<PhotoAssetIntf> photoAssetIntf)
39 : mediaLibraryLib_(mediaLibraryLib), photoAssetIntf_(photoAssetIntf)
40 {
41 CHECK_ERROR_RETURN_LOG(mediaLibraryLib_ == nullptr, "PhotoAssetProxy construct mediaLibraryLib is null");
42 CHECK_ERROR_RETURN_LOG(photoAssetIntf_ == nullptr, "PhotoAssetProxy construct photoAssetIntf is null");
43 }
44
45 // LCOV_EXCL_START
AddPhotoProxy(sptr<Media::PhotoProxy> photoProxy)46 void PhotoAssetProxy::AddPhotoProxy(sptr<Media::PhotoProxy> photoProxy)
47 {
48 CHECK_ERROR_RETURN_LOG(photoAssetIntf_ == nullptr, "PhotoAssetProxy::AddPhotoProxy photoAssetIntf_ is null");
49 photoAssetIntf_->AddPhotoProxy(photoProxy);
50 }
51
GetPhotoAssetUri()52 std::string PhotoAssetProxy::GetPhotoAssetUri()
53 {
54 CHECK_ERROR_RETURN_RET_LOG(
55 photoAssetIntf_ == nullptr, "", "PhotoAssetProxy::GetPhotoAssetUri photoAssetIntf_ is null");
56 return photoAssetIntf_->GetPhotoAssetUri();
57 }
58
GetVideoFd()59 int32_t PhotoAssetProxy::GetVideoFd()
60 {
61 CHECK_ERROR_RETURN_RET_LOG(photoAssetIntf_ == nullptr, -1, "PhotoAssetProxy::GetVideoFd photoAssetIntf_ is null");
62 return photoAssetIntf_->GetVideoFd();
63 }
64
NotifyVideoSaveFinished()65 void PhotoAssetProxy::NotifyVideoSaveFinished()
66 {
67 CHECK_ERROR_RETURN_LOG(
68 photoAssetIntf_ == nullptr, "PhotoAssetProxy::NotifyVideoSaveFinished photoAssetIntf_ is null");
69 photoAssetIntf_->NotifyVideoSaveFinished();
70 }
71
GetUserId()72 int32_t PhotoAssetProxy::GetUserId()
73 {
74 CHECK_ERROR_RETURN_RET_LOG(photoAssetIntf_ == nullptr, -1, "PhotoAssetProxy::GetUserId photoAssetIntf_ is null");
75 return photoAssetIntf_->GetUserId();
76 }
77 // LCOV_EXCL_STOP
78 } // namespace CameraStandard
79 } // namespace OHOS