From adba8eafcaf64053abe939103acb2d128a3899e3 Mon Sep 17 00:00:00 2001 From: yang1946 Date: Tue, 2 Jul 2024 11:32:01 +0800 Subject: [PATCH] =?UTF-8?q?hilog=E8=BD=BB=E9=87=8F=E5=8C=96=E6=95=B4?= =?UTF-8?q?=E6=94=B9=E9=81=97=E7=95=99=E9=97=AE=E9=A2=98=E9=97=AD=E7=8E=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yang1946 --- services/key_enable/BUILD.gn | 1 + services/key_enable/utils/include/cert_path.h | 4 ---- .../utils/include/key_enable_adapter.h | 4 ---- services/key_enable/utils/include/key_utils.h | 4 ---- .../utils/include/unlock_event_helper.h | 4 ---- services/key_enable/utils/src/cert_path.cpp | 7 ++---- .../key_enable/utils/src/devices_security.cpp | 16 ++++++------- services/key_enable/utils/src/key_utils.cpp | 6 ++--- .../utils/src/unlock_event_helper.cpp | 24 +++++++++---------- test/unittest/BUILD.gn | 1 + utils/include/log.h | 22 ----------------- 11 files changed, 25 insertions(+), 68 deletions(-) diff --git a/services/key_enable/BUILD.gn b/services/key_enable/BUILD.gn index 5ba1c7d..d131a1e 100644 --- a/services/key_enable/BUILD.gn +++ b/services/key_enable/BUILD.gn @@ -17,6 +17,7 @@ import("../../code_signature.gni") common_deps = [ "utils:libkey_enable_utils" ] common_external_deps = [ "hilog:hilog_rust", + "hilog:libhilog", "hisysevent:hisysevent_rust", "ylong_json:lib", ] diff --git a/services/key_enable/utils/include/cert_path.h b/services/key_enable/utils/include/cert_path.h index 114ad30..f4f05f8 100644 --- a/services/key_enable/utils/include/cert_path.h +++ b/services/key_enable/utils/include/cert_path.h @@ -16,10 +16,6 @@ #ifndef CODE_SIGN_IOCTL_UTILS_H #define CODE_SIGN_IOCTL_UTILS_H -#ifndef LOG_RUST -#define LOG_RUST -#endif - #include #define CERT_DEVICE_PATH "/dev/code_sign" diff --git a/services/key_enable/utils/include/key_enable_adapter.h b/services/key_enable/utils/include/key_enable_adapter.h index fe61509..66f140e 100644 --- a/services/key_enable/utils/include/key_enable_adapter.h +++ b/services/key_enable/utils/include/key_enable_adapter.h @@ -16,10 +16,6 @@ #ifndef CODE_SIGN_KEY_ENABLE_ADAPTER_H #define CODE_SIGN_KEY_ENABLE_ADAPTER_H -#ifndef LOG_RUST -#define LOG_RUST -#endif - #include #ifdef __cplusplus diff --git a/services/key_enable/utils/include/key_utils.h b/services/key_enable/utils/include/key_utils.h index 7ba018c..cb55a03 100644 --- a/services/key_enable/utils/include/key_utils.h +++ b/services/key_enable/utils/include/key_utils.h @@ -16,10 +16,6 @@ #ifndef CODE_SIGN_KEY_UTILS_H #define CODE_SIGN_KEY_UTILS_H -#ifndef LOG_RUST -#define LOG_RUST -#endif - #include typedef int32_t KeySerial; diff --git a/services/key_enable/utils/include/unlock_event_helper.h b/services/key_enable/utils/include/unlock_event_helper.h index ddc245c..e6711ef 100644 --- a/services/key_enable/utils/include/unlock_event_helper.h +++ b/services/key_enable/utils/include/unlock_event_helper.h @@ -24,10 +24,6 @@ #include "common_event_support.h" #include "iservice_registry.h" -#ifndef LOG_RUST -#define LOG_RUST -#endif - namespace OHOS { namespace Security { namespace CodeSign { diff --git a/services/key_enable/utils/src/cert_path.cpp b/services/key_enable/utils/src/cert_path.cpp index c461825..3bba8d0 100644 --- a/services/key_enable/utils/src/cert_path.cpp +++ b/services/key_enable/utils/src/cert_path.cpp @@ -26,20 +26,17 @@ #include "log.h" #include "errcode.h" -using namespace OHOS::Security::CodeSign; - static int IoctlCertPathOperation(const CertPathInfo &info, int cmd, const char *operation) { int fd = open(CERT_DEVICE_PATH, O_WRONLY); if (fd == -1) { - LOG_ERROR(LABEL, "Error opening device, errno = <%{public}d, %{public}s>", errno, strerror(errno)); + LOG_ERROR("Error opening device, errno = <%{public}d, %{public}s>", errno, strerror(errno)); return CS_ERR_FILE_OPEN; } int ret = ioctl(fd, cmd, &info); if (ret < 0) { - LOG_ERROR( - LABEL, "%s cert path ioctl error, errno = <%{public}d, %{public}s>", operation, errno, strerror(errno)); + LOG_ERROR("%s cert path ioctl error, errno = <%{public}d, %{public}s>", operation, errno, strerror(errno)); close(fd); return ret; } diff --git a/services/key_enable/utils/src/devices_security.cpp b/services/key_enable/utils/src/devices_security.cpp index 3ccca6e..7af85d1 100644 --- a/services/key_enable/utils/src/devices_security.cpp +++ b/services/key_enable/utils/src/devices_security.cpp @@ -25,8 +25,6 @@ #include "log.h" #include "parameter.h" -using namespace OHOS::Security::CodeSign; - enum DeviceMode { NOT_INITIALIZE = 0, DEVICE_MODE_RD, @@ -40,10 +38,10 @@ static int32_t g_isRdDevice = NOT_INITIALIZE; static bool CheckDeviceMode(char *buf, ssize_t bunLen) { if (strstr(buf, "oemmode=rd")) { - LOG_DEBUG(LABEL, "Oemode is rd"); + LOG_DEBUG("Oemode is rd"); return true; } else { - LOG_DEBUG(LABEL, "Not rd mode, cmdline = %{private}s", buf); + LOG_DEBUG("Not rd mode, cmdline = %{private}s", buf); } return false; } @@ -51,10 +49,10 @@ static bool CheckDeviceMode(char *buf, ssize_t bunLen) static int32_t CheckEfuseStatus(char *buf, ssize_t bunLen) { if (strstr(buf, "efuse_status=1")) { - LOG_DEBUG(LABEL, "device is not efused"); + LOG_DEBUG("device is not efused"); return true; } else { - LOG_DEBUG(LABEL, "Not efused, cmdline = %{private}s", buf); + LOG_DEBUG("Not efused, cmdline = %{private}s", buf); } return false; } @@ -64,7 +62,7 @@ static void ParseCMDLine() int32_t fd = open(PROC_CMDLINE_FILE_PATH.c_str(), O_RDONLY); if (fd < 0) { g_isRdDevice = DEVICE_MODE_NOT_RD; - LOG_ERROR(LABEL, "open %{public}s failed, %{public}s", + LOG_ERROR("open %{public}s failed, %{public}s", PROC_CMDLINE_FILE_PATH.c_str(), strerror(errno)); return; } @@ -73,13 +71,13 @@ static void ParseCMDLine() do { buf = static_cast(malloc(CMDLINE_MAX_BUF_LEN)); if (buf == nullptr) { - LOG_ERROR(LABEL, "Alloc buffer for reading cmdline failed."); + LOG_ERROR("Alloc buffer for reading cmdline failed."); break; } (void) memset_s(buf, CMDLINE_MAX_BUF_LEN, 0, CMDLINE_MAX_BUF_LEN); ssize_t bufLen = read(fd, buf, CMDLINE_MAX_BUF_LEN - 1); if (bufLen < 0) { - LOG_ERROR(LABEL, "Read %{public}s failed, %{public}s.", + LOG_ERROR("Read %{public}s failed, %{public}s.", PROC_CMDLINE_FILE_PATH.c_str(), strerror(errno)); break; } diff --git a/services/key_enable/utils/src/key_utils.cpp b/services/key_enable/utils/src/key_utils.cpp index 82a33cb..f7ae8c0 100644 --- a/services/key_enable/utils/src/key_utils.cpp +++ b/services/key_enable/utils/src/key_utils.cpp @@ -24,8 +24,6 @@ constexpr int KEYCTL_RESTRICT_KEYRING = 29; -using namespace OHOS::Security::CodeSign; - KeySerial AddKey( const char *type, const char *description, @@ -37,7 +35,7 @@ KeySerial AddKey( type, description, static_cast(payload), pLen, ringId); if (ret < 0) { - LOG_ERROR(LABEL, "Add certificate failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Add certificate failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); } return ret; @@ -52,7 +50,7 @@ KeySerial KeyctlRestrictKeyring( KEYCTL_RESTRICT_KEYRING, ringId, type, restriction); if (ret < 0) { - LOG_ERROR(LABEL, "Restrict keyring failed, errno = <%{public}d, %{public}s>", + LOG_ERROR("Restrict keyring failed, errno = <%{public}d, %{public}s>", errno, strerror(errno)); } return ret; diff --git a/services/key_enable/utils/src/unlock_event_helper.cpp b/services/key_enable/utils/src/unlock_event_helper.cpp index 23d97a1..c509fe0 100644 --- a/services/key_enable/utils/src/unlock_event_helper.cpp +++ b/services/key_enable/utils/src/unlock_event_helper.cpp @@ -36,7 +36,7 @@ void UnlockEventHelper::UnlockEventSubscriber::OnReceiveEvent(const EventFwk::Co const auto want = event.GetWant(); const auto action = want.GetAction(); if (action == EventFwk::CommonEventSupport::COMMON_EVENT_SCREEN_UNLOCKED) { - LOG_INFO(LABEL, "receive unlocked event"); + LOG_INFO("receive unlocked event"); UnlockEventHelper::GetInstance().FinishWaiting(); return; } @@ -57,10 +57,10 @@ bool UnlockEventHelper::CheckUserUnlockByScreenLockManager() } bool lockStatus = false; if (ScreenLock::ScreenLockManager::GetInstance()->IsLocked(lockStatus) == ScreenLock::E_SCREENLOCK_OK) { - LOG_INFO(LABEL, "screen locked status = %{private}d", lockStatus); + LOG_INFO("screen locked status = %{private}d", lockStatus); hasUnLocked_ = !lockStatus; } else { - LOG_ERROR(LABEL, "unable get lock screen status"); + LOG_ERROR("unable get lock screen status"); } #endif return hasUnLocked_; @@ -77,21 +77,21 @@ void UnlockEventHelper::InitUnlockEventSubscriber() EventFwk::CommonEventSubscribeInfo eventInfo(matchingSkill); unlockEventSubscriber_ = std::make_shared(eventInfo); hasInited_ = true; - LOG_INFO(LABEL, "Init subscriber success."); + LOG_INFO("Init subscriber success."); } bool UnlockEventHelper::RegisterEvent() { - LOG_INFO(LABEL, "RegisterEvent start"); + LOG_INFO("RegisterEvent start"); if (hasRegistered_) { - LOG_DEBUG(LABEL, "status observer already registered"); + LOG_DEBUG("status observer already registered"); return false; } InitUnlockEventSubscriber(); const auto result = EventFwk::CommonEventManager::SubscribeCommonEvent( unlockEventSubscriber_); if (!result) { - LOG_ERROR(LABEL, "RegisterEvent result is err"); + LOG_ERROR("RegisterEvent result is err"); return false; } hasRegistered_ = true; @@ -100,11 +100,11 @@ bool UnlockEventHelper::RegisterEvent() void UnlockEventHelper::UnregisterEvent() { - LOG_INFO(LABEL, "UnregisterEvent start"); + LOG_INFO("UnregisterEvent start"); const auto result = EventFwk::CommonEventManager::UnSubscribeCommonEvent( unlockEventSubscriber_); if (!result) { - LOG_ERROR(LABEL, "UnregisterEvent result is err"); + LOG_ERROR("UnregisterEvent result is err"); return; } hasRegistered_ = false; @@ -124,10 +124,10 @@ bool UnlockEventHelper::WaitForCommonEventManager() if (samgr != nullptr && samgr->CheckSystemAbility(COMMON_EVENT_MANAGER_ID) != nullptr) { ret = true; - LOG_INFO(LABEL, "Common event manager is loaded."); + LOG_INFO("Common event manager is loaded."); break; } - LOG_DEBUG(LABEL, "Get common event manager failed."); + LOG_DEBUG("Get common event manager failed."); usleep(SEELP_TIME_FOR_COMMON_EVENT_MGR); if (OHOS::GetSystemCurrentTime(&doingTime)) { seconds = OHOS::GetSecondsBetween(startTime, doingTime); @@ -149,7 +149,7 @@ bool UnlockEventHelper::StartWaitingUnlock() return false; } unlockConVar_.wait(lock, [this]() { return this->hasUnLocked_; }); - LOG_INFO(LABEL, "thread is wake up"); + LOG_INFO("thread is wake up"); // only listening the first unlock event UnregisterEvent(); return true; diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 6e55182..30cc85e 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -291,6 +291,7 @@ ohos_unittest("key_enable_utils_unittest") { deps = [ "${code_signature_root_dir}/services/key_enable/utils:libkey_enable_utils", ] + external_deps = [ "hilog:libhilog" ] } group("unittest_group") { diff --git a/utils/include/log.h b/utils/include/log.h index 5bae85a..ee0e166 100644 --- a/utils/include/log.h +++ b/utils/include/log.h @@ -18,7 +18,6 @@ #include "hilog/log.h" -#ifndef LOG_RUST #ifdef LOG_TAG #undef LOG_TAG #endif @@ -35,25 +34,4 @@ #define LOG_ERROR(fmt, ...) HILOG_ERROR(LOG_CORE, "[%{public}s]:" fmt, __func__, ##__VA_ARGS__) #define LOG_FATAL(fmt, ...) HILOG_FATAL(LOG_CORE, "[%{public}s]:" fmt, __func__, ##__VA_ARGS__) -#else // LOG_RUST -namespace OHOS { -namespace Security { -namespace CodeSign { -static constexpr unsigned int SECURITY_DOMAIN = 0xD005A06; -static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN, "CODE_SIGN"}; - -#define LOG_DEBUG(label, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Debug(label, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define LOG_INFO(label, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Info(label, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define LOG_WARN(label, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Warn(label, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define LOG_ERROR(label, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Error(label, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -#define LOG_FATAL(label, fmt, ...) \ - OHOS::HiviewDFX::HiLog::Fatal(label, "%{public}s: " fmt, __func__, ##__VA_ARGS__) -} -} -} -#endif #endif // CODE_SIGN_LOG_H -- Gitee