• 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 <ani.h>
17 
18 #include "ani_signature.h"
19 #include "bind_function.h"
20 #include "environment_ani.h"
21 
22 using namespace OHOS::FileManagement::ModuleFileIO::ANI;
23 using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature;
24 
BindStaticMethods(ani_env * env)25 static ani_status BindStaticMethods(ani_env *env)
26 {
27     auto classDesc = Impl::EnvironmentImpl::classDesc.c_str();
28     std::array methods = {
29         ani_native_function {
30             "getStorageDataDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetStorageDataDirSync) },
31         ani_native_function {
32             "getUserDataDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetUserDataDirSync) },
33         ani_native_function {
34             "getUserDownloadDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetUserDownloadDirSync) },
35         ani_native_function {
36             "getUserDesktopDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetUserDesktopDirSync) },
37         ani_native_function {
38             "getUserDocumentDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetUserDocumentDirSync) },
39         ani_native_function {
40             "getExternalStorageDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetExternalStorageDirSync) },
41         ani_native_function {
42             "getUserHomeDirSync", nullptr, reinterpret_cast<void *>(EnvironmentAni::GetUserHomeDirSync) },
43     };
44     return BindClass(env, classDesc, methods);
45 }
46 
ANI_Constructor(ani_vm * vm,uint32_t * result)47 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
48 {
49     if (vm == nullptr) {
50         HILOGE("Invalid parameter vm");
51         return ANI_INVALID_ARGS;
52     }
53 
54     if (result == nullptr) {
55         HILOGE("Invalid parameter result");
56         return ANI_INVALID_ARGS;
57     }
58 
59     ani_env *env;
60     ani_status status = vm->GetEnv(ANI_VERSION_1, &env);
61     if (status != ANI_OK) {
62         HILOGE("Invalid ani version!");
63         return ANI_INVALID_VERSION;
64     }
65 
66     status = BindStaticMethods(env);
67     if (status != ANI_OK) {
68         HILOGE("Cannot bind native static methods for environment!");
69         return status;
70     };
71 
72     *result = ANI_VERSION_1;
73     return ANI_OK;
74 }
75