From 82026906fd6a8f60264213e1f1ebadee2edebc4d Mon Sep 17 00:00:00 2001 From: zero-cyc Date: Sat, 7 May 2022 17:44:07 +0800 Subject: [PATCH] support 64 Signed-off-by: zero-cyc Change-Id: I754efd76cabe6f89e4cc5b1cebd85f07e4c5897c --- .../common/log/include/event_log_wrapper.h | 1 + frameworks/core/include/common_event.h | 4 +- frameworks/core/include/common_event_proxy.h | 2 +- frameworks/core/include/icommon_event.h | 4 +- frameworks/core/src/common_event.cpp | 2 +- frameworks/core/src/common_event_listener.cpp | 2 +- frameworks/core/src/common_event_proxy.cpp | 4 +- frameworks/core/src/common_event_stub.cpp | 8 +-- .../native/src/async_common_event_result.cpp | 8 +-- frameworks/native/src/common_event_data.cpp | 13 ++-- .../native/src/common_event_publish_info.cpp | 4 +- .../native/src/common_event_subscriber.cpp | 6 +- frameworks/native/src/matching_skills.cpp | 18 +++--- .../unittest/common_event_subscribe_test.cpp | 6 +- .../common_event_unsubscribe_test.cpp | 2 +- .../test/unittest/matching_skills_test.cpp | 4 +- .../inner_api/async_common_event_result.h | 10 ++-- interfaces/inner_api/common_event_data.h | 8 +-- .../inner_api/common_event_subscriber.h | 6 +- interfaces/inner_api/matching_skills.h | 12 ++-- .../napi/common_event/include/common_event.h | 18 +++--- .../napi/common_event/src/common_event.cpp | 10 ++-- services/include/bundle_manager_helper.h | 2 +- .../include/common_event_control_manager.h | 14 ++--- .../include/common_event_manager_service.h | 2 +- services/include/history_event_record.h | 4 +- services/include/inner_common_event_manager.h | 2 +- services/include/ordered_event_record.h | 6 +- services/src/bundle_manager_helper.cpp | 2 +- services/src/common_event_control_manager.cpp | 59 +++++++++---------- services/src/common_event_manager_service.cpp | 2 +- .../src/common_event_permission_manager.cpp | 2 +- services/src/common_event_sticky_manager.cpp | 8 +-- .../src/common_event_subscriber_manager.cpp | 17 ++++-- services/src/inner_common_event_manager.cpp | 4 +- ...t_services_publish_ordered_module_test.cpp | 8 +-- .../unittest/mock/src/mock_bundle_manager.cpp | 6 +- test/mock/mock_bundle_manager.cpp | 2 +- ...t_services_publish_ordered_system_test.cpp | 8 +-- .../common_event_services_system_test.cpp | 4 +- tools/cem/include/common_event_command.h | 3 +- tools/cem/include/shell_command.h | 4 +- tools/cem/src/shell_command.cpp | 11 ++-- tools/test/mock/mock_common_event_stub.h | 2 +- .../common_event_command_dump_system_test.cpp | 2 +- ...mmon_event_command_publish_system_test.cpp | 4 +- 46 files changed, 167 insertions(+), 163 deletions(-) diff --git a/frameworks/common/log/include/event_log_wrapper.h b/frameworks/common/log/include/event_log_wrapper.h index 469de57..7c22203 100644 --- a/frameworks/common/log/include/event_log_wrapper.h +++ b/frameworks/common/log/include/event_log_wrapper.h @@ -16,6 +16,7 @@ #ifndef FOUNDATION_EVENT_COMMON_LOG_INCLUDE_EVENT_LOG_WRAPPER_H #define FOUNDATION_EVENT_COMMON_LOG_INCLUDE_EVENT_LOG_WRAPPER_H +#include #include #include "hilog/log.h" diff --git a/frameworks/core/include/common_event.h b/frameworks/core/include/common_event.h index 2b0638a..4c7b566 100644 --- a/frameworks/core/include/common_event.h +++ b/frameworks/core/include/common_event.h @@ -110,7 +110,7 @@ public: * @return Returns true if successful; false otherwise. */ bool FinishReceiver( - const sptr &proxy, const int &code, const std::string &data, const bool &abortEvent); + const sptr &proxy, const int32_t &code, const std::string &data, const bool &abortEvent); /** * Dumps state of common event service. @@ -179,7 +179,7 @@ private: sptr commonEventProxy_; std::map, sptr> eventListeners_; sptr recipient_; - const unsigned int SUBSCRIBER_MAX_SIZE = 200; + const size_t SUBSCRIBER_MAX_SIZE = 200; static const uint8_t ALREADY_SUBSCRIBED = 0; static const uint8_t INITIAL_SUBSCRIPTION = 1; static const uint8_t SUBSCRIBE_FAILED = 2; diff --git a/frameworks/core/include/common_event_proxy.h b/frameworks/core/include/common_event_proxy.h index 7d869f3..6bcd902 100644 --- a/frameworks/core/include/common_event_proxy.h +++ b/frameworks/core/include/common_event_proxy.h @@ -103,7 +103,7 @@ public: * @param abortEvent Indicates whether the current ordered common event should be aborted. * @return Returns true if successful; false otherwise. */ - virtual bool FinishReceiver(const sptr &proxy, const int &code, const std::string &receiverData, + virtual bool FinishReceiver(const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) override; /** diff --git a/frameworks/core/include/icommon_event.h b/frameworks/core/include/icommon_event.h index c48261a..d1a6f65 100644 --- a/frameworks/core/include/icommon_event.h +++ b/frameworks/core/include/icommon_event.h @@ -99,8 +99,8 @@ public: * @param abortEvent Indicates whether the current ordered common event should be aborted. * @return Returns true if successful; false otherwise. */ - virtual bool FinishReceiver( - const sptr &proxy, const int &code, const std::string &receiverData, const bool &abortEvent) = 0; + virtual bool FinishReceiver(const sptr &proxy, const int32_t &code, + const std::string &receiverData, const bool &abortEvent) = 0; /** * Freezes the specified process. diff --git a/frameworks/core/src/common_event.cpp b/frameworks/core/src/common_event.cpp index 8039980..6d1986c 100644 --- a/frameworks/core/src/common_event.cpp +++ b/frameworks/core/src/common_event.cpp @@ -178,7 +178,7 @@ bool CommonEvent::GetStickyCommonEvent(const std::string &event, CommonEventData } bool CommonEvent::FinishReceiver( - const sptr &proxy, const int &code, const std::string &data, const bool &abortEvent) + const sptr &proxy, const int32_t &code, const std::string &data, const bool &abortEvent) { EVENT_LOGI("enter"); diff --git a/frameworks/core/src/common_event_listener.cpp b/frameworks/core/src/common_event_listener.cpp index b0c5ed2..e0e48a7 100644 --- a/frameworks/core/src/common_event_listener.cpp +++ b/frameworks/core/src/common_event_listener.cpp @@ -96,7 +96,7 @@ void CommonEventListener::OnReceiveEvent( std::lock_guard lock(mutex_); - int code = commonEventData.GetCode(); + int32_t code = commonEventData.GetCode(); std::string data = commonEventData.GetData(); std::shared_ptr result = diff --git a/frameworks/core/src/common_event_proxy.cpp b/frameworks/core/src/common_event_proxy.cpp index 5a1213b..122510f 100644 --- a/frameworks/core/src/common_event_proxy.cpp +++ b/frameworks/core/src/common_event_proxy.cpp @@ -256,7 +256,7 @@ bool CommonEventProxy::DumpState(const std::string &event, const int32_t &userId if (ret) { int32_t stackNum = reply.ReadInt32(); stackNum = stackNum > MAX_HISTORY_SIZE ? MAX_HISTORY_SIZE : stackNum; - for (int i = 0; i < stackNum; i++) { + for (int32_t i = 0; i < stackNum; i++) { std::string stack = Str16ToStr8(reply.ReadString16()); state.emplace_back(stack); } @@ -267,7 +267,7 @@ bool CommonEventProxy::DumpState(const std::string &event, const int32_t &userId } bool CommonEventProxy::FinishReceiver( - const sptr &proxy, const int &code, const std::string &receiverData, const bool &abortEvent) + const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { EVENT_LOGD("start"); diff --git a/frameworks/core/src/common_event_stub.cpp b/frameworks/core/src/common_event_stub.cpp index b925bea..83085d1 100644 --- a/frameworks/core/src/common_event_stub.cpp +++ b/frameworks/core/src/common_event_stub.cpp @@ -67,7 +67,7 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message if (hasLastSubscriber) { sptr commonEventListener = data.ReadRemoteObject(); } - int uid = data.ReadInt32(); + int32_t uid = data.ReadInt32(); int32_t userId = data.ReadInt32(); if (!event) { EVENT_LOGE("Failed to ReadParcelable"); @@ -151,7 +151,7 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message EVENT_LOGE("Failed to ReadRemoteObject"); return ERR_INVALID_VALUE; } - int receiverCode = data.ReadInt32(); + int32_t receiverCode = data.ReadInt32(); std::string receiverData = Str16ToStr8(data.ReadString16()); bool abortEvent = data.ReadBool(); bool ret = FinishReceiver(proxy, receiverCode, receiverData, abortEvent); @@ -163,7 +163,7 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message } case static_cast(ICommonEvent::Message::CES_FREEZE): { - int uid = data.ReadInt32(); + int32_t uid = data.ReadInt32(); bool ret = Freeze(uid); if (!reply.WriteBool(ret)) { EVENT_LOGE("Failed to write reply"); @@ -173,7 +173,7 @@ int CommonEventStub::OnRemoteRequest(uint32_t code, MessageParcel &data, Message } case static_cast(ICommonEvent::Message::CES_UNFREEZE): { - int uid = data.ReadInt32(); + int32_t uid = data.ReadInt32(); bool ret = Unfreeze(uid); if (!reply.WriteBool(ret)) { EVENT_LOGE("Failed to write reply"); diff --git a/frameworks/native/src/async_common_event_result.cpp b/frameworks/native/src/async_common_event_result.cpp index dac0a3b..4d51706 100644 --- a/frameworks/native/src/async_common_event_result.cpp +++ b/frameworks/native/src/async_common_event_result.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace EventFwk { -AsyncCommonEventResult::AsyncCommonEventResult(const int &resultCode, const std::string &resultData, +AsyncCommonEventResult::AsyncCommonEventResult(const int32_t &resultCode, const std::string &resultData, const bool &ordered, const bool &sticky, const sptr &token) : abortEvent_(false), finished_(false) { @@ -34,7 +34,7 @@ AsyncCommonEventResult::AsyncCommonEventResult(const int &resultCode, const std: AsyncCommonEventResult::~AsyncCommonEventResult() {} -bool AsyncCommonEventResult::SetCode(const int &code) +bool AsyncCommonEventResult::SetCode(const int32_t &code) { if (!CheckSynchronous()) { return false; @@ -45,7 +45,7 @@ bool AsyncCommonEventResult::SetCode(const int &code) return true; } -int AsyncCommonEventResult::GetCode() const +int32_t AsyncCommonEventResult::GetCode() const { return resultCode_; } @@ -66,7 +66,7 @@ std::string AsyncCommonEventResult::GetData() const return resultData_; } -bool AsyncCommonEventResult::SetCodeAndData(const int &code, const std::string &data) +bool AsyncCommonEventResult::SetCodeAndData(const int32_t &code, const std::string &data) { if (!CheckSynchronous()) { return false; diff --git a/frameworks/native/src/common_event_data.cpp b/frameworks/native/src/common_event_data.cpp index cae91d2..08d0793 100644 --- a/frameworks/native/src/common_event_data.cpp +++ b/frameworks/native/src/common_event_data.cpp @@ -12,7 +12,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "common_event_data.h" #include "event_log_wrapper.h" @@ -29,7 +28,7 @@ CommonEventData::CommonEventData(const Want &want) : want_(want), code_(0) { } -CommonEventData::CommonEventData(const Want &want, const int &code, const std::string &data) +CommonEventData::CommonEventData(const Want &want, const int32_t &code, const std::string &data) : want_(want), code_(code), data_(data) { } @@ -38,12 +37,12 @@ CommonEventData::~CommonEventData() { } -void CommonEventData::SetCode(const int &code) +void CommonEventData::SetCode(const int32_t &code) { code_ = code; } -int CommonEventData::GetCode() const +int32_t CommonEventData::GetCode() const { return code_; } @@ -75,7 +74,7 @@ bool CommonEventData::Marshalling(Parcel &parcel) const EVENT_LOGE("Type conversion failed"); return false; } - if (!messageParcel->WriteUint32(data_.size() + 1)) { + if (!messageParcel->WriteUint64(data_.size() + 1)) { EVENT_LOGE("Failed to write data size"); return false; } @@ -105,14 +104,14 @@ bool CommonEventData::ReadFromParcel(Parcel &parcel) EVENT_LOGE("Type conversion failed"); return false; } - uint32_t length = messageParcel->ReadUint32(); + uint64_t length = messageParcel->ReadUint64(); if (length == 0) { EVENT_LOGE("Invalid data length"); return false; } const char *data = reinterpret_cast(messageParcel->ReadRawData(length)); if (!data) { - EVENT_LOGE("Fail to read raw data, length = %{public}u", length); + EVENT_LOGE("Fail to read raw data, length = %{public}" PRIu64 "", length); return false; } data_ = data; diff --git a/frameworks/native/src/common_event_publish_info.cpp b/frameworks/native/src/common_event_publish_info.cpp index 5cd1e05..64a3645 100644 --- a/frameworks/native/src/common_event_publish_info.cpp +++ b/frameworks/native/src/common_event_publish_info.cpp @@ -68,7 +68,7 @@ bool CommonEventPublishInfo::Marshalling(Parcel &parcel) const { EVENT_LOGD("enter"); - // write subscriberpermissions + // write subscriber permissions std::vector permissionVec_; for (std::vector::size_type i = 0; i < subscriberPermissions_.size(); ++i) { permissionVec_.emplace_back(Str8ToStr16(subscriberPermissions_[i])); @@ -97,7 +97,7 @@ bool CommonEventPublishInfo::ReadFromParcel(Parcel &parcel) { EVENT_LOGD("enter"); - // read subscriberpermissions + // read subscriber permissions std::vector permissionVec_; if (!parcel.ReadString16Vector(&permissionVec_)) { EVENT_LOGE("ReadFromParcel read permission error"); diff --git a/frameworks/native/src/common_event_subscriber.cpp b/frameworks/native/src/common_event_subscriber.cpp index 90389d1..c9ddcab 100644 --- a/frameworks/native/src/common_event_subscriber.cpp +++ b/frameworks/native/src/common_event_subscriber.cpp @@ -33,7 +33,7 @@ const CommonEventSubscribeInfo &CommonEventSubscriber::GetSubscribeInfo() const return subscribeInfo_; } -bool CommonEventSubscriber::SetCode(const int &code) +bool CommonEventSubscriber::SetCode(const int32_t &code) { if (!CheckSynchronous()) { return false; @@ -42,7 +42,7 @@ bool CommonEventSubscriber::SetCode(const int &code) return result_->SetCode(code); } -int CommonEventSubscriber::GetCode() const +int32_t CommonEventSubscriber::GetCode() const { if (!CheckSynchronous()) { return 0; @@ -69,7 +69,7 @@ std::string CommonEventSubscriber::GetData() const return result_->GetData(); } -bool CommonEventSubscriber::SetCodeAndData(const int &code, const std::string &data) +bool CommonEventSubscriber::SetCodeAndData(const int32_t &code, const std::string &data) { if (!CheckSynchronous()) { return false; diff --git a/frameworks/native/src/matching_skills.cpp b/frameworks/native/src/matching_skills.cpp index dfe20b4..0f54467 100644 --- a/frameworks/native/src/matching_skills.cpp +++ b/frameworks/native/src/matching_skills.cpp @@ -32,10 +32,10 @@ MatchingSkills::MatchingSkills(const MatchingSkills &matchingSkills) MatchingSkills::~MatchingSkills() {} -std::string MatchingSkills::GetEntity(int index) const +std::string MatchingSkills::GetEntity(size_t index) const { std::string entity; - if ((index >= 0) && (index < static_cast(entities_.size()))) { + if ((index >= 0) && (index < entities_.size())) { entity = entities_[index]; } return entity; @@ -62,7 +62,7 @@ void MatchingSkills::RemoveEntity(const std::string &entity) } } -int MatchingSkills::CountEntities() const +size_t MatchingSkills::CountEntities() const { return entities_.size(); } @@ -75,15 +75,15 @@ void MatchingSkills::AddEvent(const std::string &event) } } -int MatchingSkills::CountEvent() const +size_t MatchingSkills::CountEvent() const { return events_.size(); } -std::string MatchingSkills::GetEvent(int index) const +std::string MatchingSkills::GetEvent(size_t index) const { std::string event; - if (index >= 0 && index < static_cast(events_.size())) { + if (index >= 0 && index < events_.size()) { event = events_[index]; } return event; @@ -107,10 +107,10 @@ bool MatchingSkills::HasEvent(const std::string &event) const return std::find(events_.cbegin(), events_.cend(), event) != events_.cend(); } -std::string MatchingSkills::GetScheme(int index) const +std::string MatchingSkills::GetScheme(size_t index) const { std::string schemes; - if ((index >= 0) && (index < static_cast(schemes_.size()))) { + if ((index >= 0) && (index < schemes_.size())) { schemes = schemes_[index]; } return schemes; @@ -137,7 +137,7 @@ void MatchingSkills::RemoveScheme(const std::string &scheme) } } -int MatchingSkills::CountSchemes() const +size_t MatchingSkills::CountSchemes() const { return schemes_.size(); } diff --git a/frameworks/native/test/unittest/common_event_subscribe_test.cpp b/frameworks/native/test/unittest/common_event_subscribe_test.cpp index 68ad88b..33175f0 100644 --- a/frameworks/native/test/unittest/common_event_subscribe_test.cpp +++ b/frameworks/native/test/unittest/common_event_subscribe_test.cpp @@ -120,7 +120,7 @@ public: virtual ~CommonEventStubTest() {} - virtual bool FinishReceiver(const OHOS::sptr &proxy, const int &code, + virtual bool FinishReceiver(const OHOS::sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { return false; @@ -502,7 +502,7 @@ HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_014, TestSize.Level1) CommonEventListener commonEventListener(subscriber); commonEventListener.runner_ = nullptr; - int result = commonEventListener.IsReady(); + bool result = commonEventListener.IsReady(); EXPECT_EQ(false, result); } @@ -525,7 +525,7 @@ HWTEST_F(CommonEventSubscribeTest, CommonEventSubscribe_015, TestSize.Level1) CommonEventListener commonEventListener(subscriber); commonEventListener.handler_ = nullptr; - int result = commonEventListener.IsReady(); + bool result = commonEventListener.IsReady(); EXPECT_EQ(false, result); } \ No newline at end of file diff --git a/frameworks/native/test/unittest/common_event_unsubscribe_test.cpp b/frameworks/native/test/unittest/common_event_unsubscribe_test.cpp index 1ea5469..d769135 100644 --- a/frameworks/native/test/unittest/common_event_unsubscribe_test.cpp +++ b/frameworks/native/test/unittest/common_event_unsubscribe_test.cpp @@ -94,7 +94,7 @@ public: virtual ~CommonEventStubTest() {} - virtual bool FinishReceiver(const OHOS::sptr &proxy, const int &code, + virtual bool FinishReceiver(const OHOS::sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { return false; diff --git a/frameworks/native/test/unittest/matching_skills_test.cpp b/frameworks/native/test/unittest/matching_skills_test.cpp index 5230775..870704e 100644 --- a/frameworks/native/test/unittest/matching_skills_test.cpp +++ b/frameworks/native/test/unittest/matching_skills_test.cpp @@ -25,8 +25,8 @@ using namespace testing::ext; using namespace OHOS::EventFwk; using OHOS::Parcel; -static const int SET_COUNT = 1; -static const int MAX_COUNT = 100; +static const size_t SET_COUNT = 1; +static const size_t MAX_COUNT = 100; class MatchingSkillsTest : public testing::Test { public: diff --git a/interfaces/inner_api/async_common_event_result.h b/interfaces/inner_api/async_common_event_result.h index 1e1f310..433c0ad 100644 --- a/interfaces/inner_api/async_common_event_result.h +++ b/interfaces/inner_api/async_common_event_result.h @@ -31,7 +31,7 @@ public: * @param sticky Indicates the type of the current sticky common event is sticky or not. * @param token Indicates the remote object of the current ordered common event. */ - AsyncCommonEventResult(const int &resultCode, const std::string &resultData, const bool &ordered, + AsyncCommonEventResult(const int32_t &resultCode, const std::string &resultData, const bool &ordered, const bool &sticky, const sptr &token); ~AsyncCommonEventResult(); @@ -42,14 +42,14 @@ public: * @param code Indicates the result code of the current ordered common event * @return Returns true if successful; false otherwise. */ - bool SetCode(const int &code); + bool SetCode(const int32_t &code); /** * Obtains the result code of the current ordered common event. * * @return Returns the result code of the current ordered common event */ - int GetCode() const; + int32_t GetCode() const; /** * Sets the result data of the current ordered common event. @@ -73,7 +73,7 @@ public: * @param data Indicates the result data of the current ordered common event. * @return Returns true if successful; false otherwise. */ - bool SetCodeAndData(const int &code, const std::string &data); + bool SetCodeAndData(const int32_t &code, const std::string &data); /** * Cancels the current ordered common event. @@ -125,7 +125,7 @@ public: bool CheckSynchronous() const; private: - int resultCode_; + int32_t resultCode_; std::string resultData_; bool ordered_; bool sticky_; diff --git a/interfaces/inner_api/common_event_data.h b/interfaces/inner_api/common_event_data.h index b41d154..1582645 100644 --- a/interfaces/inner_api/common_event_data.h +++ b/interfaces/inner_api/common_event_data.h @@ -43,7 +43,7 @@ public: * @param code Indicates the code of a common event. * @param data Indicates the data of a common event. */ - CommonEventData(const Want &want, const int &code, const std::string &data); + CommonEventData(const Want &want, const int32_t &code, const std::string &data); ~CommonEventData(); @@ -66,14 +66,14 @@ public: * * @param code Indicates the code of a common event. */ - void SetCode(const int &code); + void SetCode(const int32_t &code); /** * Obtains the result code of a common event. * * @return Returns the code of a common event. */ - int GetCode() const; + int32_t GetCode() const; /** * Sets the result data of a common event. @@ -115,7 +115,7 @@ private: private: Want want_; - int code_; + int32_t code_; std::string data_; }; } // namespace EventFwk diff --git a/interfaces/inner_api/common_event_subscriber.h b/interfaces/inner_api/common_event_subscriber.h index 76f4c18..57f3455 100644 --- a/interfaces/inner_api/common_event_subscriber.h +++ b/interfaces/inner_api/common_event_subscriber.h @@ -56,14 +56,14 @@ public: * @param code Indicates the result code of the current ordered common event * @return Returns true if success; false otherwise. */ - bool SetCode(const int &code); + bool SetCode(const int32_t &code); /** * Obtains the result code of the current ordered common event. * * @return Returns the result code of the current ordered common event. */ - int GetCode() const; + int32_t GetCode() const; /** * Sets the result data of the current ordered common event. @@ -87,7 +87,7 @@ public: * @param data Indicates the result data of the current ordered common event. * @return Returns true if success; false otherwise. */ - bool SetCodeAndData(const int &code, const std::string &data); + bool SetCodeAndData(const int32_t &code, const std::string &data); /** * Cancels the current ordered common event. diff --git a/interfaces/inner_api/matching_skills.h b/interfaces/inner_api/matching_skills.h index 54e76f8..3e6a53d 100644 --- a/interfaces/inner_api/matching_skills.h +++ b/interfaces/inner_api/matching_skills.h @@ -41,7 +41,7 @@ public: * @param index Indicates the entity index. * @return Returns entity. */ - std::string GetEntity(int index) const; + std::string GetEntity(size_t index) const; /** * Adds an entity to this MatchingSkills object. @@ -70,7 +70,7 @@ public: * * @return Returns entity count. */ - int CountEntities() const; + size_t CountEntities() const; /** * Adds an event to this MatchingSkills object. @@ -84,7 +84,7 @@ public: * * @return Indicates the event count in MatchingSkills object. */ - int CountEvent() const; + size_t CountEvent() const; /** * Gets event. @@ -92,7 +92,7 @@ public: * @param index Indicates the scheme index. * @return Returns the event in MatchingSkills object. */ - std::string GetEvent(int index) const; + std::string GetEvent(size_t index) const; /** * Gets events. @@ -122,7 +122,7 @@ public: * @param index Indicates the scheme index. * @return Retruns scheme. */ - std::string GetScheme(int index) const; + std::string GetScheme(size_t index) const; /** * Adds scheme to this MatchingSkills object. @@ -151,7 +151,7 @@ public: * * @return Retruns scheme count. */ - int CountSchemes() const; + size_t CountSchemes() const; /** * Matches want. diff --git a/interfaces/kits/napi/common_event/include/common_event.h b/interfaces/kits/napi/common_event/include/common_event.h index 88a67e5..b6fd786 100644 --- a/interfaces/kits/napi/common_event/include/common_event.h +++ b/interfaces/kits/napi/common_event/include/common_event.h @@ -101,7 +101,7 @@ struct AsyncCallbackInfoGetCode { napi_env env = nullptr; napi_async_work asyncWork; SubscriberInstance *objectInfo = nullptr; - int code = 0; + int32_t code = 0; CallbackPromiseInfo info; }; @@ -109,7 +109,7 @@ struct AsyncCallbackInfoSetCode { napi_env env = nullptr; napi_async_work asyncWork; SubscriberInstance *objectInfo = nullptr; - int code = 0; + int32_t code = 0; CallbackPromiseInfo info; }; @@ -133,7 +133,7 @@ struct AsyncCallbackInfoSetCodeAndData { napi_env env = nullptr; napi_async_work asyncWork; SubscriberInstance *objectInfo = nullptr; - int code = 0; + int32_t code = 0; std::string data; CallbackPromiseInfo info; }; @@ -188,7 +188,7 @@ struct AsyncCallbackInfoPublish { struct CommonEventPublishDataByjs { std::string bundleName; std::string data; - int code = 0; + int32_t code = 0; std::vector subscriberPermissions; bool isOrdered = false; bool isSticky = false; @@ -199,7 +199,7 @@ struct CommonEventDataWorker { napi_env env = nullptr; napi_ref ref = nullptr; Want want; - int code = 0; + int32_t code = 0; std::string data; }; @@ -288,7 +288,7 @@ std::shared_ptr GetAsyncResult(const SubscriberInstance napi_value GetCode(napi_env env, napi_callback_info info); napi_value ParseParametersBySetCode( - const napi_env &env, const napi_value (&argv)[2], size_t argc, int &code, napi_ref &callback); + const napi_env &env, const napi_value (&argv)[2], size_t argc, int32_t &code, napi_ref &callback); void PaddingAsyncCallbackInfoSetCode(const napi_env &env, const size_t &argc, AsyncCallbackInfoSetCode *&asynccallbackinfo, const napi_ref &callback, napi_value &promise); @@ -310,8 +310,8 @@ void PaddingAsyncCallbackInfoSetData(const napi_env &env, const size_t &argc, napi_value SetData(napi_env env, napi_callback_info info); -napi_value ParseParametersBySetCodeAndData( - const napi_env &env, const napi_value (&argv)[3], size_t argc, int &code, std::string &data, napi_ref &callback); +napi_value ParseParametersBySetCodeAndData(const napi_env &env, const napi_value (&argv)[3], + size_t argc, int32_t &code, std::string &data, napi_ref &callback); void PaddingAsyncCallbackInfoSetCodeAndData(const napi_env &env, const size_t &argc, AsyncCallbackInfoSetCodeAndData *&asynccallbackinfo, const napi_ref &callback, napi_value &promise); @@ -359,7 +359,7 @@ napi_value GetBundlenameByPublish(const napi_env &env, const napi_value &value, napi_value GetDataByPublish(const napi_env &env, const napi_value &value, std::string &data); -napi_value GetCodeByPublish(const napi_env &env, const napi_value &value, int &code); +napi_value GetCodeByPublish(const napi_env &env, const napi_value &value, int32_t &code); napi_value GetSubscriberPermissionsByPublish( const napi_env &env, const napi_value &value, std::vector &subscriberPermissions); diff --git a/interfaces/kits/napi/common_event/src/common_event.cpp b/interfaces/kits/napi/common_event/src/common_event.cpp index a0cb3ee..7d51c2e 100644 --- a/interfaces/kits/napi/common_event/src/common_event.cpp +++ b/interfaces/kits/napi/common_event/src/common_event.cpp @@ -897,7 +897,7 @@ napi_value GetCode(napi_env env, napi_callback_info info) } napi_value ParseParametersBySetCode( - const napi_env &env, const napi_value (&argv)[SET_CODE_MAX_PARA], size_t argc, int &code, napi_ref &callback) + const napi_env &env, const napi_value (&argv)[SET_CODE_MAX_PARA], size_t argc, int32_t &code, napi_ref &callback) { napi_valuetype valuetype; @@ -942,7 +942,7 @@ napi_value SetCode(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); napi_ref callback = nullptr; - int code = 0; + int32_t code = 0; if (ParseParametersBySetCode(env, argv, argc, code, callback) == nullptr) { return NapiGetNull(env); } @@ -1220,7 +1220,7 @@ napi_value SetData(napi_env env, napi_callback_info info) napi_value ParseParametersBySetCodeAndData( const napi_env &env, const napi_value (&argv)[SET_CODE_AND_DATA_MAX_PARA], - size_t argc, int &code, std::string &data, napi_ref &callback) + size_t argc, int32_t &code, std::string &data, napi_ref &callback) { napi_valuetype valuetype; size_t strLen = 0; @@ -1279,7 +1279,7 @@ napi_value SetCodeAndData(napi_env env, napi_callback_info info) NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, NULL)); napi_ref callback = nullptr; - int code = 0; + int32_t code = 0; std::string data; if (ParseParametersBySetCodeAndData(env, argv, argc, code, data, callback) == nullptr) { return NapiGetNull(env); @@ -1889,7 +1889,7 @@ napi_value GetDataByPublish(const napi_env &env, const napi_value &value, std::s return NapiGetNull(env); } -napi_value GetCodeByPublish(const napi_env &env, const napi_value &value, int &code) +napi_value GetCodeByPublish(const napi_env &env, const napi_value &value, int32_t &code) { EVENT_LOGI("GetCodeByPublish start"); diff --git a/services/include/bundle_manager_helper.h b/services/include/bundle_manager_helper.h index a8b2db0..f7b93fe 100644 --- a/services/include/bundle_manager_helper.h +++ b/services/include/bundle_manager_helper.h @@ -51,7 +51,7 @@ public: * @param uid Indicates the uid of the application. * @return Returns the bundle name. */ - std::string GetBundleName(int uid); + std::string GetBundleName(uid_t uid); /** * Queries extension information. diff --git a/services/include/common_event_control_manager.h b/services/include/common_event_control_manager.h index 6da218e..09815b4 100644 --- a/services/include/common_event_control_manager.h +++ b/services/include/common_event_control_manager.h @@ -66,7 +66,7 @@ public: * @param abortEvent Indicates whether to cancel the current common event. * @return Returns true if success; false otherwise. */ - bool FinishReceiverAction(std::shared_ptr recordPtr, const int &code, + bool FinishReceiverAction(std::shared_ptr recordPtr, const int32_t &code, const std::string &receiverData, const bool &abortEvent); /** @@ -128,18 +128,18 @@ private: bool ScheduleOrderedCommonEvent(); - bool NotifyOrderedEvent(std::shared_ptr &eventRecordPtr, int index); + bool NotifyOrderedEvent(std::shared_ptr &eventRecordPtr, size_t index); - void SetTime(int recIdx, std::shared_ptr &sp, bool timeoutMessage); + void SetTime(size_t recIdx, std::shared_ptr &sp, bool timeoutMessage); bool SetTimeout(int64_t timeoutTime); bool CancelTimeout(); - bool FinishReceiver(std::shared_ptr recordPtr, const int &code, const std::string &receiverData, - const bool &abortEvent); + bool FinishReceiver(std::shared_ptr recordPtr, const int32_t &code, + const std::string &receiverData, const bool &abortEvent); - int CheckPermission(const EventSubscriberRecord &subscriberRecord, const CommonEventRecord &eventRecord); + int8_t CheckPermission(const EventSubscriberRecord &subscriberRecord, const CommonEventRecord &eventRecord); bool CheckSubscriberPermission(const EventSubscriberRecord &subscriberRecord, const CommonEventRecord &eventRecord); @@ -182,7 +182,7 @@ private: std::mutex orderedMutex_; std::mutex unorderedMutex_; std::mutex historyMutex_; - const unsigned int HISTORY_MAX_SIZE = 100; + const size_t HISTORY_MAX_SIZE = 100; }; } // namespace EventFwk } // namespace OHOS diff --git a/services/include/common_event_manager_service.h b/services/include/common_event_manager_service.h index a27404e..8e7a725 100644 --- a/services/include/common_event_manager_service.h +++ b/services/include/common_event_manager_service.h @@ -105,7 +105,7 @@ public: * @param abortEvent Indicates Whether to cancel the current common event. * @return Returns true if successful; false otherwise. */ - virtual bool FinishReceiver(const sptr &proxy, const int &code, const std::string &receiverData, + virtual bool FinishReceiver(const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) override; /** diff --git a/services/include/history_event_record.h b/services/include/history_event_record.h index 9e671f9..0667420 100644 --- a/services/include/history_event_record.h +++ b/services/include/history_event_record.h @@ -48,7 +48,7 @@ struct HistoryEventRecord { }; Want want; - int code; + int32_t code; std::string data; bool sticky; @@ -68,7 +68,7 @@ struct HistoryEventRecord { std::vector deliveryState; int64_t dispatchTime; int64_t receiverTime; - int state; + int8_t state; bool resultAbort; HistoryEventRecord() diff --git a/services/include/inner_common_event_manager.h b/services/include/inner_common_event_manager.h index 6d43119..99c0230 100644 --- a/services/include/inner_common_event_manager.h +++ b/services/include/inner_common_event_manager.h @@ -102,7 +102,7 @@ public: * @return Returns true if successful; false otherwise. */ void FinishReceiver( - const sptr &proxy, const int &code, const std::string &receiverData, const bool &abortEvent); + const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent); /** * Freezes application. diff --git a/services/include/ordered_event_record.h b/services/include/ordered_event_record.h index 173b69a..c7fab0b 100644 --- a/services/include/ordered_event_record.h +++ b/services/include/ordered_event_record.h @@ -39,12 +39,12 @@ struct OrderedEventRecord : public CommonEventRecord { sptr resultTo; sptr curReceiver; std::vector deliveryState; - int enqueueClockTime; + int32_t enqueueClockTime; int64_t dispatchTime; int64_t receiverTime; int64_t finishTime; - int nextReceiver; - int state; + size_t nextReceiver; + int8_t state; bool resultAbort; OrderedEventRecord() diff --git a/services/src/bundle_manager_helper.cpp b/services/src/bundle_manager_helper.cpp index b63977b..bac67cc 100644 --- a/services/src/bundle_manager_helper.cpp +++ b/services/src/bundle_manager_helper.cpp @@ -35,7 +35,7 @@ BundleManagerHelper::BundleManagerHelper() : sptrBundleMgr_(nullptr), bmsDeath_( BundleManagerHelper::~BundleManagerHelper() {} -std::string BundleManagerHelper::GetBundleName(int uid) +std::string BundleManagerHelper::GetBundleName(uid_t uid) { EVENT_LOGI("enter"); diff --git a/services/src/common_event_control_manager.cpp b/services/src/common_event_control_manager.cpp index c84f104..70cc7df 100644 --- a/services/src/common_event_control_manager.cpp +++ b/services/src/common_event_control_manager.cpp @@ -27,8 +27,9 @@ namespace OHOS { namespace EventFwk { -constexpr int LENGTH = 80; -constexpr int DOUBLE = 2; +constexpr int32_t LENGTH = 80; +constexpr int32_t DOUBLE = 2; +constexpr unsigned int TIMEVAL = 5000; const std::string CONNECTOR = " or "; using frozenRecords = std::map, std::vector>>; @@ -107,7 +108,7 @@ bool CommonEventControlManager::NotifyFreezeEvents( return false; } - int ret = CheckPermission(subscriberRecord, eventRecord); + int8_t ret = CheckPermission(subscriberRecord, eventRecord); if (ret != OrderedEventRecord::DELIVERED) { EVENT_LOGE("check permission is failed"); return false; @@ -134,8 +135,7 @@ bool CommonEventControlManager::GetUnorderedEventHandler() } if (handler_->GetEventRunner() != nullptr) { std::string threadName = handler_->GetEventRunner()->GetRunnerThreadName(); - static unsigned int timeval = 5000; - if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_, timeval) != 0) { + if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handler_, TIMEVAL) != 0) { EVENT_LOGE("Failed to Add handler Thread"); } } @@ -153,7 +153,7 @@ bool CommonEventControlManager::NotifyUnorderedEvent(std::shared_ptrcommonEventData->GetWant().GetAction().c_str(), eventRecord->receivers.size()); for (auto vec : eventRecord->receivers) { - int index = eventRecord->nextReceiver++; + size_t index = eventRecord->nextReceiver++; eventRecord->curReceiver = vec->commonEventListener; if (vec->isFreeze) { eventRecord->deliveryState[index] = OrderedEventRecord::SKIPPED; @@ -165,7 +165,7 @@ bool CommonEventControlManager::NotifyUnorderedEvent(std::shared_ptrdeliveryState[index] = ret; if (ret == OrderedEventRecord::DELIVERED) { eventRecord->state = OrderedEventRecord::RECEIVEING; @@ -258,8 +258,7 @@ bool CommonEventControlManager::GetOrderedEventHandler() } if (handlerOrdered_->GetEventRunner() != nullptr) { std::string threadName = handlerOrdered_->GetEventRunner()->GetRunnerThreadName(); - static unsigned int timeval = 5000; - if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handlerOrdered_, timeval) != 0) { + if (HiviewDFX::Watchdog::GetInstance().AddThread(threadName, handlerOrdered_, TIMEVAL) != 0) { EVENT_LOGE("Failed to Add Ordered Thread"); } } @@ -397,22 +396,22 @@ bool CommonEventControlManager::ScheduleOrderedCommonEvent() return handlerOrdered_->SendEvent(InnerEvent::Get(OrderedEventHandler::ORDERED_EVENT_START)); } -bool CommonEventControlManager::NotifyOrderedEvent(std::shared_ptr &eventRecordPtr, int index) +bool CommonEventControlManager::NotifyOrderedEvent(std::shared_ptr &eventRecordPtr, size_t index) { - EVENT_LOGI("enter with index %{public}d", index); + EVENT_LOGI("enter with index %{public}zu", index); if (eventRecordPtr == nullptr) { EVENT_LOGE("eventRecordPtr = nullptr"); return false; } - int receiverNum = static_cast(eventRecordPtr->receivers.size()); + size_t receiverNum = eventRecordPtr->receivers.size(); if ((index < 0) || (index >= receiverNum)) { - EVENT_LOGE("Invalid index (= %{public}d)", index); + EVENT_LOGE("Invalid index (= %{public}zu)", index); return false; } - int ret = CheckPermission(*(eventRecordPtr->receivers[index]), *eventRecordPtr); + int8_t ret = CheckPermission(*(eventRecordPtr->receivers[index]), *eventRecordPtr); if (ret == OrderedEventRecord::SKIPPED) { eventRecordPtr->deliveryState[index] = ret; } else if (ret == OrderedEventRecord::DELIVERED) { @@ -466,7 +465,7 @@ void CommonEventControlManager::ProcessNextOrderedEvent(bool isSendMsg) sp = orderedEventQueue_.front(); bool forceReceive = false; - int numReceivers = static_cast(sp->receivers.size()); + size_t numReceivers = sp->receivers.size(); int64_t nowSysTime = SystemTime::GetNowSysTime(); if (sp->dispatchTime > 0) { @@ -505,7 +504,7 @@ void CommonEventControlManager::ProcessNextOrderedEvent(bool isSendMsg) } } while (sp == nullptr); - int recIdx = sp->nextReceiver++; + size_t recIdx = sp->nextReceiver++; SetTime(recIdx, sp, pendingTimeoutMessage_); NotifyOrderedEvent(sp, recIdx); @@ -517,7 +516,7 @@ void CommonEventControlManager::ProcessNextOrderedEvent(bool isSendMsg) return; } -void CommonEventControlManager::SetTime(int recIdx, std::shared_ptr &sp, bool timeoutMessage) +void CommonEventControlManager::SetTime(size_t recIdx, std::shared_ptr &sp, bool timeoutMessage) { EVENT_LOGI("enter"); @@ -599,7 +598,7 @@ void CommonEventControlManager::CurrentOrderedEventTimeout(bool isFromMsg) } // Forced to finish the current receiver to process the next receiver - int code = sp->commonEventData->GetCode(); + int32_t code = sp->commonEventData->GetCode(); const std::string &strRef = sp->commonEventData->GetData(); bool abort = sp->resultAbort; FinishReceiver(sp, code, strRef, abort); @@ -609,7 +608,7 @@ void CommonEventControlManager::CurrentOrderedEventTimeout(bool isFromMsg) return; } -bool CommonEventControlManager::FinishReceiver(std::shared_ptr recordPtr, const int &code, +bool CommonEventControlManager::FinishReceiver(std::shared_ptr recordPtr, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { EVENT_LOGI("enter"); @@ -621,7 +620,7 @@ bool CommonEventControlManager::FinishReceiver(std::shared_ptrstate=%{public}d", recordPtr->state); - int state = recordPtr->state; + int8_t state = recordPtr->state; recordPtr->state = OrderedEventRecord::IDLE; recordPtr->curReceiver = nullptr; recordPtr->commonEventData->SetCode(code); @@ -631,7 +630,7 @@ bool CommonEventControlManager::FinishReceiver(std::shared_ptr recordPtr, const int &code, +bool CommonEventControlManager::FinishReceiverAction(std::shared_ptr recordPtr, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { EVENT_LOGI("enter"); @@ -650,7 +649,7 @@ bool CommonEventControlManager::FinishReceiverAction(std::shared_ptrpublishInfo->GetSubscriberPermissions()) { if (permissionNum == 0) { separator = ""; @@ -941,7 +940,7 @@ void CommonEventControlManager::DumpStateByCommonEventRecord( std::string action = "\t\tAction: " + record->commonEventData->GetWant().GetAction() + "\n"; std::string entities = "\t\tEntity: "; - int entityNum = 0; + size_t entityNum = 0; for (auto entitiesVec : record->commonEventData->GetWant().GetEntities()) { if (entityNum == 0) { separator = ""; @@ -1022,7 +1021,7 @@ void CommonEventControlManager::DumpHistoryStateByCommonEventRecord( std::string permission = "\tRequiredPermission: "; std::string separator; - int permissionNum = 0; + size_t permissionNum = 0; for (auto permissionVec : record.subscriberPermissions) { if (permissionNum == 0) { separator = ""; @@ -1055,7 +1054,7 @@ void CommonEventControlManager::DumpHistoryStateByCommonEventRecord( std::string action = "\t\tAction: " + record.want.GetAction() + "\n"; std::string entities = "\t\tEntity: "; - int entityNum = 0; + size_t entityNum = 0; for (auto entitiesVec : record.want.GetEntities()) { if (entityNum == 0) { separator = ""; @@ -1118,7 +1117,7 @@ void CommonEventControlManager::DumpStateBySubscriberRecord( return; } - int num = 0; + size_t num = 0; for (auto receiver : record->receivers) { num++; @@ -1163,7 +1162,7 @@ void CommonEventControlManager::DumpHistoryStateBySubscriberRecord( return; } - int num = 0; + size_t num = 0; for (auto receiver : record.receivers) { num++; @@ -1248,7 +1247,7 @@ void CommonEventControlManager::DumpState( return; } - int num = 0; + size_t num = 0; for (auto record : records) { num++; @@ -1281,7 +1280,7 @@ void CommonEventControlManager::DumpHistoryState( return; } - int num = 0; + size_t num = 0; for (auto record : records) { num++; diff --git a/services/src/common_event_manager_service.cpp b/services/src/common_event_manager_service.cpp index 0c73717..f43c9b4 100644 --- a/services/src/common_event_manager_service.cpp +++ b/services/src/common_event_manager_service.cpp @@ -284,7 +284,7 @@ bool CommonEventManagerService::DumpState(const std::string &event, const int32_ } bool CommonEventManagerService::FinishReceiver( - const sptr &proxy, const int &code, const std::string &receiverData, const bool &abortEvent) + const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { EVENT_LOGI("enter"); diff --git a/services/src/common_event_permission_manager.cpp b/services/src/common_event_permission_manager.cpp index 19906cc..131d8f5 100644 --- a/services/src/common_event_permission_manager.cpp +++ b/services/src/common_event_permission_manager.cpp @@ -24,7 +24,7 @@ namespace OHOS { namespace EventFwk { -const int REVERSE = 3; +constexpr size_t REVERSE = 3; static const std::unordered_map>> COMMON_EVENT_MAP { {CommonEventSupport::COMMON_EVENT_BOOT_COMPLETED, diff --git a/services/src/common_event_sticky_manager.cpp b/services/src/common_event_sticky_manager.cpp index 49313ef..3d468ca 100644 --- a/services/src/common_event_sticky_manager.cpp +++ b/services/src/common_event_sticky_manager.cpp @@ -19,7 +19,7 @@ namespace OHOS { namespace EventFwk { -constexpr int LENGTH = 80; +constexpr int32_t LENGTH = 80; int CommonEventStickyManager::FindStickyEvents( const SubscribeInfoPtr &subscribeInfo, std::vector &commonEventRecords) @@ -85,7 +85,7 @@ void CommonEventStickyManager::DumpState( return; } - int num = 0; + size_t num = 0; for (auto record : records) { num++; @@ -106,7 +106,7 @@ void CommonEventStickyManager::DumpState( std::string permission = "\tRequiredPermission: "; std::string separator; - int permissionNum = 0; + size_t permissionNum = 0; for (auto permissionVec : record->publishInfo->GetSubscriberPermissions()) { if (permissionNum == 0) { separator = ""; @@ -137,7 +137,7 @@ void CommonEventStickyManager::DumpState( std::string action = "\t\tAction: " + record->commonEventData->GetWant().GetAction() + "\n"; std::string entities = "\t\tEntity: "; - int entityNum = 0; + size_t entityNum = 0; for (auto entitiesVec : record->commonEventData->GetWant().GetEntities()) { if (entityNum == 0) { separator = ""; diff --git a/services/src/common_event_subscriber_manager.cpp b/services/src/common_event_subscriber_manager.cpp index 6338332..0a4a7ea 100644 --- a/services/src/common_event_subscriber_manager.cpp +++ b/services/src/common_event_subscriber_manager.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace EventFwk { -const int LENGTH = 80; +constexpr int32_t LENGTH = 80; CommonEventSubscriberManager::CommonEventSubscriberManager() : death_(sptr(new SubscriberDeathRecipient())) @@ -106,6 +106,10 @@ std::vector> CommonEventSubscriberManager void CommonEventSubscriberManager::DumpDetailed( const std::string &title, const SubscriberRecordPtr &record, const std::string format, std::string &dumpInfo) { + if (record == nullptr || record->eventSubscribeInfo == nullptr) { + EVENT_LOGE("record or eventSubscribeInfo is null"); + return; + } char systime[LENGTH]; strftime(systime, sizeof(char) * LENGTH, "%Y%m%d %I:%M %p", &record->recordTime); @@ -132,7 +136,8 @@ void CommonEventSubscriberManager::DumpDetailed( std::string events = format + "\tEvent: "; std::string separator; - for (int eventNum = 0; eventNum < record->eventSubscribeInfo->GetMatchingSkills().CountEvent(); ++eventNum) { + size_t countSize = record->eventSubscribeInfo->GetMatchingSkills().CountEvent(); + for (auto eventNum = 0; eventNum < countSize; ++eventNum) { if (eventNum == 0) { separator = ""; } else { @@ -143,7 +148,8 @@ void CommonEventSubscriberManager::DumpDetailed( events = events + "\n"; std::string entities = format + "\tEntity: "; - for (int entityNum = 0; entityNum < record->eventSubscribeInfo->GetMatchingSkills().CountEntities(); ++entityNum) { + size_t entitySize = record->eventSubscribeInfo->GetMatchingSkills().CountEntities(); + for (size_t entityNum = 0; entityNum < entitySize; ++entityNum) { if (entityNum == 0) { separator = ""; } else { @@ -154,7 +160,8 @@ void CommonEventSubscriberManager::DumpDetailed( entities = entities + "\n"; std::string scheme = format + "\tScheme: "; - for (int schemeNum = 0; schemeNum < record->eventSubscribeInfo->GetMatchingSkills().CountSchemes(); ++schemeNum) { + size_t schemeSize = record->eventSubscribeInfo->GetMatchingSkills().CountSchemes(); + for (size_t schemeNum = 0; schemeNum < schemeSize; ++schemeNum) { if (schemeNum == 0) { separator = ""; } else { @@ -195,7 +202,7 @@ void CommonEventSubscriberManager::DumpState(const std::string &event, const int return; } - int num = 0; + size_t num = 0; for (auto record : records) { num++; std::string title = std::to_string(num); diff --git a/services/src/inner_common_event_manager.cpp b/services/src/inner_common_event_manager.cpp index 3968b29..0f1ab27 100644 --- a/services/src/inner_common_event_manager.cpp +++ b/services/src/inner_common_event_manager.cpp @@ -179,7 +179,7 @@ bool InnerCommonEventManager::UnsubscribeCommonEvent(const sptr & std::shared_ptr sp = controlPtr_->GetMatchingOrderedReceiver(commonEventListener); if (sp) { EVENT_LOGI("Unsubscribe the subscriber who is waiting to receive finish feedback"); - int code = sp->commonEventData->GetCode(); + int32_t code = sp->commonEventData->GetCode(); std::string data = sp->commonEventData->GetData(); controlPtr_->FinishReceiverAction(sp, code, data, sp->resultAbort); } @@ -216,7 +216,7 @@ void InnerCommonEventManager::DumpState(const std::string &event, const int32_t } void InnerCommonEventManager::FinishReceiver( - const sptr &proxy, const int &code, const std::string &receiverData, const bool &abortEvent) + const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent) { EVENT_LOGI("enter"); diff --git a/services/test/moduletest/common_event_services_publish_ordered_module_test/common_event_services_publish_ordered_module_test.cpp b/services/test/moduletest/common_event_services_publish_ordered_module_test/common_event_services_publish_ordered_module_test.cpp index ca7984f..d35d5ff 100644 --- a/services/test/moduletest/common_event_services_publish_ordered_module_test/common_event_services_publish_ordered_module_test.cpp +++ b/services/test/moduletest/common_event_services_publish_ordered_module_test/common_event_services_publish_ordered_module_test.cpp @@ -53,10 +53,10 @@ std::mutex g_mtx; std::mutex g_mtxAnother; const time_t TIME_OUT_SECONDS_LIMIT = 5; const time_t TIME_OUT_SECONDS_MIDDLE = 15; -const int INITCODE = 0; -const int CHANGECODE = 1; -const int LOWPRIORITY = 0; -const int HIGHPRIORITY = 100; +const int32_t INITCODE = 0; +const int32_t CHANGECODE = 1; +const int32_t LOWPRIORITY = 0; +const int32_t HIGHPRIORITY = 100; } // namespace class CesPublishOrderedEventModuleTest : public testing::Test { diff --git a/services/test/unittest/mock/src/mock_bundle_manager.cpp b/services/test/unittest/mock/src/mock_bundle_manager.cpp index 7007089..1c4e8c5 100644 --- a/services/test/unittest/mock/src/mock_bundle_manager.cpp +++ b/services/test/unittest/mock/src/mock_bundle_manager.cpp @@ -20,7 +20,7 @@ namespace OHOS { namespace AppExecFwk { -constexpr uint16_t SYSTEM_UID = 1000; +constexpr int SYSTEM_UID = 1000; void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp) { @@ -28,12 +28,12 @@ void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp) isSystemApp_ = isSystemApp; } -bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid) +bool MockBundleMgrService::CheckIsSystemAppByUid(const int32_t uid) { if (isSystemAppMock_) { return isSystemApp_; } - return (uid > SYSTEM_UID) ? false : true; + return uid <= SYSTEM_UID; } } // namespace AppExecFwk } // namespace OHOS diff --git a/test/mock/mock_bundle_manager.cpp b/test/mock/mock_bundle_manager.cpp index abd6b00..00120c9 100644 --- a/test/mock/mock_bundle_manager.cpp +++ b/test/mock/mock_bundle_manager.cpp @@ -28,7 +28,7 @@ void MockBundleMgrService::MockSetIsSystemApp(bool isSystemApp) isSystemApp_ = isSystemApp; } -bool MockBundleMgrService::CheckIsSystemAppByUid(const int uid) +bool MockBundleMgrService::CheckIsSystemAppByUid(const int32_t uid) { if (isSystemAppMock_) { return isSystemApp_; diff --git a/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp b/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp index 96602ae..f92c0cf 100755 --- a/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp +++ b/test/systemtest/common/ces/common_event_services_publish_ordered_system_test/common_event_services_publish_ordered_system_test.cpp @@ -48,10 +48,10 @@ std::mutex g_mtx; std::mutex g_mtxAnother; const time_t TIME_OUT_SECONDS_LIMIT = 5; const time_t TIME_OUT_SECONDS_MIDDLE = 15; -const int INITCODE = 0; -const int CHANGECODE = 1; -const int LOWPRIORITY = 0; -const int HIGHPRIORITY = 100; +const int32_t INITCODE = 0; +const int32_t CHANGECODE = 1; +const int32_t LOWPRIORITY = 0; +const int32_t HIGHPRIORITY = 100; } // namespace class CESPublishOrderedEventSystmTest : public testing::Test { diff --git a/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp b/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp index 9728403..3297645 100644 --- a/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp +++ b/test/systemtest/common/ces/common_event_services_system_test/common_event_services_system_test.cpp @@ -43,8 +43,8 @@ const time_t TIME_OUT_SECONDS_TWO = 2; const time_t TIME_OUT_SECONDS_ = 3; const time_t TIME_OUT_SECONDS_TEN = 10; const time_t TIME_OUT_SECONDS_TWENTY = 20; -const unsigned int SUBSCRIBER_MAX_SIZE = 200; -const unsigned int SUBSCRIBER_MAX_SIZE_PLUS = 201; +const size_t SUBSCRIBER_MAX_SIZE = 200; +const size_t SUBSCRIBER_MAX_SIZE_PLUS = 201; const std::string CompareStr = "cesComparesStrForCase"; const std::string CompareStrFalse = "cesComparesStrForCaseFalse"; diff --git a/tools/cem/include/common_event_command.h b/tools/cem/include/common_event_command.h index f6f29c0..e0f0348 100644 --- a/tools/cem/include/common_event_command.h +++ b/tools/cem/include/common_event_command.h @@ -61,8 +61,7 @@ public: */ CommonEventCommand(int argc, char *argv[]); - ~CommonEventCommand() override - {} + ~CommonEventCommand() override = default; private: ErrCode CreateCommandMap() override; diff --git a/tools/cem/include/shell_command.h b/tools/cem/include/shell_command.h index 1562e46..f2655ab 100644 --- a/tools/cem/include/shell_command.h +++ b/tools/cem/include/shell_command.h @@ -27,8 +27,6 @@ namespace OHOS { namespace EventFwk { namespace { const std::string HELP_MSG_NO_OPTION = "error: you must specify an option at least."; - -const int OFFSET_REQUIRED_ARGUMENT = 2; } // namespace class ShellCommand { @@ -79,7 +77,7 @@ public: * @param code Indicates the code. * @return Returns the message from the code. */ - std::string GetMessageFromCode(const int32_t code) const; + std::string GetMessageFromCode(int32_t code) const; /** * Creates the command map. diff --git a/tools/cem/src/shell_command.cpp b/tools/cem/src/shell_command.cpp index 07ac03e..ed4b37f 100644 --- a/tools/cem/src/shell_command.cpp +++ b/tools/cem/src/shell_command.cpp @@ -16,6 +16,8 @@ #include "shell_command.h" #include + +#include #include "event_log_wrapper.h" namespace OHOS { @@ -33,12 +35,11 @@ ShellCommand::ShellCommand(int argc, char *argv[], std::string name) } cmd_ = argv[1]; for (int i = 2; i < argc; i++) { - argList_.push_back(argv[i]); + argList_.emplace_back(argv[i]); } } -ShellCommand::~ShellCommand() -{} +ShellCommand::~ShellCommand() = default; ErrCode ShellCommand::OnCommand() { @@ -103,7 +104,7 @@ std::string ShellCommand::GetUnknownOptionMsg(std::string &unknownOption) const return result; } -std::string ShellCommand::GetMessageFromCode(const int32_t code) const +std::string ShellCommand::GetMessageFromCode(int32_t code) const { EVENT_LOGI("[%{public}s(%{public}s)] enter", __FILE__, __FUNCTION__); EVENT_LOGI("code = %{public}d", code); @@ -111,7 +112,7 @@ std::string ShellCommand::GetMessageFromCode(const int32_t code) const std::string result = ""; if (messageMap_.find(code) != messageMap_.end()) { std::string message = messageMap_.at(code); - if (message.size() != 0) { + if (!message.empty()) { result.append(message + "\n"); } } diff --git a/tools/test/mock/mock_common_event_stub.h b/tools/test/mock/mock_common_event_stub.h index 9780c1d..2ff7403 100644 --- a/tools/test/mock/mock_common_event_stub.h +++ b/tools/test/mock/mock_common_event_stub.h @@ -25,7 +25,7 @@ namespace OHOS { namespace EventFwk { class MockCommonEventStub : public CommonEventStub { public: - MOCK_METHOD4(FinishReceiver, bool(const sptr &proxy, const int &code, + MOCK_METHOD4(FinishReceiver, bool(const sptr &proxy, const int32_t &code, const std::string &receiverData, const bool &abortEvent)); /** diff --git a/tools/test/systemtest/cem/common_event_command_dump_system_test.cpp b/tools/test/systemtest/cem/common_event_command_dump_system_test.cpp index 4df5f83..52d1eae 100644 --- a/tools/test/systemtest/cem/common_event_command_dump_system_test.cpp +++ b/tools/test/systemtest/cem/common_event_command_dump_system_test.cpp @@ -27,7 +27,7 @@ using namespace OHOS::EventFwk; namespace { const std::string STRING_EVENT = "com.ces.event"; const std::string STRING_NO_SUBSCRIBERS = "Subscribers:\tNo information\n"; -const int TIME_DELAY_FOR_SERVICES = 2; +const int32_t TIME_DELAY_FOR_SERVICES = 2; std::string ExecuteCommand(const std::string &command) { diff --git a/tools/test/systemtest/cem/common_event_command_publish_system_test.cpp b/tools/test/systemtest/cem/common_event_command_publish_system_test.cpp index 27153db..965ac6a 100644 --- a/tools/test/systemtest/cem/common_event_command_publish_system_test.cpp +++ b/tools/test/systemtest/cem/common_event_command_publish_system_test.cpp @@ -34,7 +34,7 @@ const std::string STRING_DATA_TWO = "data_two"; const std::string STRING_DEVICE_ID_001 = "device_001"; const std::string STRING_DEVICE_ID_002 = "device_002"; const std::string STRING_DEVICE_ID_003 = "device_003"; -const int TIME_DELAY_FOR_SERVICES = 2; +const int32_t TIME_DELAY_FOR_SERVICES = 2; const time_t TIME_OUT_SECONDS_LIMIT = 5; std::mutex mtx; @@ -98,7 +98,7 @@ public: std::string deviceId = GetSubscribeInfo().GetDeviceId(); GTEST_LOG_(INFO) << "deviceId = " << deviceId; - int code = commonEventData.GetCode(); + int32_t code = commonEventData.GetCode(); GTEST_LOG_(INFO) << "code = " << code; std::string data = commonEventData.GetData();