• 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 #include "ani_signature.h"
18 #include "bind_function.h"
19 #include "securitylabel_ani.h"
20 
21 using namespace OHOS::FileManagement::ModuleFileIO::ANI;
22 using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature;
23 
BindStaticMethods(ani_env * env)24 static ani_status BindStaticMethods(ani_env *env)
25 {
26     auto classDesc = Impl::SecurityLabelImpl::classDesc.c_str();
27     std::array methods = {
28         ani_native_function {
29             "setSecurityLabelSync", nullptr, reinterpret_cast<void *>(SecurityLabelAni::SetSecurityLabelSync) },
30         ani_native_function {
31             "getSecurityLabelSync", nullptr, reinterpret_cast<void *>(SecurityLabelAni::GetSecurityLabelSync) },
32     };
33     return BindClass(env, classDesc, methods);
34 }
35 
ANI_Constructor(ani_vm * vm,uint32_t * result)36 ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result)
37 {
38     if (vm == nullptr) {
39         HILOGE("Invalid parameter vm");
40         return ANI_INVALID_ARGS;
41     }
42 
43     if (result == nullptr) {
44         HILOGE("Invalid parameter result");
45         return ANI_INVALID_ARGS;
46     }
47 
48     ani_env *env;
49     ani_status status = vm->GetEnv(ANI_VERSION_1, &env);
50     if (status != ANI_OK) {
51         HILOGE("Invalid ani version!");
52         return ANI_INVALID_VERSION;
53     }
54 
55     status = BindStaticMethods(env);
56     if (status != ANI_OK) {
57         HILOGE("Cannot bind native static methods for securitylabel!");
58         return status;
59     };
60 
61     *result = ANI_VERSION_1;
62     return ANI_OK;
63 }
64