1 /*
2  * Copyright (c) 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 #ifndef FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_DATA_ABILITY_HELPER_STANDARD_H
17 #define FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_DATA_ABILITY_HELPER_STANDARD_H
18 
19 #include "base/resource/data_ability_helper.h"
20 
21 #ifdef MEDIA_LIBRARY_EXISTS
22 #include "media_library_manager.h"
23 #endif
24 
25 #include "pixel_map.h"
26 
27 namespace OHOS::AppExecFwk {
28 class DataAbilityHelper;
29 class Context;
30 } // namespace OHOS::AppExecFwk
31 
32 namespace OHOS::AbilityRuntime {
33 class Context;
34 }
35 
36 namespace OHOS::DataShare {
37 class DataShareHelper;
38 }
39 
40 namespace OHOS {
41 class Uri;
42 }
43 
44 namespace OHOS::Ace {
45 
46 class ACE_FORCE_EXPORT DataAbilityHelperStandard : public DataAbilityHelper {
47     DECLARE_ACE_TYPE(DataAbilityHelperStandard, DataAbilityHelper)
48 
49 public:
50     DataAbilityHelperStandard(const std::shared_ptr<OHOS::AppExecFwk::Context>& context,
51         const std::shared_ptr<OHOS::AbilityRuntime::Context>& runtimeContext, bool useStageModel);
52     ~DataAbilityHelperStandard() override = default;
53 
54     int32_t OpenFile(const std::string& uriStr, const std::string& mode) override;
55     void* QueryThumbnailResFromDataAbility(const std::string& uri) override;
56     int32_t ReadMovingPhotoVideo(const std::string &uri) override;
57     std::string GetMovingPhotoImageUri(const std::string& uri) override;
58     int64_t GetMovingPhotoDateModified(const std::string& uri) override;
59 
60 private:
61     int32_t OpenFileWithDataAbility(const std::string& uriStr, const std::string& mode);
62     int32_t OpenFileWithDataShare(const std::string& uriStr, const std::string& mode);
63 
64     bool useStageModel_ = false;
65     std::shared_ptr<DataShare::DataShareHelper> dataShareHelper_;
66     std::shared_ptr<AppExecFwk::DataAbilityHelper> dataAbilityHelper_;
67     std::weak_ptr<OHOS::AbilityRuntime::Context> runtimeContext_;
68     std::weak_ptr<OHOS::AppExecFwk::Context> context_;
69 #ifdef MEDIA_LIBRARY_EXISTS
70     OHOS::Media::MediaLibraryManager mgr_;
71 #endif
72 };
73 
74 } // namespace OHOS::Ace
75 
76 #endif // FOUNDATION_ACE_ACE_ENGINE_ADAPTER_OHOS_CPP_DATA_ABILITY_HELPER_STANDARD_H
77