• 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 
16 #include "cloud_enhancement_ani.h"
17 #include "file_asset_ani.h"
18 #include "fetch_result_ani.h"
19 #include "media_album_change_request_ani.h"
20 #include "media_asset_change_request_ani.h"
21 #include "media_assets_change_request_ani.h"
22 #include "media_library_ani.h"
23 #include "medialibrary_ani_log.h"
24 #include "moving_photo_ani.h"
25 #include "photo_album_ani.h"
26 #include "photo_proxy_ani.h"
27 
28 using namespace OHOS::Media;
29 
30 namespace OHOS::Media::Ani {
GlobalFunctionInit(ani_env * env)31 ani_status GlobalFunctionInit(ani_env *env)
32 {
33     const char *namespaceName = "L@ohos/file/photoAccessHelper/photoAccessHelper;";
34     ani_namespace ns;
35     if (ANI_OK != env->FindNamespace(namespaceName, &ns)) {
36         ANI_ERR_LOG("Not found namespace: %{public}s", namespaceName);
37         return ANI_ERROR;
38     }
39 
40     std::array staticMethods = {
41         ani_native_function {"getPhotoAccessHelper", nullptr, reinterpret_cast<void *>(MediaLibraryAni::Constructor)},
42     };
43 
44     if (ANI_OK != env->Namespace_BindNativeFunctions(ns, staticMethods.data(), staticMethods.size())) {
45         ANI_ERR_LOG("Cannot bind native methods to namespace: %{public}s", namespaceName);
46         return ANI_ERROR;
47     };
48 
49     ANI_INFO_LOG("GlobalFunctionInit ok");
50     return ANI_OK;
51 }
52 } // namespace OHOS::Media::Ani
53 
ANI_Constructor(ani_vm * vm,uint32_t * result)54 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
55 {
56     ANI_INFO_LOG("ANI_Constructor start");
57     ani_env *env;
58     if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) {
59         ANI_ERR_LOG("Unsupported %{public}d", ANI_VERSION_1);
60         return ANI_ERROR;
61     }
62 
63     CHECK_STATUS_RET(OHOS::Media::Ani::GlobalFunctionInit(env), "GlobalFunctionInit fail");
64     CHECK_STATUS_RET(MediaLibraryAni::PhotoAccessHelperInit(env), "PhotoAccessHelperInit fail");
65     CHECK_STATUS_RET(PhotoAlbumAni::PhotoAccessInit(env), "PhotoAccessInit fail");
66     CHECK_STATUS_RET(FileAssetAni::FileAssetAniInit(env), "FileAssetAniInit fail");
67     CHECK_STATUS_RET(FetchFileResultAni::FetchFileResultInit(env), "FetchFileResultInit fail");
68     CHECK_STATUS_RET(MovingPhotoAni::MovingPhotoInit(env), "MovingPhotoInit fail");
69 
70     *result = ANI_VERSION_1;
71     return ANI_OK;
72 }