From a81c92f68892885aab461ce6407dcbe75d53ce18 Mon Sep 17 00:00:00 2001 From: zhuofan0129 <861080528@qq.com> Date: Tue, 27 Feb 2024 15:58:58 +0800 Subject: [PATCH] feat: add interface for querying level to softbus Signed-off-by: zhuofan0129 <861080528@qq.com> --- bundle.json | 2 ++ interfaces/inner_api/BUILD.gn | 1 + .../inner_api/include/device_security_info.h | 13 +++++++++ .../src/standard/device_security_info.cpp | 28 +++++++++++++++++++ param/BUILD.gn | 28 +++++++++++++++++++ param/device_security_level.para | 14 ++++++++++ 6 files changed, 86 insertions(+) create mode 100644 param/BUILD.gn create mode 100644 param/device_security_level.para diff --git a/bundle.json b/bundle.json index 2237dab..cba9724 100644 --- a/bundle.json +++ b/bundle.json @@ -36,6 +36,7 @@ "hisysevent", "hitrace", "huks", + "init", "ipc", "safwk", "samgr" @@ -54,6 +55,7 @@ "service_group": [ "//base/security/device_security_level/oem_property/ohos:dslm_service", "//base/security/device_security_level/oem_property/ohos:dslm_ohos_cred_file", + "//base/security/device_security_level/param:param_files", "//base/security/device_security_level/profile:dslm_service.rc" ] }, diff --git a/interfaces/inner_api/BUILD.gn b/interfaces/inner_api/BUILD.gn index db7e859..e5b15a0 100644 --- a/interfaces/inner_api/BUILD.gn +++ b/interfaces/inner_api/BUILD.gn @@ -129,6 +129,7 @@ if (defined(ohos_lite)) { external_deps = [ "c_utils:utils", "hilog:libhilog", + "init:libbegetutil", "ipc:ipc_core", "samgr:samgr_proxy", ] diff --git a/interfaces/inner_api/include/device_security_info.h b/interfaces/inner_api/include/device_security_info.h index ba34284..23e25f4 100644 --- a/interfaces/inner_api/include/device_security_info.h +++ b/interfaces/inner_api/include/device_security_info.h @@ -67,6 +67,19 @@ void FreeDeviceSecurityInfo(DeviceSecurityInfo *info); */ int32_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo *info, int32_t *level); +/** + * Gets the device security level from param. + * @param [out] level Device security level. + * @return + */ +int32_t GetSelfDeviceSecurityLevelValue(int32_t *level); + +/** + * Judge the device security level changeable. + * @return + */ +int32_t IsDeviceSecurityLevelChangeable(const char *udid, int32_t level); + #ifdef __cplusplus } #endif diff --git a/interfaces/inner_api/src/standard/device_security_info.cpp b/interfaces/inner_api/src/standard/device_security_info.cpp index 3118cb2..d2edb45 100644 --- a/interfaces/inner_api/src/standard/device_security_info.cpp +++ b/interfaces/inner_api/src/standard/device_security_info.cpp @@ -18,6 +18,7 @@ #include #include "hilog/log.h" +#include "parameter.h" #include "device_security_level_callback_helper.h" #include "device_security_level_callback_stub.h" @@ -111,6 +112,23 @@ static int32_t GetDeviceSecurityLevelValueImpl(const DeviceSecurityInfo *info, i return static_cast(info->result); } +int32_t GetSelfDeviceSecurityLevelValueImpl(int32_t *level) +{ + const char key[128] = "const.security.device_security_level"; + int32_t def = 0; + int32_t levelGet = GetIntParameter(key, def); + *level = levelGet; + if (levelGet == -1) { + return -1; + } + return 0; +} + +int32_t IsDeviceSecurityLevelChangeableImpl(const char *udid, int32_t level) +{ + return 0; +} + #ifdef __cplusplus extern "C" { #endif @@ -137,6 +155,16 @@ int32_t GetDeviceSecurityLevelValue(const DeviceSecurityInfo *info, int32_t *lev return GetDeviceSecurityLevelValueImpl(info, level); } +int32_t GetSelfDeviceSecurityLevelValue(int32_t *level) +{ + return GetSelfDeviceSecurityLevelValueImpl(level); +} + +int32_t IsDeviceSecurityLevelChangeable(const char *udid, int32_t level) +{ + return IsDeviceSecurityLevelChangeableImpl(udid, level); +} + #ifdef __cplusplus } #endif diff --git a/param/BUILD.gn b/param/BUILD.gn new file mode 100644 index 0000000..2619f76 --- /dev/null +++ b/param/BUILD.gn @@ -0,0 +1,28 @@ +# Copyright (c) 2024 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. + +import("//build/ohos.gni") + +## Install device_security_level.para to /system/etc/param/device_security_level.para + +group("param_files") { + deps = [ ":device_security_level.para" ] +} + +ohos_prebuilt_etc("device_security_level.para") { + source = "device_security_level.para" + + relative_install_dir = "param" + part_name = "device_security_level" + subsystem_name = "security" +} diff --git a/param/device_security_level.para b/param/device_security_level.para new file mode 100644 index 0000000..c04f0d7 --- /dev/null +++ b/param/device_security_level.para @@ -0,0 +1,14 @@ +# Copyright (c) 2024 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. + +const.security.device_security_level = 1 \ No newline at end of file -- Gitee