diff --git a/bundle.json b/bundle.json index 04cb865aba4c6c6d993bdb36f20aa77e0f2485dc..52a2ec232dbf32f05c774cd99d5b982c415e841a 100644 --- a/bundle.json +++ b/bundle.json @@ -57,7 +57,8 @@ "fs_manager/fs_manager.h", "init_reboot.h", "service_control.h", - "beget_ext.h" + "beget_ext.h", + "systemcapability.h" ] }, "name": "//base/startup/init_lite/interfaces/innerkits:libbegetutil" diff --git a/interfaces/innerkits/BUILD.gn b/interfaces/innerkits/BUILD.gn index c26fb412e55237e466a6c4a630b8ef0d6517a6ab..fa15eb8b7460c63f9348ccdb789e75a74465c2c1 100755 --- a/interfaces/innerkits/BUILD.gn +++ b/interfaces/innerkits/BUILD.gn @@ -31,6 +31,7 @@ ohos_shared_library("libbegetutil") { "reboot/init_reboot_innerkits.c", "service_control/service_control.c", "socket/init_socket.c", + "syscap/init_syscap.c", ] sources += fs_manager_sources diff --git a/interfaces/innerkits/include/systemcapability.h b/interfaces/innerkits/include/systemcapability.h new file mode 100644 index 0000000000000000000000000000000000000000..b8d5fb0c86066cadb2329df1f50234180294722b --- /dev/null +++ b/interfaces/innerkits/include/systemcapability.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef INIT_SYSCAP_API_H +#define INIT_SYSCAP_API_H + +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + + +bool HasSystemCapability(const char *cap); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif \ No newline at end of file diff --git a/interfaces/innerkits/syscap/init_syscap.c b/interfaces/innerkits/syscap/init_syscap.c new file mode 100644 index 0000000000000000000000000000000000000000..72fbb622f56a05a636f93817a842127baaae4790 --- /dev/null +++ b/interfaces/innerkits/syscap/init_syscap.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "sys_param.h" +#include "beget_ext.h" +#include "securec.h" +#include "systemcapability.h" + +#define SYSCAP_MAX_SIZE 100 +#define SYSCAP_PREFIX_NAME "SystemCapability" + +bool HasSystemCapability(const char *cap) +{ + char capName[SYSCAP_MAX_SIZE] = { 0 }; + char paramValue[PARAM_VALUE_LEN_MAX] = { 0 }; + unsigned int valueLen = PARAM_VALUE_LEN_MAX; + + if (strncmp(SYSCAP_PREFIX_NAME, cap, sizeof(SYSCAP_PREFIX_NAME) - 1) != 0) { + if (strncpy_s(capName, sizeof(capName), cap, sizeof(capName) - 1) < 0) { + BEGET_LOGE("Failed strncpy_s err=%d", errno); + return false; + } + } else if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, SYSCAP_PREFIX_NAME".%s", cap) == -1) { + BEGET_LOGE("Failed snprintf_s err=%d", errno); + return false; + } + + if (SystemGetParameter(capName, paramValue, &valueLen) != 0) { + BEGET_LOGE("Failed get paramName."); + return false; + } + + return true; +} \ No newline at end of file