From 28cb4991639c3ecd3c69c898d488300dc569567f Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Tue, 16 May 2023 21:53:42 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E5=AF=B9=E8=8E=B7=E5=8F=96=E5=AF=B9?= =?UTF-8?q?=E7=AB=AF=E6=9C=8D=E5=8A=A1=E5=AF=B9=E8=B1=A1Remote()=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E5=88=A4=E7=A9=BA=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_proxy.cpp | 84 ++++++++++++++++--- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 4b01289..e1682c5 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -19,6 +19,11 @@ namespace OHOS { namespace DeviceUsageStats { ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -27,7 +32,7 @@ ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t u } data.WriteInt32(userId); event.Marshalling(data); - Remote() -> SendRequest(REPORT_EVENT, data, reply, option); + remote -> SendRequest(REPORT_EVENT, data, reply, option); int32_t result = reply.ReadInt32(); return result; @@ -35,6 +40,11 @@ ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t u ErrCode BundleActiveProxy::IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -43,7 +53,7 @@ ErrCode BundleActiveProxy::IsBundleIdle(bool& isBundleIdle, const std::string& b !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - Remote() -> SendRequest(IS_BUNDLE_IDLE, data, reply, option); + remote -> SendRequest(IS_BUNDLE_IDLE, data, reply, option); isBundleIdle = reply.ReadInt32(); return reply.ReadInt32(); } @@ -51,6 +61,11 @@ ErrCode BundleActiveProxy::IsBundleIdle(bool& isBundleIdle, const std::string& b ErrCode BundleActiveProxy::QueryBundleStatsInfoByInterval(std::vector& PackageStats, const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -61,7 +76,7 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfoByInterval(std::vector SendRequest(QUERY_BUNDLE_STATS_INFO_BY_INTERVAL, data, reply, option); + remote -> SendRequest(QUERY_BUNDLE_STATS_INFO_BY_INTERVAL, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; @@ -86,6 +101,11 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfoByInterval(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime, int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -95,7 +115,7 @@ ErrCode BundleActiveProxy::QueryBundleEvents(std::vector& bun data.WriteInt64(beginTime); data.WriteInt64(endTime); data.WriteInt32(userId); - Remote() -> SendRequest(QUERY_BUNDLE_EVENTS, data, reply, option); + remote -> SendRequest(QUERY_BUNDLE_EVENTS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; @@ -114,6 +134,11 @@ ErrCode BundleActiveProxy::QueryBundleEvents(std::vector& bun ErrCode BundleActiveProxy::SetAppGroup(const std::string& bundleName, int32_t newGroup, int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -124,13 +149,18 @@ ErrCode BundleActiveProxy::SetAppGroup(const std::string& bundleName, int32_t ne data.WriteInt32(newGroup); data.WriteInt32(userId); - Remote() -> SendRequest(SET_APP_GROUP, data, reply, option); + remote -> SendRequest(SET_APP_GROUP, data, reply, option); return reply.ReadInt32(); } ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector& bundleActivePackageStats, const int32_t intervalType, const int64_t beginTime, const int64_t endTime) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -140,7 +170,7 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector SendRequest(QUERY_BUNDLE_STATS_INFOS, data, reply, option); + remote -> SendRequest(QUERY_BUNDLE_STATS_INFOS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; @@ -167,6 +197,11 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -175,7 +210,7 @@ ErrCode BundleActiveProxy::QueryCurrentBundleEvents(std::vector SendRequest(QUERY_CURRENT_BUNDLE_EVENTS, data, reply, option); + remote -> SendRequest(QUERY_CURRENT_BUNDLE_EVENTS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; @@ -196,6 +231,11 @@ ErrCode BundleActiveProxy::QueryCurrentBundleEvents(std::vector SendRequest(QUERY_APP_GROUP, data, reply, option); + remote -> SendRequest(QUERY_APP_GROUP, data, reply, option); appGroup = reply.ReadInt32(); return reply.ReadInt32(); } @@ -214,6 +254,11 @@ ErrCode BundleActiveProxy::QueryAppGroup(int32_t& appGroup, std::string& bundleN ErrCode BundleActiveProxy::QueryModuleUsageRecords(int32_t maxNum, std::vector& results, int32_t userId) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -222,7 +267,7 @@ ErrCode BundleActiveProxy::QueryModuleUsageRecords(int32_t maxNum, std::vector SendRequest(QUERY_MODULE_USAGE_RECORDS, data, reply, option); + remote -> SendRequest(QUERY_MODULE_USAGE_RECORDS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; @@ -253,6 +298,11 @@ ErrCode BundleActiveProxy::RegisterAppGroupCallBack(const sptrSendRequest(REGISTER_APP_GROUP_CALLBACK, data, reply, option); + int32_t ret = remote->SendRequest(REGISTER_APP_GROUP_CALLBACK, data, reply, option); if (ret!= ERR_OK) { BUNDLE_ACTIVE_LOGE("RegisterAppGroupCallBack SendRequest failed, error code: %{public}d", ret); } @@ -277,6 +327,11 @@ ErrCode BundleActiveProxy::UnRegisterAppGroupCallBack(const sptrSendRequest(UNREGISTER_APP_GROUP_CALLBACK, data, reply, option); + remote ->SendRequest(UNREGISTER_APP_GROUP_CALLBACK, data, reply, option); return reply.ReadInt32(); } @@ -316,6 +371,11 @@ ErrCode BundleActiveProxy::QueryNotificationEventStats(int64_t beginTime, int64_ ErrCode BundleActiveProxy::IPCCommunication(int64_t beginTime, int64_t endTime, std::vector& eventStats, int32_t userId, int32_t communicationFlag) { + auto remote = Remote(); + if (remote == nullptr) { + BUNDLE_ACTIVE_LOGE("device_usage_statistics remote is dead."); + return ERR_IPC_COMMUNICATION_FAILED; + } MessageParcel data; MessageParcel reply; MessageOption option; @@ -325,7 +385,7 @@ ErrCode BundleActiveProxy::IPCCommunication(int64_t beginTime, int64_t endTime, data.WriteInt64(beginTime); data.WriteInt64(endTime); data.WriteInt32(userId); - Remote() -> SendRequest(communicationFlag, data, reply, option); + remote -> SendRequest(communicationFlag, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); std::shared_ptr tmp; -- Gitee From c99cc09e6a6b73cdd8e22949dd879de264dfe603 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 17 May 2023 15:07:45 +0800 Subject: [PATCH 2/7] =?UTF-8?q?IPC=E5=A2=9E=E5=8A=A0=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=AD=BB?= =?UTF-8?q?=E4=BA=A1=E8=BD=AE=E8=AF=A2=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_client.cpp | 5 +- .../innerkits/src/bundle_active_proxy.cpp | 50 ++++++------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index c24711d..db0350a 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -34,6 +34,7 @@ ErrCode BundleActiveClient::GetBundleActiveProxy() if (bundleActiveProxy_ != nullptr) { return ERR_OK; } + sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); @@ -252,8 +253,10 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() { std::lock_guard lock(BundleActiveClient::GetInstance().mutex_); - while (BundleActiveClient::GetInstance().GetBundleActiveProxy() != ERR_OK) { + int32_t loopTimes = 3; + while ((BundleActiveClient::GetInstance().GetBundleActiveProxy() != ERR_OK) && (loopTimes > 0)) { sleep(SLEEP_TIME); + loopTimes--; } if (observer_) { BundleActiveClient::GetInstance().RegisterAppGroupCallBack(observer_); diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index e1682c5..b70fd24 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -27,10 +27,9 @@ ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t u MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - data.WriteInt32(userId); event.Marshalling(data); remote -> SendRequest(REPORT_EVENT, data, reply, option); @@ -48,9 +47,7 @@ ErrCode BundleActiveProxy::IsBundleIdle(bool& isBundleIdle, const std::string& b MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor()) || - !data.WriteString(bundleName) || - !data.WriteInt32(userId)) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } remote -> SendRequest(IS_BUNDLE_IDLE, data, reply, option); @@ -69,13 +66,10 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfoByInterval(std::vector SendRequest(QUERY_BUNDLE_STATS_INFO_BY_INTERVAL, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); @@ -109,12 +103,10 @@ ErrCode BundleActiveProxy::QueryBundleEvents(std::vector& bun MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt64(beginTime) || + !data.WriteInt64(endTime) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - data.WriteInt32(userId); remote -> SendRequest(QUERY_BUNDLE_EVENTS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); @@ -142,12 +134,10 @@ ErrCode BundleActiveProxy::SetAppGroup(const std::string& bundleName, int32_t ne MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteInt32(newGroup) || + !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - data.WriteString(bundleName); - data.WriteInt32(newGroup); - data.WriteInt32(userId); remote -> SendRequest(SET_APP_GROUP, data, reply, option); return reply.ReadInt32(); @@ -164,12 +154,10 @@ ErrCode BundleActiveProxy::QueryBundleStatsInfos(std::vector SendRequest(QUERY_BUNDLE_STATS_INFOS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); @@ -205,11 +193,9 @@ ErrCode BundleActiveProxy::QueryCurrentBundleEvents(std::vector SendRequest(QUERY_CURRENT_BUNDLE_EVENTS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); @@ -240,12 +226,9 @@ ErrCode BundleActiveProxy::QueryAppGroup(int32_t& appGroup, std::string& bundleN MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteString(bundleName) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - - data.WriteString(bundleName); - data.WriteInt32(userId); remote -> SendRequest(QUERY_APP_GROUP, data, reply, option); appGroup = reply.ReadInt32(); return reply.ReadInt32(); @@ -262,11 +245,9 @@ ErrCode BundleActiveProxy::QueryModuleUsageRecords(int32_t maxNum, std::vector SendRequest(QUERY_MODULE_USAGE_RECORDS, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); @@ -379,12 +360,9 @@ ErrCode BundleActiveProxy::IPCCommunication(int64_t beginTime, int64_t endTime, MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt64(beginTime) || !data.WriteInt64(endTime) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } - data.WriteInt64(beginTime); - data.WriteInt64(endTime); - data.WriteInt32(userId); remote -> SendRequest(communicationFlag, data, reply, option); ErrCode errCode = reply.ReadInt32(); int32_t size = reply.ReadInt32(); -- Gitee From 638108f259667d34af1868de201bb022c5e5a7d2 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 17 May 2023 16:37:13 +0800 Subject: [PATCH 3/7] =?UTF-8?q?IPC=E5=A2=9E=E5=8A=A0=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=AD=BB?= =?UTF-8?q?=E4=BA=A1=E8=BD=AE=E8=AF=A2=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- interfaces/innerkits/src/bundle_active_proxy.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index b70fd24..158da1b 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -360,7 +360,8 @@ ErrCode BundleActiveProxy::IPCCommunication(int64_t beginTime, int64_t endTime, MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt64(beginTime) || !data.WriteInt64(endTime) || !data.WriteInt32(userId)) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt64(beginTime) || + !data.WriteInt64(endTime) || !data.WriteInt32(userId)) { return ERR_PARCEL_WRITE_FALIED; } remote -> SendRequest(communicationFlag, data, reply, option); -- Gitee From 50e5aebdf677758a5a744e2772dc595e4fa8e3b6 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Wed, 17 May 2023 19:46:23 +0800 Subject: [PATCH 4/7] =?UTF-8?q?IPC=E5=A2=9E=E5=8A=A0=E5=88=A4=E7=A9=BA?= =?UTF-8?q?=E5=92=8C=E6=B7=BB=E5=8A=A0=E6=9C=8D=E5=8A=A1=E7=AB=AF=E6=AD=BB?= =?UTF-8?q?=E4=BA=A1=E8=BD=AE=E8=AF=A2=E4=B8=8A=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .../innerkits/src/bundle_active_client.cpp | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index db0350a..6a74a5b 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -31,6 +31,7 @@ BundleActiveClient& BundleActiveClient::GetInstance() ErrCode BundleActiveClient::GetBundleActiveProxy() { + std::lock_guard lock(mutex_); if (bundleActiveProxy_ != nullptr) { return ERR_OK; } @@ -75,7 +76,6 @@ ErrCode BundleActiveClient::GetBundleActiveProxy() ErrCode BundleActiveClient::ReportEvent(BundleActiveEvent event, const int32_t userId) { BUNDLE_ACTIVE_LOGI("BundleActiveClient::ReportEvent called"); - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -85,7 +85,6 @@ ErrCode BundleActiveClient::ReportEvent(BundleActiveEvent event, const int32_t u ErrCode BundleActiveClient::IsBundleIdle(bool& isBundleIdle, const std::string& bundleName, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -96,7 +95,6 @@ ErrCode BundleActiveClient::IsBundleIdle(bool& isBundleIdle, const std::string& ErrCode BundleActiveClient::QueryBundleStatsInfoByInterval(std::vector& PackageStats, const int32_t intervalType, const int64_t beginTime, const int64_t endTime, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -107,7 +105,6 @@ ErrCode BundleActiveClient::QueryBundleStatsInfoByInterval(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -119,7 +116,6 @@ ErrCode BundleActiveClient::QueryBundleEvents(std::vector& bu ErrCode BundleActiveClient::SetAppGroup(std::string bundleName, const int32_t newGroup, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -130,7 +126,6 @@ ErrCode BundleActiveClient::SetAppGroup(std::string bundleName, const int32_t ne ErrCode BundleActiveClient::QueryBundleStatsInfos(std::vector& bundleActivePackageStats, const int32_t intervalType, const int64_t beginTime, const int64_t endTime) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -141,7 +136,6 @@ ErrCode BundleActiveClient::QueryBundleStatsInfos(std::vector& bundleActiveEvents, const int64_t beginTime, const int64_t endTime) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -151,7 +145,6 @@ ErrCode BundleActiveClient::QueryCurrentBundleEvents(std::vector lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -166,7 +159,6 @@ ErrCode BundleActiveClient::QueryModuleUsageRecords(int32_t maxNum, std::vector< BUNDLE_ACTIVE_LOGI("maxNum is illegal, maxNum is %{public}d", maxNum); return ERR_MAX_RECORDS_NUM_BIGER_THEN_ONE_THOUSAND; } - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -176,7 +168,6 @@ ErrCode BundleActiveClient::QueryModuleUsageRecords(int32_t maxNum, std::vector< ErrCode BundleActiveClient::RegisterAppGroupCallBack(const sptr &observer) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -190,7 +181,6 @@ ErrCode BundleActiveClient::RegisterAppGroupCallBack(const sptr &observer) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -205,7 +195,6 @@ ErrCode BundleActiveClient::UnRegisterAppGroupCallBack(const sptr& eventStats, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -216,7 +205,6 @@ ErrCode BundleActiveClient::QueryDeviceEventStats(int64_t beginTime, int64_t end ErrCode BundleActiveClient::QueryNotificationEventStats(int64_t beginTime, int64_t endTime, std::vector& eventStats, int32_t userId) { - std::lock_guard lock(mutex_); ErrCode ret = GetBundleActiveProxy(); if (ret != ERR_OK) { return ret; @@ -243,8 +231,10 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::RemoveObserver() void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wptr &object) { (void)object; - std::lock_guard lock(BundleActiveClient::GetInstance().mutex_); - BundleActiveClient::GetInstance().bundleActiveProxy_ = nullptr; + { + std::lock_guard lock(BundleActiveClient::GetInstance().mutex_); + BundleActiveClient::GetInstance().bundleActiveProxy_ = nullptr; + } BundleActiveClient::GetInstance().bundleClientHandler_->PostTask([this]() { this->OnServiceDiedInner(); }, DELAY_TIME); @@ -252,7 +242,6 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() { - std::lock_guard lock(BundleActiveClient::GetInstance().mutex_); int32_t loopTimes = 3; while ((BundleActiveClient::GetInstance().GetBundleActiveProxy() != ERR_OK) && (loopTimes > 0)) { sleep(SLEEP_TIME); -- Gitee From 9514b37e48e5ffff626d642ba18bf4293e75f7ce Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 22 May 2023 19:48:29 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=8A=A0=E9=94=81=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .vscode/settings.json | 56 +++++++++++++++++++ .../innerkits/src/bundle_active_client.cpp | 16 +++++- 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8c69c5a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,56 @@ +{ + "files.associations": { + "mutex": "cpp", + "array": "cpp", + "atomic": "cpp", + "bit": "cpp", + "*.tcc": "cpp", + "cctype": "cpp", + "chrono": "cpp", + "clocale": "cpp", + "cmath": "cpp", + "condition_variable": "cpp", + "cstdarg": "cpp", + "cstddef": "cpp", + "cstdint": "cpp", + "cstdio": "cpp", + "cstdlib": "cpp", + "ctime": "cpp", + "cwchar": "cpp", + "cwctype": "cpp", + "deque": "cpp", + "map": "cpp", + "set": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "algorithm": "cpp", + "functional": "cpp", + "iterator": "cpp", + "memory": "cpp", + "memory_resource": "cpp", + "numeric": "cpp", + "optional": "cpp", + "random": "cpp", + "ratio": "cpp", + "string": "cpp", + "string_view": "cpp", + "system_error": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp", + "fstream": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "iostream": "cpp", + "istream": "cpp", + "limits": "cpp", + "new": "cpp", + "ostream": "cpp", + "sstream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "thread": "cpp", + "typeinfo": "cpp" + } +} \ No newline at end of file diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 6a74a5b..437b0b5 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -80,6 +80,7 @@ ErrCode BundleActiveClient::ReportEvent(BundleActiveEvent event, const int32_t u if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->ReportEvent(event, userId); } @@ -89,6 +90,7 @@ ErrCode BundleActiveClient::IsBundleIdle(bool& isBundleIdle, const std::string& if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->IsBundleIdle(isBundleIdle, bundleName, userId); } @@ -99,6 +101,7 @@ ErrCode BundleActiveClient::QueryBundleStatsInfoByInterval(std::vector lock(mutex_); return bundleActiveProxy_->QueryBundleStatsInfoByInterval(PackageStats, intervalType, beginTime, endTime, userId); } @@ -109,6 +112,7 @@ ErrCode BundleActiveClient::QueryBundleEvents(std::vector& bu if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); auto err = bundleActiveProxy_->QueryBundleEvents(bundleActiveEvents, beginTime, endTime, userId); BUNDLE_ACTIVE_LOGI("QueryBundleEvents bundleActiveEvents is %{public}zu", bundleActiveEvents.size()); return err; @@ -120,6 +124,7 @@ ErrCode BundleActiveClient::SetAppGroup(std::string bundleName, const int32_t ne if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->SetAppGroup(bundleName, newGroup, userId); } @@ -130,6 +135,7 @@ ErrCode BundleActiveClient::QueryBundleStatsInfos(std::vector lock(mutex_); return bundleActiveProxy_->QueryBundleStatsInfos(bundleActivePackageStats, intervalType, beginTime, endTime); } @@ -140,6 +146,7 @@ ErrCode BundleActiveClient::QueryCurrentBundleEvents(std::vector lock(mutex_); return bundleActiveProxy_->QueryCurrentBundleEvents(bundleActiveEvents, beginTime, endTime); } @@ -149,6 +156,7 @@ ErrCode BundleActiveClient::QueryAppGroup(int32_t& appGroup, std::string& bundle if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->QueryAppGroup(appGroup, bundleName, userId); } @@ -163,6 +171,7 @@ ErrCode BundleActiveClient::QueryModuleUsageRecords(int32_t maxNum, std::vector< if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->QueryModuleUsageRecords(maxNum, results, userId); } @@ -172,6 +181,7 @@ ErrCode BundleActiveClient::RegisterAppGroupCallBack(const sptr lock(mutex_); ret = bundleActiveProxy_->RegisterAppGroupCallBack(observer); if (recipient_ && ret == ERR_OK) { recipient_->AddObserver(observer); @@ -185,6 +195,7 @@ ErrCode BundleActiveClient::UnRegisterAppGroupCallBack(const sptr lock(mutex_); ret = bundleActiveProxy_->UnRegisterAppGroupCallBack(observer); if (recipient_ && ret == ERR_OK) { recipient_->RemoveObserver(); @@ -199,6 +210,7 @@ ErrCode BundleActiveClient::QueryDeviceEventStats(int64_t beginTime, int64_t end if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->QueryDeviceEventStats(beginTime, endTime, eventStats, userId); } @@ -209,6 +221,7 @@ ErrCode BundleActiveClient::QueryNotificationEventStats(int64_t beginTime, int64 if (ret != ERR_OK) { return ret; } + std::lock_guard lock(mutex_); return bundleActiveProxy_->QueryNotificationEventStats(beginTime, endTime, eventStats, userId); } @@ -242,11 +255,12 @@ void BundleActiveClient::BundleActiveClientDeathRecipient::OnRemoteDied(const wp void BundleActiveClient::BundleActiveClientDeathRecipient::OnServiceDiedInner() { - int32_t loopTimes = 3; + int32_t loopTimes = 5; while ((BundleActiveClient::GetInstance().GetBundleActiveProxy() != ERR_OK) && (loopTimes > 0)) { sleep(SLEEP_TIME); loopTimes--; } + std::lock_guard lock(mutex_); if (observer_) { BundleActiveClient::GetInstance().RegisterAppGroupCallBack(observer_); } -- Gitee From 0b6efc23bfed46e04882c58ec1f2c97ed6ca6440 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 22 May 2023 19:53:02 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=88=A0=E9=99=A4.vscode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .vscode/settings.json | 56 ------------------- .../innerkits/src/bundle_active_client.cpp | 1 - 2 files changed, 57 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8c69c5a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "files.associations": { - "mutex": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 437b0b5..8eabbe2 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -35,7 +35,6 @@ ErrCode BundleActiveClient::GetBundleActiveProxy() if (bundleActiveProxy_ != nullptr) { return ERR_OK; } - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); -- Gitee From 437c8ee22e156e50b46e3a7fb5a6abde2f0ce0f5 Mon Sep 17 00:00:00 2001 From: "yupeng74@huawei.com" Date: Mon, 22 May 2023 19:53:02 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E5=88=A0=E9=99=A4.vscode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yupeng74@huawei.com --- .vscode/settings.json | 56 ------------------- .../innerkits/src/bundle_active_client.cpp | 1 - .../innerkits/src/bundle_active_proxy.cpp | 3 +- 3 files changed, 1 insertion(+), 59 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 8c69c5a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,56 +0,0 @@ -{ - "files.associations": { - "mutex": "cpp", - "array": "cpp", - "atomic": "cpp", - "bit": "cpp", - "*.tcc": "cpp", - "cctype": "cpp", - "chrono": "cpp", - "clocale": "cpp", - "cmath": "cpp", - "condition_variable": "cpp", - "cstdarg": "cpp", - "cstddef": "cpp", - "cstdint": "cpp", - "cstdio": "cpp", - "cstdlib": "cpp", - "ctime": "cpp", - "cwchar": "cpp", - "cwctype": "cpp", - "deque": "cpp", - "map": "cpp", - "set": "cpp", - "unordered_map": "cpp", - "vector": "cpp", - "exception": "cpp", - "algorithm": "cpp", - "functional": "cpp", - "iterator": "cpp", - "memory": "cpp", - "memory_resource": "cpp", - "numeric": "cpp", - "optional": "cpp", - "random": "cpp", - "ratio": "cpp", - "string": "cpp", - "string_view": "cpp", - "system_error": "cpp", - "tuple": "cpp", - "type_traits": "cpp", - "utility": "cpp", - "fstream": "cpp", - "initializer_list": "cpp", - "iosfwd": "cpp", - "iostream": "cpp", - "istream": "cpp", - "limits": "cpp", - "new": "cpp", - "ostream": "cpp", - "sstream": "cpp", - "stdexcept": "cpp", - "streambuf": "cpp", - "thread": "cpp", - "typeinfo": "cpp" - } -} \ No newline at end of file diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 437b0b5..8eabbe2 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -35,7 +35,6 @@ ErrCode BundleActiveClient::GetBundleActiveProxy() if (bundleActiveProxy_ != nullptr) { return ERR_OK; } - sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); if (!samgr) { BUNDLE_ACTIVE_LOGE("Failed to get SystemAbilityManager."); diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 158da1b..cd6b4dc 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -27,10 +27,9 @@ ErrCode BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t u MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(userId)) { + if (!data.WriteInterfaceToken(GetDescriptor()) || !data.WriteInt32(userId) || !event.Marshalling(data)) { return ERR_PARCEL_WRITE_FALIED; } - event.Marshalling(data); remote -> SendRequest(REPORT_EVENT, data, reply, option); int32_t result = reply.ReadInt32(); -- Gitee