From 9be9804d027fd808e4835327a949645a64a4b3c1 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 15 Jun 2022 10:49:39 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=B7=BB=E5=8A=A0isbundleidle=E5=AF=B9nati?= =?UTF-8?q?ve=E8=BF=9B=E7=A8=8B=E7=9A=84=E6=9D=83=E9=99=90=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_service.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index de701d7..4a6612a 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -260,14 +260,16 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName, int32_t& e int32_t userId = -1; int32_t result = -1; BundleActiveAccountHelper::GetUserId(callingUid, userId); - if (userId != -1 && !callingBundleName.empty()) { + if (userId != -1) { if (callingBundleName == bundleName) { BUNDLE_ACTIVE_LOGI("%{public}s check its own idle state", bundleName.c_str()); result = bundleActiveCore_->IsBundleIdle(bundleName, userId); } else { bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, tokenId, errCode); BUNDLE_ACTIVE_LOGI("check other bundle idle state"); - if (isSystemAppAndHasPermission) { + if (isSystemAppAndHasPermission || + AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == + AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { errCode = 0; result = bundleActiveCore_->IsBundleIdle(bundleName, userId); } else { -- Gitee From bf86d4cbc51bb7d5be8e8eb989aa37b89ef6851a Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 15 Jun 2022 11:06:19 +0800 Subject: [PATCH 2/4] =?UTF-8?q?isbundleidle=E6=8E=A5=E5=8F=A3=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0native=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/include/bundle_active_client.h | 2 +- interfaces/innerkits/include/bundle_active_proxy.h | 2 +- interfaces/innerkits/src/bundle_active_client.cpp | 4 ++-- interfaces/innerkits/src/bundle_active_proxy.cpp | 4 +++- services/common/include/bundle_active_service.h | 2 +- services/common/include/ibundle_active_service.h | 2 +- services/common/src/bundle_active_service.cpp | 7 ++++--- services/common/src/bundle_active_stub.cpp | 3 ++- 8 files changed, 15 insertions(+), 11 deletions(-) diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 6e186ba..772000c 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -42,7 +42,7 @@ public: * parameters: bundleName * return: if bundle is idle, return true. if bundle is not idle, return false. */ - bool IsBundleIdle(const std::string& bundleName, int32_t& errCode); + bool IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId = -1); /* * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. * parameters: intervalType, beginTime, endTime, errCode diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index 5adce7c..9e0a205 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -38,7 +38,7 @@ public: * parameters: bundleName * return: if bundle is idle, return true. if bundle is not idle, return false. */ - bool IsBundleIdle(const std::string& bundleName, int32_t& errCode) override; + bool IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId = -1) override; /* * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. * parameters: intervalType, beginTime, endTime, errCode diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index 2b635de..4c0441d 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -63,12 +63,12 @@ int32_t BundleActiveClient::ReportEvent(BundleActiveEvent event, const int32_t u return bundleActiveProxy_->ReportEvent(event, userId); } -bool BundleActiveClient::IsBundleIdle(const std::string& bundleName, int32_t& errCode) +bool BundleActiveClient::IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId) { if (!GetBundleActiveProxy()) { return -1; } - return bundleActiveProxy_->IsBundleIdle(bundleName, errCode); + return bundleActiveProxy_->IsBundleIdle(bundleName, errCode, userId); } std::vector BundleActiveClient::QueryPackageStats(const int32_t intervalType, diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 93bc327..d4b64f7 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -33,7 +33,7 @@ int32_t BundleActiveProxy::ReportEvent(BundleActiveEvent& event, const int32_t u return result; } -bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName, int32_t& errCode) +bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId) { MessageParcel data; MessageParcel reply; @@ -42,6 +42,8 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName, int32_t& err return false; } data.WriteString(bundleName); + data.WriteInt32(errCode); + data.WriteInt32(userId); Remote() -> SendRequest(IS_BUNDLE_IDLE, data, reply, option); bool result = reply.ReadInt32(); errCode = reply.ReadInt32(); diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index 7e45ef2..92ad34e 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -56,7 +56,7 @@ public: * parameters: bundleName * return: if bundle is idle, return true. if bundle is not idle, return false. */ - bool IsBundleIdle(const std::string& bundleName, int32_t& errCode) override; + bool IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId = -1) override; /* * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. * parameters: intervalType, beginTime, endTime, errCode diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index ee37510..4935160 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -61,7 +61,7 @@ public: * parameters: bundleName * return: if bundle is idle, return true. if bundle is not idle, return false. */ - virtual bool IsBundleIdle(const std::string& bundleName, int32_t& errCode) = 0; + virtual bool IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId) = 0; /* * function: QueryPackageStats, query all bundle usage statistics in specific time span for calling user. * parameters: intervalType, beginTime, endTime, errCode diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index 4a6612a..0d13b45 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -244,7 +244,7 @@ int32_t BundleActiveService::ReportEvent(BundleActiveEvent& event, const int32_t } } -bool BundleActiveService::IsBundleIdle(const std::string& bundleName, int32_t& errCode) +bool BundleActiveService::IsBundleIdle(const std::string& bundleName, int32_t& errCode, int32_t userId) { // get uid int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid(); @@ -257,9 +257,10 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName, int32_t& e sptrBundleMgr_->GetBundleNameForUid(callingUid, callingBundleName); BUNDLE_ACTIVE_LOGI("UID is %{public}d, bundle name is %{public}s", callingUid, callingBundleName.c_str()); // get user id - int32_t userId = -1; int32_t result = -1; - BundleActiveAccountHelper::GetUserId(callingUid, userId); + if (userId == -1) { + BundleActiveAccountHelper::GetUserId(callingUid, userId); + } if (userId != -1) { if (callingBundleName == bundleName) { BUNDLE_ACTIVE_LOGI("%{public}s check its own idle state", bundleName.c_str()); diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 3dae350..4745fe8 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -41,7 +41,8 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me case IS_BUNDLE_IDLE: { std::string bundleName = data.ReadString(); int32_t errCode = data.ReadInt32(); - int32_t result = IsBundleIdle(bundleName, errCode); + int32_t userId = data.ReadInt32(); + int32_t result = IsBundleIdle(bundleName, errCode, userId); reply.WriteInt32(result); return reply.WriteInt32(errCode); } -- Gitee From 3a1f13aa2867ea407ae6ab1cd2cf295d3ff97cde Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 15 Jun 2022 13:56:22 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=80=82=E9=85=8Dtdd=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- test/unittest/device_usage_statistics_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/unittest/device_usage_statistics_test.cpp b/test/unittest/device_usage_statistics_test.cpp index 2748693..7c8142b 100644 --- a/test/unittest/device_usage_statistics_test.cpp +++ b/test/unittest/device_usage_statistics_test.cpp @@ -151,9 +151,9 @@ HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_QueryPackagesStats HWTEST_F(DeviceUsageStatisticsTest, DeviceUsageStatisticsTest_IsBundleIdle_001, Function | MediumTest | Level0) { int32_t errCode = 0; - bool result = BundleActiveClient::GetInstance().IsBundleIdle(DEFAULT_BUNDLENAME, errCode); + bool result = BundleActiveClient::GetInstance().IsBundleIdle(DEFAULT_BUNDLENAME, errCode, DEFAULT_USERID); EXPECT_EQ(result, false); - EXPECT_EQ(errCode, -1); + EXPECT_EQ(errCode, 0); } /* -- Gitee From 28387759245b928c4fc20cca5e272fc28f2980b8 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Wed, 15 Jun 2022 15:10:53 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=AE=E6=94=B9proxyipc=E9=80=9A?= =?UTF-8?q?=E8=AE=AF=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_proxy.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 3161b35..f984489 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -38,12 +38,12 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName, int32_t& err MessageParcel data; MessageParcel reply; MessageOption option; - if (!data.WriteInterfaceToken(GetDescriptor())) { + if (!data.WriteInterfaceToken(GetDescriptor()) || + !data.WriteString(bundleName) || + !data.WriteInt32(errCode) || + !data.WriteInt32(userId)) { return false; } - data.WriteString(bundleName); - data.WriteInt32(errCode); - data.WriteInt32(userId); Remote() -> SendRequest(IS_BUNDLE_IDLE, data, reply, option); bool result = reply.ReadInt32(); errCode = reply.ReadInt32(); -- Gitee