From 04b6ba1fd49a65063a06fb47c643071b2d152604 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 18 Apr 2022 17:17:26 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E9=80=82=E9=85=8Dinner=5Fsdk=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- .../innerkits/include/bundle_active_client.h | 5 ++- .../innerkits/include/bundle_active_proxy.h | 6 +-- .../innerkits/src/bundle_active_client.cpp | 8 ++-- .../innerkits/src/bundle_active_proxy.cpp | 6 ++- .../common/include/bundle_active_service.h | 4 +- .../common/include/ibundle_active_service.h | 4 +- services/common/src/bundle_active_service.cpp | 40 +++++++++++++------ services/common/src/bundle_active_stub.cpp | 2 + 8 files changed, 48 insertions(+), 27 deletions(-) diff --git a/interfaces/innerkits/include/bundle_active_client.h b/interfaces/innerkits/include/bundle_active_client.h index 0c62f66..85a5318 100644 --- a/interfaces/innerkits/include/bundle_active_client.h +++ b/interfaces/innerkits/include/bundle_active_client.h @@ -46,13 +46,14 @@ public: * return: vector of bundle usage statistics. */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, - const int64_t endTime, int32_t& errCode); + const int64_t endTime, int32_t& errCode, int userId = -1); /* * function: QueryEvents, query all events in specific time span for calling user. * parameters: beginTime, endTime, errCode * return: vector of events. */ - std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, int32_t& errCode); + std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, + int32_t& errCode, int userId = -1); /* * function: SetBundleGroup, set specific bundle of specific user to a priority group. * parameters: bundleName, newGroup, userId diff --git a/interfaces/innerkits/include/bundle_active_proxy.h b/interfaces/innerkits/include/bundle_active_proxy.h index 3627748..de35a83 100644 --- a/interfaces/innerkits/include/bundle_active_proxy.h +++ b/interfaces/innerkits/include/bundle_active_proxy.h @@ -44,14 +44,14 @@ public: * return: vector of bundle usage statistics. */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, - const int64_t endTime, int32_t& errCode) override; + const int64_t endTime, int32_t& errCode, int userId = -1) override; /* * function: QueryEvents, query all events in specific time span for calling user. * parameters: beginTime, endTime, errCode * return: vector of events. */ - std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, - int32_t& errCode) override; + std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, + int32_t& errCode, int userId = -1) override; /* * function: SetBundleGroup, set specific bundle of specific user to a priority group. * parameters: bundleName, newGroup, userId diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index f6bff8d..d478a03 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -63,21 +63,21 @@ bool BundleActiveClient::IsBundleIdle(const std::string& bundleName) } std::vector BundleActiveClient::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode) + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) { if (!GetBundleActiveProxy()) { return std::vector(0); } - return bundleActiveProxy_->QueryPackageStats(intervalType, beginTime, endTime, errCode); + return bundleActiveProxy_->QueryPackageStats(intervalType, beginTime, endTime, errCode, userId); } std::vector BundleActiveClient::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode) + const int64_t endTime, int32_t& errCode, int userId) { if (!GetBundleActiveProxy()) { return std::vector(0); } - return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode); + return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode, int userId); } void BundleActiveClient::SetBundleGroup(std::string bundleName, const int newGroup, const int userId) diff --git a/interfaces/innerkits/src/bundle_active_proxy.cpp b/interfaces/innerkits/src/bundle_active_proxy.cpp index 12aa116..f74fb04 100644 --- a/interfaces/innerkits/src/bundle_active_proxy.cpp +++ b/interfaces/innerkits/src/bundle_active_proxy.cpp @@ -49,7 +49,7 @@ bool BundleActiveProxy::IsBundleIdle(const std::string& bundleName) } std::vector BundleActiveProxy::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode) + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) { MessageParcel data; MessageParcel reply; @@ -61,6 +61,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const data.WriteInt32(intervalType); data.WriteInt64(beginTime); data.WriteInt64(endTime); + data.WriteInt32(userId); data.WriteInt32(errCode); Remote() -> SendRequest(QUERY_USAGE_STATS, data, reply, option); errCode = reply.ReadInt32(); @@ -85,7 +86,7 @@ std::vector BundleActiveProxy::QueryPackageStats(const } std::vector BundleActiveProxy::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode) + const int64_t endTime, int32_t& errCode, int userId) { MessageParcel data; MessageParcel reply; @@ -96,6 +97,7 @@ std::vector BundleActiveProxy::QueryEvents(const int64_t begi } data.WriteInt64(beginTime); data.WriteInt64(endTime); + data.WriteInt32(userId); data.WriteInt32(errCode); Remote() -> SendRequest(QUERY_EVENTS, data, reply, option); errCode = reply.ReadInt32(); diff --git a/services/common/include/bundle_active_service.h b/services/common/include/bundle_active_service.h index e892224..558434d 100644 --- a/services/common/include/bundle_active_service.h +++ b/services/common/include/bundle_active_service.h @@ -58,14 +58,14 @@ public: * return: vector of bundle usage statistics. */ std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, - const int64_t endTime, int32_t& errCode) override; + const int64_t endTime, int32_t& errCode, int userId = -1) override; /* * function: QueryEvents, query all events in specific time span for calling user. * parameters: beginTime, endTime, errCode * return: vector of events. */ std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, - int32_t& errCode) override; + int32_t& errCode, int userId = -1) override; /* * function: SetBundleGroup, set specific bundle of specific user to a priority group. * parameters: bundleName, newGroup, userId diff --git a/services/common/include/ibundle_active_service.h b/services/common/include/ibundle_active_service.h index 2655275..d223bee 100644 --- a/services/common/include/ibundle_active_service.h +++ b/services/common/include/ibundle_active_service.h @@ -62,14 +62,14 @@ public: * return: vector of bundle usage statistics. */ virtual std::vector QueryPackageStats(const int intervalType, const int64_t beginTime, - const int64_t endTime, int32_t& errCode) = 0; + const int64_t endTime, int32_t& errCode, int userId) = 0; /* * function: QueryEvents, query all events in specific time span for calling user. * parameters: beginTime, endTime, errCode * return: vector of events. */ virtual std::vector QueryEvents(const int64_t beginTime, const int64_t endTime, - int32_t& errCode) = 0; + int32_t& errCode, int userId) = 0; /* * function: QueryCurrentPackageStats, query bundle usage statistics in specific time span for calling bundle. * parameters: intervalType, beginTime, endTime diff --git a/services/common/src/bundle_active_service.cpp b/services/common/src/bundle_active_service.cpp index a2ac0d2..28983c7 100644 --- a/services/common/src/bundle_active_service.cpp +++ b/services/common/src/bundle_active_service.cpp @@ -253,7 +253,7 @@ bool BundleActiveService::IsBundleIdle(const std::string& bundleName) } std::vector BundleActiveService::QueryPackageStats(const int intervalType, - const int64_t beginTime, const int64_t endTime, int32_t& errCode) + const int64_t beginTime, const int64_t endTime, int32_t& errCode, int userId) { BUNDLE_ACTIVE_LOGI("QueryPackageStats stats called, intervaltype is %{public}d", intervalType); @@ -261,13 +261,21 @@ std::vector BundleActiveService::QueryPackageStats(con // get uid int callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("QueryPackageStats UID is %{public}d", callingUid); - // get userid - int userId = -1; - OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); - if (ret == ERR_OK && userId != -1) { + if (userId == -1) { + // get userid + OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + if (ret != ERR_OK) { + errCode = -1; + return result; + } + } + if (userId != -1) { BUNDLE_ACTIVE_LOGI("QueryPackageStats user id is %{public}d", userId); bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode); - if (isSystemAppAndHasPermission == true) { + AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + if (isSystemAppAndHasPermission == true || + AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == + AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { int convertedIntervalType = ConvertIntervalType(intervalType); result = bundleActiveCore_->QueryPackageStats(userId, convertedIntervalType, beginTime, endTime, ""); } @@ -276,20 +284,28 @@ std::vector BundleActiveService::QueryPackageStats(con } std::vector BundleActiveService::QueryEvents(const int64_t beginTime, - const int64_t endTime, int32_t& errCode) + const int64_t endTime, int32_t& errCode, int userId) { BUNDLE_ACTIVE_LOGI("QueryEvents stats called"); std::vector result; // get uid int callingUid = OHOS::IPCSkeleton::GetCallingUid(); BUNDLE_ACTIVE_LOGI("QueryEvents UID is %{public}d", callingUid); - // get userid - int userId = -1; - OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); - if (ret == ERR_OK && userId != -1) { + if (userId == -1) { + // get userid + OHOS::ErrCode ret = OHOS::AccountSA::OsAccountManager::GetOsAccountLocalIdFromUid(callingUid, userId); + if (ret != ERR_OK) { + errCode = -1; + return result; + } + } + if (userId != -1) { BUNDLE_ACTIVE_LOGI("QueryEvents userid is %{public}d", userId); bool isSystemAppAndHasPermission = CheckBundleIsSystemAppAndHasPermission(callingUid, userId, errCode); - if (isSystemAppAndHasPermission == true) { + AccessToken::AccessTokenID tokenId = OHOS::IPCSkeleton::GetCallingTokenID(); + if (isSystemAppAndHasPermission == true || + AccessToken::AccessTokenKit::GetTokenTypeFlag(tokenId) == + AccessToken::TypeATokenTypeEnum::TOKEN_NATIVE) { result = bundleActiveCore_->QueryEvents(userId, beginTime, endTime, ""); } } diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 46c5503..8474659 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -50,6 +50,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me intervalType); int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); + int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); result = QueryPackageStats(intervalType, beginTime, endTime, errCode); reply.WriteInt32(errCode); @@ -69,6 +70,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int size = 0; int64_t beginTime = data.ReadInt64(); int64_t endTime = data.ReadInt64(); + int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); result = QueryEvents(beginTime, endTime, errCode); size = static_cast(result.size()); -- Gitee From 937b3cb2ccff0f54067b88dc7aac1493ec744180 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 18 Apr 2022 18:15:54 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E9=80=82=E9=85=8Dinner=5Fsdk=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- services/common/src/bundle_active_stub.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/common/src/bundle_active_stub.cpp b/services/common/src/bundle_active_stub.cpp index 8474659..fb11273 100644 --- a/services/common/src/bundle_active_stub.cpp +++ b/services/common/src/bundle_active_stub.cpp @@ -52,7 +52,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int64_t endTime = data.ReadInt64(); int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); - result = QueryPackageStats(intervalType, beginTime, endTime, errCode); + result = QueryPackageStats(intervalType, beginTime, endTime, errCode, userId); reply.WriteInt32(errCode); size = static_cast(result.size()); BUNDLE_ACTIVE_LOGI("OnRemoteRequest QUERY_USAGE_STATS result size is %{public}d", size); @@ -72,7 +72,7 @@ int32_t BundleActiveStub::OnRemoteRequest(uint32_t code, MessageParcel& data, Me int64_t endTime = data.ReadInt64(); int32_t userId = data.ReadInt32(); int32_t errCode = data.ReadInt32(); - result = QueryEvents(beginTime, endTime, errCode); + result = QueryEvents(beginTime, endTime, errCode, userId); size = static_cast(result.size()); reply.WriteInt32(errCode); reply.WriteInt32(size); -- Gitee From 08074123e18e32eea4d0e8a614ba26201f137a58 Mon Sep 17 00:00:00 2001 From: houdisheng Date: Mon, 18 Apr 2022 18:25:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E9=80=82=E9=85=8Dinner=5Fsdk=E8=B0=83?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: houdisheng --- interfaces/innerkits/src/bundle_active_client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/innerkits/src/bundle_active_client.cpp b/interfaces/innerkits/src/bundle_active_client.cpp index d478a03..ef7bb21 100644 --- a/interfaces/innerkits/src/bundle_active_client.cpp +++ b/interfaces/innerkits/src/bundle_active_client.cpp @@ -77,7 +77,7 @@ std::vector BundleActiveClient::QueryEvents(const int64_t beg if (!GetBundleActiveProxy()) { return std::vector(0); } - return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode, int userId); + return bundleActiveProxy_->QueryEvents(beginTime, endTime, errCode, userId); } void BundleActiveClient::SetBundleGroup(std::string bundleName, const int newGroup, const int userId) -- Gitee