From 5375705b21749c743f1d899eaca75afa4b21ce71 Mon Sep 17 00:00:00 2001 From: liupengfei Date: Tue, 29 Mar 2022 15:06:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liupengfei Change-Id: I23c14ae8388772a79a084249b4252c7df1d56f4c Signed-off-by: liupengfei --- .../innerkits/accesstoken/src/accesstoken_manager_proxy.h | 2 +- .../innerkits/tokensync/src/token_sync_manager_proxy.h | 2 +- .../main/cpp/src/token/accesstoken_id_manager.cpp | 6 +++--- .../include/command/delete_remote_token_command.h | 2 +- .../include/command/sync_remote_hap_token_command.h | 2 +- .../include/command/update_remote_hap_token_command.h | 2 +- .../include/service/token_sync_event_handler.h | 2 +- services/tokensyncmanager/src/common/constant.cpp | 7 +++++-- services/tokensyncmanager/src/remote/soft_bus_channel.cpp | 8 ++++---- services/tokensyncmanager/test/mock/src/constant_mock.cpp | 7 +++++-- 10 files changed, 23 insertions(+), 17 deletions(-) diff --git a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h index 3ad9cab15..5e549ade6 100644 --- a/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h +++ b/interfaces/innerkits/accesstoken/src/accesstoken_manager_proxy.h @@ -37,7 +37,7 @@ namespace AccessToken { class AccessTokenManagerProxy : public IRemoteProxy { public: explicit AccessTokenManagerProxy(const sptr& impl); - virtual ~AccessTokenManagerProxy() override; + ~AccessTokenManagerProxy() override; int VerifyAccessToken(AccessTokenID tokenID, const std::string& permissionName) override; int VerifyNativeToken(AccessTokenID tokenID, const std::string& permissionName) override; diff --git a/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.h b/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.h index 6e251e961..9568bfa6d 100644 --- a/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.h +++ b/interfaces/innerkits/tokensync/src/token_sync_manager_proxy.h @@ -30,7 +30,7 @@ namespace AccessToken { class TokenSyncManagerProxy : public IRemoteProxy { public: explicit TokenSyncManagerProxy(const sptr& impl); - virtual ~TokenSyncManagerProxy() override; + ~TokenSyncManagerProxy() override; int GetRemoteHapTokenInfo(const std::string& deviceID, AccessTokenID tokenID) override; int DeleteRemoteHapTokenInfo(AccessTokenID tokenID) override; diff --git a/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp b/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp index 19d7f2722..e96fdccf3 100644 --- a/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp +++ b/services/accesstokenmanager/main/cpp/src/token/accesstoken_id_manager.cpp @@ -27,7 +27,7 @@ static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_ ATokenTypeEnum AccessTokenIDManager::GetTokenIdTypeEnum(AccessTokenID id) { - AccessTokenIDInner *idInner = (AccessTokenIDInner *)&id; + AccessTokenIDInner *idInner = reinterpret_cast(&id); return (ATokenTypeEnum)idInner->type; } @@ -44,7 +44,7 @@ ATokenTypeEnum AccessTokenIDManager::GetTokenIdType(AccessTokenID id) int AccessTokenIDManager::RegisterTokenId(AccessTokenID id, ATokenTypeEnum type) { - AccessTokenIDInner *idInner = (AccessTokenIDInner *)&id; + AccessTokenIDInner *idInner = reinterpret_cast(&id); if (idInner->version != DEFAULT_TOKEN_VERSION || idInner->type != type) { return RET_FAILED; } @@ -53,7 +53,7 @@ int AccessTokenIDManager::RegisterTokenId(AccessTokenID id, ATokenTypeEnum type) for (std::set::iterator it = tokenIdSet_.begin(); it != tokenIdSet_.end(); ++it) { AccessTokenID tokenId = *it; - AccessTokenIDInner *idInnerExist = (AccessTokenIDInner *)&tokenId; + AccessTokenIDInner *idInnerExist = reinterpret_cast(&tokenId); if (idInnerExist->tokenUniqueID == idInner->tokenUniqueID) { return RET_FAILED; } diff --git a/services/tokensyncmanager/include/command/delete_remote_token_command.h b/services/tokensyncmanager/include/command/delete_remote_token_command.h index 97e3a2444..f0623b051 100644 --- a/services/tokensyncmanager/include/command/delete_remote_token_command.h +++ b/services/tokensyncmanager/include/command/delete_remote_token_command.h @@ -34,7 +34,7 @@ public: std::string ToJsonPayload() override; - DeleteRemoteTokenCommand(const std::string &json); + explicit DeleteRemoteTokenCommand(const std::string &json); DeleteRemoteTokenCommand(const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID deleteID); virtual ~DeleteRemoteTokenCommand() = default; diff --git a/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h b/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h index 14df3a21c..a746a9772 100644 --- a/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h +++ b/services/tokensyncmanager/include/command/sync_remote_hap_token_command.h @@ -39,7 +39,7 @@ public: std::string ToJsonPayload() override; - SyncRemoteHapTokenCommand(const std::string &json); + explicit SyncRemoteHapTokenCommand(const std::string &json); SyncRemoteHapTokenCommand(const std::string &srcDeviceId, const std::string &dstDeviceId, AccessTokenID id); virtual ~SyncRemoteHapTokenCommand() = default; diff --git a/services/tokensyncmanager/include/command/update_remote_hap_token_command.h b/services/tokensyncmanager/include/command/update_remote_hap_token_command.h index 1e6f88919..3786241bb 100644 --- a/services/tokensyncmanager/include/command/update_remote_hap_token_command.h +++ b/services/tokensyncmanager/include/command/update_remote_hap_token_command.h @@ -38,7 +38,7 @@ public: std::string ToJsonPayload() override; - UpdateRemoteHapTokenCommand(const std::string &json); + explicit UpdateRemoteHapTokenCommand(const std::string &json); UpdateRemoteHapTokenCommand(const std::string &srcDeviceId, const std::string &dstDeviceId, const HapTokenInfoForSync& tokenInfo); virtual ~UpdateRemoteHapTokenCommand() = default; diff --git a/services/tokensyncmanager/include/service/token_sync_event_handler.h b/services/tokensyncmanager/include/service/token_sync_event_handler.h index f9a0caf36..a86ca94ea 100644 --- a/services/tokensyncmanager/include/service/token_sync_event_handler.h +++ b/services/tokensyncmanager/include/service/token_sync_event_handler.h @@ -26,7 +26,7 @@ namespace Security { namespace AccessToken { class TokenSyncEventHandler : public AppExecFwk::EventHandler { public: - TokenSyncEventHandler(const std::shared_ptr &runner); + explicit TokenSyncEventHandler(const std::shared_ptr &runner); virtual ~TokenSyncEventHandler(); bool ProxyPostTask(const Callback &callback, int64_t delayTime); diff --git a/services/tokensyncmanager/src/common/constant.cpp b/services/tokensyncmanager/src/common/constant.cpp index ac90d7d19..a20a7cc05 100644 --- a/services/tokensyncmanager/src/common/constant.cpp +++ b/services/tokensyncmanager/src/common/constant.cpp @@ -18,6 +18,9 @@ namespace OHOS { namespace Security { namespace AccessToken { +namespace { +static const std::string REPLACE_TARGET = "****"; +} // namespace const std::string Constant::COMMAND_RESULT_SUCCESS = "success"; const std::string Constant::COMMAND_RESULT_FAILED = "execute command failed"; @@ -25,9 +28,9 @@ std::string Constant::EncryptDevId(std::string deviceId) { std::string result = deviceId; if (deviceId.size() >= ENCRYPTLEN) { - result.replace(ENCRYPTBEGIN, ENCRYPTEND, "****"); + result.replace(ENCRYPTBEGIN, ENCRYPTEND, REPLACE_TARGET); } else { - result.replace(ENCRYPTBEGIN, result.size() - 1, "****"); + result.replace(ENCRYPTBEGIN, result.size() - 1, REPLACE_TARGET); } return result; } diff --git a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp index 61695aeeb..ab6a481eb 100644 --- a/services/tokensyncmanager/src/remote/soft_bus_channel.cpp +++ b/services/tokensyncmanager/src/remote/soft_bus_channel.cpp @@ -32,8 +32,8 @@ namespace { static const std::string REQUEST_TYPE = "request"; static const std::string RESPONSE_TYPE = "response"; static const std::string TASK_NAME_CLOSE_SESSION = "atm_soft_bus_channel_close_session"; -static const long EXECUTE_COMMAND_TIME_OUT = 3000; -static const long WAIT_SESSION_CLOSE_MILLISECONDS = 5 * 1000; +static const int32_t EXECUTE_COMMAND_TIME_OUT = 3000; +static const int32_t WAIT_SESSION_CLOSE_MILLISECONDS = 5 * 1000; // send buf size for header static const int RPC_TRANSFER_HEAD_BYTES_LENGTH = 1024 * 256; // decompress buf size @@ -101,7 +101,7 @@ void SoftBusChannel::CloseConnection() thisPtr->isDelayClosing_ = false; }); - ACCESSTOKEN_LOG_DEBUG(LABEL, "close session after %{public}ld ms", WAIT_SESSION_CLOSE_MILLISECONDS); + ACCESSTOKEN_LOG_DEBUG(LABEL, "close session after %{public}d ms", WAIT_SESSION_CLOSE_MILLISECONDS); handler->ProxyPostTask(delayed, TASK_NAME_CLOSE_SESSION, WAIT_SESSION_CLOSE_MILLISECONDS); isDelayClosing_ = true; @@ -276,7 +276,7 @@ std::string SoftBusChannel::Decompress(const unsigned char *bytes, const int len return ""; } buf[len] = '\0'; - std::string str((char *) buf); + std::string str(reinterpret_cast(buf)); delete[] buf; ACCESSTOKEN_LOG_DEBUG(LABEL, "done, output: %{public}s", str.c_str()); return str; diff --git a/services/tokensyncmanager/test/mock/src/constant_mock.cpp b/services/tokensyncmanager/test/mock/src/constant_mock.cpp index 3995ac79a..6998e7fd6 100644 --- a/services/tokensyncmanager/test/mock/src/constant_mock.cpp +++ b/services/tokensyncmanager/test/mock/src/constant_mock.cpp @@ -17,6 +17,9 @@ namespace OHOS { namespace Security { namespace AccessToken { +namespace { +static const std::string REPLACE_TARGET = "****"; +} // namespace const std::string Constant::COMMAND_RESULT_SUCCESS = "success"; const std::string Constant::COMMAND_RESULT_FAILED = "execute command failed"; @@ -24,9 +27,9 @@ std::string Constant::EncryptDevId(std::string deviceId) { std::string result = deviceId; if (deviceId.size() >= ENCRYPTLEN) { - result.replace(ENCRYPTBEGIN, ENCRYPTEND, "****"); + result.replace(ENCRYPTBEGIN, ENCRYPTEND, REPLACE_TARGET); } else { - result.replace(ENCRYPTBEGIN, result.size() - 1, "****"); + result.replace(ENCRYPTBEGIN, result.size() - 1, REPLACE_TARGET); } return result; } -- Gitee