未验证 提交 cb21afdf 编写于 作者: O openharmony_ci 提交者: Gitee

!286 添加查询设备是否支持指定的SystemCapability。

Merge pull request !286 from chenyude/commit-syscap
......@@ -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"
......
......@@ -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
......
/*
* 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 <stdbool.h>
#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
/*
* 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 <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册