diff --git a/services/key_enable/BUILD.gn b/services/key_enable/BUILD.gn index 5ba1c7d000c9c4ea4df705af4ba92bfd112a734c..d131a1e8e7b5680f3f20105de134d2e1f88b1c8e 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 114ad30ed2578b582a1262bbe80b97b896bbbf59..f4f05f84aed4ab26e1b9e1233c8a525936571734 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 fe61509942c255a64c64dd10ee00456eeedecf60..66f140eb87b0dcc3f93296b2549f9e85584e144e 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 7ba018c14421a0973ae953deb74d7147c48cc781..cb55a03f62761ae293c51b0406f7bcaae1bfce54 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 ddc245c295588cb191422b4e4842c6dd0581f421..e6711efd862bf24e3ac2fc566898535f3002b210 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 c4618255b0fda8778835e657271cfbb7c49f180d..3bba8d0ca7d7b4cb4a5364c3f6966d67f95cfaf0 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 3ccca6e9476494ded7fb29143bab18d823e16101..7af85d1ac836af99928204328e47d5b957b3f67f 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 82a33cb55e4547138f0ef44927597694b72c4ecd..f7ae8c0bff5933a07a8c1f503df03ef9511a3a13 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 23d97a156f603c088a8f3cadffe75001df4d064e..c509fe0ade7318e26a2b6619d498fae42cf98d4a 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 6e55182a1a2b056038ba25301c84fa85eefa58da..30cc85ea66b5eb832dd74d7943b7571ad4122f08 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 5bae85a9f4df78f9d2130402609db05523cf9b13..ee0e1661aff3207c9e1102e341426ef1d0cde6a9 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