• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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, uint32_t);
GetPhotoAssetProxy(int32_t shootType,int32_t callingUid,uint32_t callingTokenID)21 std::shared_ptr<PhotoAssetProxy> PhotoAssetProxy::GetPhotoAssetProxy(
22     int32_t shootType, int32_t callingUid, uint32_t callingTokenID)
23 {
24     MEDIA_DEBUG_LOG("GetPhotoAssetProxy E callingUid:%{public}d", callingUid);
25     auto dynamiclib = CameraDynamicLoader::GetDynamiclib(MEDIA_LIB_SO);
26     CHECK_RETURN_RET_ELOG(
27         dynamiclib == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get dynamiclib fail");
28     CreatePhotoAssetIntf createPhotoAssetIntf = (CreatePhotoAssetIntf)dynamiclib->GetFunction("createPhotoAssetIntf");
29     CHECK_RETURN_RET_ELOG(
30         createPhotoAssetIntf == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get createPhotoAssetIntf fail");
31     PhotoAssetIntf* photoAssetIntf = createPhotoAssetIntf(shootType, callingUid, callingTokenID);
32     CHECK_RETURN_RET_ELOG(
33         photoAssetIntf == nullptr, nullptr, "PhotoAssetProxy::GetPhotoAssetProxy get photoAssetIntf fail");
34     std::shared_ptr<PhotoAssetProxy> photoAssetProxy =
35         std::make_shared<PhotoAssetProxy>(dynamiclib, std::shared_ptr<PhotoAssetIntf>(photoAssetIntf));
36     return photoAssetProxy;
37 }
38 
PhotoAssetProxy(std::shared_ptr<Dynamiclib> mediaLibraryLib,std::shared_ptr<PhotoAssetIntf> photoAssetIntf)39 PhotoAssetProxy::PhotoAssetProxy(
40     std::shared_ptr<Dynamiclib> mediaLibraryLib, std::shared_ptr<PhotoAssetIntf> photoAssetIntf)
41     : mediaLibraryLib_(mediaLibraryLib), photoAssetIntf_(photoAssetIntf)
42 {
43     CHECK_RETURN_ELOG(mediaLibraryLib_ == nullptr, "PhotoAssetProxy construct mediaLibraryLib is null");
44     CHECK_RETURN_ELOG(photoAssetIntf_ == nullptr, "PhotoAssetProxy construct photoAssetIntf is null");
45 }
46 
47 // LCOV_EXCL_START
AddPhotoProxy(sptr<Media::PhotoProxy> photoProxy)48 void PhotoAssetProxy::AddPhotoProxy(sptr<Media::PhotoProxy> photoProxy)
49 {
50     CHECK_RETURN_ELOG(photoAssetIntf_ == nullptr, "PhotoAssetProxy::AddPhotoProxy photoAssetIntf_ is null");
51     photoAssetIntf_->AddPhotoProxy(photoProxy);
52 }
53 
GetPhotoAssetUri()54 std::string PhotoAssetProxy::GetPhotoAssetUri()
55 {
56     CHECK_RETURN_RET_ELOG(
57         photoAssetIntf_ == nullptr, "", "PhotoAssetProxy::GetPhotoAssetUri photoAssetIntf_ is null");
58     return photoAssetIntf_->GetPhotoAssetUri();
59 }
60 
GetVideoFd()61 int32_t PhotoAssetProxy::GetVideoFd()
62 {
63     CHECK_RETURN_RET_ELOG(photoAssetIntf_ == nullptr, -1, "PhotoAssetProxy::GetVideoFd photoAssetIntf_ is null");
64     return photoAssetIntf_->GetVideoFd();
65 }
66 
NotifyVideoSaveFinished()67 void PhotoAssetProxy::NotifyVideoSaveFinished()
68 {
69     CHECK_RETURN_ELOG(
70         photoAssetIntf_ == nullptr, "PhotoAssetProxy::NotifyVideoSaveFinished photoAssetIntf_ is null");
71     photoAssetIntf_->NotifyVideoSaveFinished();
72 }
73 
GetUserId()74 int32_t PhotoAssetProxy::GetUserId()
75 {
76     CHECK_RETURN_RET_ELOG(photoAssetIntf_ == nullptr, -1, "PhotoAssetProxy::GetUserId photoAssetIntf_ is null");
77     return photoAssetIntf_->GetUserId();
78 }
79 // LCOV_EXCL_STOP
80 } // namespace CameraStandard
81 } // namespace OHOS