From f3cf2bb008ba7f59b85f1b7becb1004306a1f9b4 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Wed, 24 May 2023 08:42:35 +0000 Subject: [PATCH 01/19] add uninstall callback Signed-off-by: gongyuechen --- .../src/ability_manager_service.cpp | 2 +- services/uripermmgr/BUILD.gn | 2 + .../include/uri_bundle_event_callback.h | 49 ++++++++++++++++ .../include/uri_permission_manager_service.h | 1 + .../uri_permission_manager_stub_impl.h | 1 + .../src/uri_bundle_event_callback.cpp | 56 +++++++++++++++++++ .../src/uri_permission_manager_service.cpp | 18 ++++++ .../src/uri_permission_manager_stub_impl.cpp | 45 +++++++++++++++ 8 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 services/uripermmgr/include/uri_bundle_event_callback.h create mode 100644 services/uripermmgr/src/uri_bundle_event_callback.cpp diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index 649aa5b8084..b26e919b292 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -342,7 +342,7 @@ bool AbilityManagerService::Init() HILOG_ERROR("RegisterBundleEventCallback failed!"); } } else { - HILOG_ERROR("Get BundleManager or abilieyBundleEventCallback failed!"); + HILOG_ERROR("Get BundleManager or abilityBundleEventCallback failed!"); } }; handler_->PostTask(registerBundleEventCallbackTask, "RegisterBundleEventCallback"); diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index 195d46ac355..f3c415ba9fc 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -87,6 +87,8 @@ ohos_static_library("libupms_static") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h new file mode 100644 index 00000000000..65363398bf7 --- /dev/null +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#include "bundle_event_callback_host.h" +#include "common_event_support.h" +#include "hilog_wrapper.h" +#include "uri_permission_manager_client.h" + +namespace OHOS { +namespace AAFwk { +/** + * @brief This class is a callback class that will be registered to BundleManager. + * This class will be called by BundleManager when install, uninstall, updates of haps happens, + * and executes corresponding functionalities of Uri Permission manager. + */ +class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { +public: + UriBundleEventCallbackk(); + explicit UriBundleEventCallback(std::shared_ptr eventHandler); + + ~UriBundleEventCallback() = default; + + /** + * @brief The main callback function that will be called by BundleManager + * when install, uninstall, updates of haps happens to notify UriPermissionManger. + * @param eventData the data passed from BundleManager that includes bundleName, change type of haps + * etc. More can be found from BundleCommonEventMgr::NotifyBundleStatus() + */ + void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; + +private: + DISALLOW_COPY_AND_MOVE(UriBundleEventCallbackk); + std::shared_ptr eventHandler_ = nullptr; +}; +} // namespace OHOS +} // namespace AAFwk \ No newline at end of file diff --git a/services/uripermmgr/include/uri_permission_manager_service.h b/services/uripermmgr/include/uri_permission_manager_service.h index aeb97f78be5..c1a9f9621b5 100644 --- a/services/uripermmgr/include/uri_permission_manager_service.h +++ b/services/uripermmgr/include/uri_permission_manager_service.h @@ -44,6 +44,7 @@ private: bool ready_ = false; bool registerToService_ = false; sptr impl_; + std::shared_ptr handler_; DISALLOW_COPY_AND_MOVE(UriPermissionManagerService); }; diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index f03ce023cf7..11691813d74 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -46,6 +46,7 @@ public: const std::string targetBundleName, int autoremove) override; void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override; + void RevokeAllUriPermissions(const std::string bundleName); int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override; private: diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp new file mode 100644 index 00000000000..69522ffa501 --- /dev/null +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "uri_bundle_event_callback.h" +#include "uri_permission_manager_client.h" + +namespace OHOS { +namespace AAFwk { +UriBundleEventCallback::UriBundleEventCallback() : eventHandler_(nullptr) {} + +UriBundleEventCallback::UriBundleEventCallback(std::shared_ptr eventHandler) +{ + eventHandler_ = eventHandler; +} + + +void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) +{ + // env check + if (eventHandler_ == nullptr) { + HILOG_ERROR("OnReceiveEvent failed, eventHandler_ is nullptr"); + return; + } + const Want& want = eventData.GetWant(); + // action contains the change type of haps. + std::string action = want.GetAction(); + std::string bundleName = want.GetElement().GetBundleName(); + int uid = want.GetIntParam(KEY_UID, 0); + // verify data + if (action.empty() || bundleName.empty()) { + HILOG_ERROR("OnReceiveEvent failed, empty action/bundleName"); + return; + } + HILOG_DEBUG("OnReceiveEvent, action:%{public}s.", action.c_str()); + + if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { + HILOG_DEBUG("revoke URI permission when uninstall."); + auto upmClient = AAFwk::UriPermissionManagerClient::GetInstance(); + upmClient->RevokeAllUriPermissions(bundleName); + } +} + +} // namespace AAFwk +} // namespace OHOS \ No newline at end of file diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index d0bee404ede..dd275840a53 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -75,6 +75,24 @@ bool UriPermissionManagerService::Init() if (impl_ == nullptr) { impl_ = new UriPermissionManagerStubImpl(); } + handler_ = std::make_shared(eventLoop_, weak_from_this()); + CHECK_POINTER_RETURN_BOOL(handler_); + // Register UriBundleEventCallback to receive hap updates + HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); + auto registerBundleEventCallbackTask = [upms = shared_from_this(), impl_]() { + sptr uriBundleEventCallback_ = + new (std::nothrow) UriBundleEventCallback(upms->handler_); + auto bms = impl_->ConnectBundleManager(); + if (bms && uriBundleEventCallback_) { + bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); + if (!re) { + HILOG_ERROR("RegisterBundleEventCallback failed!"); + } + } else { + HILOG_ERROR("Get BundleManager or uriBundleEventCallback failed!"); + } + }; + handler_->PostTask(registerBundleEventCallbackTask, "RegisterBundleEventCallback"); ready_ = true; return true; } diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index bddcd8149d2..ecd75ac2a5b 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -174,6 +174,51 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) } } +void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bundleName) +{ + HILOG_DEBUG("Start to remove all uri permission for uninstalled app."); + auto callerTokenId = IPCSkeleton::GetCallingTokenID(); + Security::AccessToken::NativeTokenInfo nativeInfo; + Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo); + HILOG_DEBUG("callerprocessName : %{public}s", nativeInfo.processName.c_str()); + if (nativeInfo.processName != "foundation") { + HILOG_ERROR("RevokeAllUriPermissions can only be called by foundation"); + return; + } + + ecurity::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); + std::vector uriList; + { + std::lock_guard guard(mutex_); + for (auto iter = uriMap_.begin(); iter != uriMap_.end();) { + auto& list = iter->second; + for (auto it = list.begin(); it != list.end(); it++) { + if (it->targetTokenId == tokenId) { + HILOG_INFO("Erase an info form list."); + list.erase(it); + uriList.emplace_back(iter->first); + break; + } + } + if (list.size() == 0) { + uriMap_.erase(iter++); + } else { + iter++; + } + } + } + + auto storageMgrProxy = ConnectStorageManager(); + if (storageMgrProxy == nullptr) { + HILOG_ERROR("ConnectStorageManager failed"); + return; + } + + if (!uriList.empty()) { + storageMgrProxy->DeleteShareFile(tokenId, uriList); + } +} + int UriPermissionManagerStubImpl::RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) { HILOG_DEBUG("Start to remove uri permission manually."); -- Gitee From 25576ddae28700c9e28ca1631cf5f423548011d5 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 01:28:58 +0000 Subject: [PATCH 02/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_permission_manager_service.h | 1 + services/uripermmgr/src/uri_bundle_event_callback.cpp | 1 - services/uripermmgr/src/uri_permission_manager_service.cpp | 1 + 3 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/uripermmgr/include/uri_permission_manager_service.h b/services/uripermmgr/include/uri_permission_manager_service.h index c1a9f9621b5..e20649374d5 100644 --- a/services/uripermmgr/include/uri_permission_manager_service.h +++ b/services/uripermmgr/include/uri_permission_manager_service.h @@ -16,6 +16,7 @@ #ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_SERVICE_H #define OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_SERVICE_H +#include "ability_event_handler.h" #include "singleton.h" #include "system_ability.h" #include "uri_permission_manager_stub_impl.h" diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 69522ffa501..82db42a3716 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -14,7 +14,6 @@ */ #include "uri_bundle_event_callback.h" -#include "uri_permission_manager_client.h" namespace OHOS { namespace AAFwk { diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index dd275840a53..cbd298714cf 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -20,6 +20,7 @@ #include "ipc_skeleton.h" #include "iservice_registry.h" #include "system_ability_definition.h" +#include "uri_bundle_event_callback.h" namespace OHOS { namespace AAFwk { -- Gitee From d4fe57dbcb78ea192bfc4ca4243d2e70a5758617 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 02:03:39 +0000 Subject: [PATCH 03/19] add uninstall event Signed-off-by: gongyuechen --- services/uripermmgr/BUILD.gn | 5 +++++ services/uripermmgr/src/uri_permission_manager_stub_impl.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index f3c415ba9fc..773f74af3d7 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libupms") { deps = [ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", ] @@ -53,6 +54,10 @@ ohos_shared_library("libupms") { "bundle_framework:appexecfwk_base", "bundle_framework:appexecfwk_core", "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hisysevent_native:libhisysevent", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", "safwk:system_ability_fwk", diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index ecd75ac2a5b..7639f0a433d 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -186,7 +186,7 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun return; } - ecurity::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); + Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); std::vector uriList; { std::lock_guard guard(mutex_); -- Gitee From 82932d7acae12416715a36b755a1a89096a2bac4 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 03:15:47 +0000 Subject: [PATCH 04/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index 773f74af3d7..f02e8ddd5cd 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -42,6 +42,7 @@ ohos_shared_library("libupms") { deps = [ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", ] -- Gitee From f5ebc067da98c5b5f4c6337c1b9867ad85feae22 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 06:07:21 +0000 Subject: [PATCH 05/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/BUILD.gn | 2 +- .../include/uri_permission_manager_service.h | 1 - .../src/uri_permission_manager_service.cpp | 23 +++++++------------ 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/services/uripermmgr/BUILD.gn b/services/uripermmgr/BUILD.gn index f02e8ddd5cd..c0cfe6d456c 100644 --- a/services/uripermmgr/BUILD.gn +++ b/services/uripermmgr/BUILD.gn @@ -25,6 +25,7 @@ config("upms_config") { } libupms_sources = [ + "src/uri_bundle_event_callback.cpp", "src/uri_permission_manager_service.cpp", "src/uri_permission_manager_stub_impl.cpp", ] @@ -42,7 +43,6 @@ ohos_shared_library("libupms") { deps = [ "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", - "${ability_runtime_services_path}/abilitymgr:abilityms", "${ability_runtime_services_path}/common:event_report", "${ability_runtime_services_path}/common:perm_verification", ] diff --git a/services/uripermmgr/include/uri_permission_manager_service.h b/services/uripermmgr/include/uri_permission_manager_service.h index e20649374d5..c1a9f9621b5 100644 --- a/services/uripermmgr/include/uri_permission_manager_service.h +++ b/services/uripermmgr/include/uri_permission_manager_service.h @@ -16,7 +16,6 @@ #ifndef OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_SERVICE_H #define OHOS_ABILITY_RUNTIME_URI_PERMISSION_MANAGER_SERVICE_H -#include "ability_event_handler.h" #include "singleton.h" #include "system_ability.h" #include "uri_permission_manager_stub_impl.h" diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index cbd298714cf..35b2762bd52 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -76,24 +76,17 @@ bool UriPermissionManagerService::Init() if (impl_ == nullptr) { impl_ = new UriPermissionManagerStubImpl(); } - handler_ = std::make_shared(eventLoop_, weak_from_this()); - CHECK_POINTER_RETURN_BOOL(handler_); // Register UriBundleEventCallback to receive hap updates HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); - auto registerBundleEventCallbackTask = [upms = shared_from_this(), impl_]() { - sptr uriBundleEventCallback_ = - new (std::nothrow) UriBundleEventCallback(upms->handler_); - auto bms = impl_->ConnectBundleManager(); - if (bms && uriBundleEventCallback_) { - bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); - if (!re) { - HILOG_ERROR("RegisterBundleEventCallback failed!"); - } - } else { - HILOG_ERROR("Get BundleManager or uriBundleEventCallback failed!"); + auto bms = impl_->ConnectBundleManager(); + if (bms && uriBundleEventCallback_) { + bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); + if (!re) { + HILOG_ERROR("RegisterBundleEventCallback failed!"); } - }; - handler_->PostTask(registerBundleEventCallbackTask, "RegisterBundleEventCallback"); + } else { + HILOG_ERROR("Get BundleManager or uriBundleEventCallback failed!"); + } ready_ = true; return true; } -- Gitee From 5c3ad94946e3ddd35d6643ce3c0a1ddc38b79b80 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 07:47:52 +0000 Subject: [PATCH 06/19] add uninstall callback Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_bundle_event_callback.h | 8 +------- services/uripermmgr/src/uri_bundle_event_callback.cpp | 9 --------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 65363398bf7..4aa8a8667e5 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -28,9 +28,7 @@ namespace AAFwk { */ class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - UriBundleEventCallbackk(); - explicit UriBundleEventCallback(std::shared_ptr eventHandler); - + UriBundleEventCallback(); ~UriBundleEventCallback() = default; /** @@ -40,10 +38,6 @@ public: * etc. More can be found from BundleCommonEventMgr::NotifyBundleStatus() */ void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; - -private: - DISALLOW_COPY_AND_MOVE(UriBundleEventCallbackk); - std::shared_ptr eventHandler_ = nullptr; }; } // namespace OHOS } // namespace AAFwk \ No newline at end of file diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 82db42a3716..1461c2d36c4 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -17,14 +17,6 @@ namespace OHOS { namespace AAFwk { -UriBundleEventCallback::UriBundleEventCallback() : eventHandler_(nullptr) {} - -UriBundleEventCallback::UriBundleEventCallback(std::shared_ptr eventHandler) -{ - eventHandler_ = eventHandler; -} - - void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) { // env check @@ -36,7 +28,6 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even // action contains the change type of haps. std::string action = want.GetAction(); std::string bundleName = want.GetElement().GetBundleName(); - int uid = want.GetIntParam(KEY_UID, 0); // verify data if (action.empty() || bundleName.empty()) { HILOG_ERROR("OnReceiveEvent failed, empty action/bundleName"); -- Gitee From d8afc92fd7887f7b06b0f91378b11d8e4f299682 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 08:18:17 +0000 Subject: [PATCH 07/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_bundle_event_callback.h | 1 - services/uripermmgr/include/uri_permission_manager_service.h | 1 - .../uripermmgr/include/uri_permission_manager_stub_impl.h | 2 +- services/uripermmgr/src/uri_bundle_event_callback.cpp | 5 ----- services/uripermmgr/src/uri_permission_manager_service.cpp | 2 ++ 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 4aa8a8667e5..38fd91dc012 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -17,7 +17,6 @@ #include "bundle_event_callback_host.h" #include "common_event_support.h" #include "hilog_wrapper.h" -#include "uri_permission_manager_client.h" namespace OHOS { namespace AAFwk { diff --git a/services/uripermmgr/include/uri_permission_manager_service.h b/services/uripermmgr/include/uri_permission_manager_service.h index c1a9f9621b5..aeb97f78be5 100644 --- a/services/uripermmgr/include/uri_permission_manager_service.h +++ b/services/uripermmgr/include/uri_permission_manager_service.h @@ -44,7 +44,6 @@ private: bool ready_ = false; bool registerToService_ = false; sptr impl_; - std::shared_ptr handler_; DISALLOW_COPY_AND_MOVE(UriPermissionManagerService); }; diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 11691813d74..3dddff1c5f3 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -48,10 +48,10 @@ public: void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override; void RevokeAllUriPermissions(const std::string bundleName); int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override; + sptr ConnectBundleManager(); private: sptr ConnectAppMgr(); - sptr ConnectBundleManager(); sptr ConnectStorageManager(); int GetCurrentAccountId(); void ClearAppMgrProxy(); diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 1461c2d36c4..4ac8119e20f 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -19,11 +19,6 @@ namespace OHOS { namespace AAFwk { void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) { - // env check - if (eventHandler_ == nullptr) { - HILOG_ERROR("OnReceiveEvent failed, eventHandler_ is nullptr"); - return; - } const Want& want = eventData.GetWant(); // action contains the change type of haps. std::string action = want.GetAction(); diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index 35b2762bd52..5f986f68f47 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -79,6 +79,8 @@ bool UriPermissionManagerService::Init() // Register UriBundleEventCallback to receive hap updates HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); auto bms = impl_->ConnectBundleManager(); + sptr uriBundleEventCallback_ = + new (std::nothrow) UriBundleEventCallback(); if (bms && uriBundleEventCallback_) { bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); if (!re) { -- Gitee From a3154645a4a70f58c65af9299eed8f5f26e38e82 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 08:45:15 +0000 Subject: [PATCH 08/19] uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/src/uri_bundle_event_callback.cpp | 5 +++-- services/uripermmgr/src/uri_permission_manager_service.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 4ac8119e20f..c873dbc6075 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -14,6 +14,7 @@ */ #include "uri_bundle_event_callback.h" +#include "uri_permission_manager_stub_impl.h" namespace OHOS { namespace AAFwk { @@ -32,8 +33,8 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { HILOG_DEBUG("revoke URI permission when uninstall."); - auto upmClient = AAFwk::UriPermissionManagerClient::GetInstance(); - upmClient->RevokeAllUriPermissions(bundleName); + auto upms = std::make_shared(); + upms->RevokeAllUriPermissions(bundleName); } } diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index 5f986f68f47..04f1d2dfaa1 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -79,7 +79,7 @@ bool UriPermissionManagerService::Init() // Register UriBundleEventCallback to receive hap updates HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); auto bms = impl_->ConnectBundleManager(); - sptr uriBundleEventCallback_ = + sptr uriBundleEventCallback_ = new (std::nothrow) UriBundleEventCallback(); if (bms && uriBundleEventCallback_) { bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); -- Gitee From 2fdd6f69e89e8a0540cccbeb5b76f90dca5de58d Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 11:26:23 +0000 Subject: [PATCH 09/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_bundle_event_callback.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 38fd91dc012..873b57bdf02 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -27,7 +27,7 @@ namespace AAFwk { */ class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - UriBundleEventCallback(); + UriBundleEventCallback() = default;; ~UriBundleEventCallback() = default; /** -- Gitee From bee399e1722ad9e1138e40e430dd88b80c20931c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Thu, 25 May 2023 14:17:44 +0000 Subject: [PATCH 10/19] add uninstall observer Signed-off-by: gongyuechen --- services/abilitymgr/src/ability_manager_service.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/abilitymgr/src/ability_manager_service.cpp b/services/abilitymgr/src/ability_manager_service.cpp index b26e919b292..f66f0f00ba3 100644 --- a/services/abilitymgr/src/ability_manager_service.cpp +++ b/services/abilitymgr/src/ability_manager_service.cpp @@ -4850,7 +4850,7 @@ void AbilityManagerService::UpdateMissionSnapShot(const sptr& tok } auto isSaCall = AAFwk::PermissionVerification::GetInstance()->IsSACall(); if (!isSaCall) { - if(!CheckCallingTokenId(BUNDLE_NAME_LAUNCHER, GetUserId())) { + if (!CheckCallingTokenId(BUNDLE_NAME_LAUNCHER, GetUserId())) { HILOG_ERROR("Not launcher called, not allowed."); return; } -- Gitee From 1a06edaa5c4da9384be398265cf3694d9eaefb43 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 01:16:32 +0000 Subject: [PATCH 11/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/src/uri_permission_manager_service.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index 04f1d2dfaa1..bb0a0a581a1 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -79,10 +79,10 @@ bool UriPermissionManagerService::Init() // Register UriBundleEventCallback to receive hap updates HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); auto bms = impl_->ConnectBundleManager(); - sptr uriBundleEventCallback_ = + sptr uriBundleEventCallback = new (std::nothrow) UriBundleEventCallback(); - if (bms && uriBundleEventCallback_) { - bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback_); + if (bms && uriBundleEventCallback) { + bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback); if (!re) { HILOG_ERROR("RegisterBundleEventCallback failed!"); } -- Gitee From 549d0341b918cd2a7c6da4b65759683cf2993f0c Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 01:37:47 +0000 Subject: [PATCH 12/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/src/uri_permission_manager_stub_impl.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 7639f0a433d..186f4f9c3dc 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -193,11 +193,10 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun for (auto iter = uriMap_.begin(); iter != uriMap_.end();) { auto& list = iter->second; for (auto it = list.begin(); it != list.end(); it++) { - if (it->targetTokenId == tokenId) { + if (it->targetTokenId == tokenId || it->fromTokenId == tokenId) { HILOG_INFO("Erase an info form list."); list.erase(it); uriList.emplace_back(iter->first); - break; } } if (list.size() == 0) { -- Gitee From ae5e57433612f13dac4f52fde29e1d730dd9382f Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 02:24:56 +0000 Subject: [PATCH 13/19] add uninstall observer Signed-off-by: gongyuechen --- .../include/uri_bundle_event_callback.h | 7 +++---- .../src/uri_bundle_event_callback.cpp | 17 ++++++++++------- .../src/uri_permission_manager_service.cpp | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 873b57bdf02..0902f8ad3a9 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -13,11 +13,9 @@ * limitations under the License. */ - #include "bundle_event_callback_host.h" #include "common_event_support.h" #include "hilog_wrapper.h" - namespace OHOS { namespace AAFwk { /** @@ -27,9 +25,8 @@ namespace AAFwk { */ class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - UriBundleEventCallback() = default;; + UriBundleEventCallback(sptr impl); ~UriBundleEventCallback() = default; - /** * @brief The main callback function that will be called by BundleManager * when install, uninstall, updates of haps happens to notify UriPermissionManger. @@ -37,6 +34,8 @@ public: * etc. More can be found from BundleCommonEventMgr::NotifyBundleStatus() */ void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; +private: + sptr upms; }; } // namespace OHOS } // namespace AAFwk \ No newline at end of file diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index c873dbc6075..05723a14aae 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -12,12 +12,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - #include "uri_bundle_event_callback.h" #include "uri_permission_manager_stub_impl.h" - namespace OHOS { namespace AAFwk { +UriBundleEventCallback(sptr impl) +{ + upms_ = impl; +} void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData eventData) { const Want& want = eventData.GetWant(); @@ -30,13 +32,14 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even return; } HILOG_DEBUG("OnReceiveEvent, action:%{public}s.", action.c_str()); - if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) { HILOG_DEBUG("revoke URI permission when uninstall."); - auto upms = std::make_shared(); - upms->RevokeAllUriPermissions(bundleName); + if (!upms_) { + HILOG_ERROR("Uri permission manager is nullptr"); + return; + } + upms_->RevokeAllUriPermissions(bundleName); } } - } // namespace AAFwk -} // namespace OHOS \ No newline at end of file +} // namespace OHOS diff --git a/services/uripermmgr/src/uri_permission_manager_service.cpp b/services/uripermmgr/src/uri_permission_manager_service.cpp index bb0a0a581a1..18242e1298b 100644 --- a/services/uripermmgr/src/uri_permission_manager_service.cpp +++ b/services/uripermmgr/src/uri_permission_manager_service.cpp @@ -80,7 +80,7 @@ bool UriPermissionManagerService::Init() HILOG_INFO("Register UriBundleEventCallback to receive hap updates."); auto bms = impl_->ConnectBundleManager(); sptr uriBundleEventCallback = - new (std::nothrow) UriBundleEventCallback(); + new (std::nothrow) UriBundleEventCallback(impl_); if (bms && uriBundleEventCallback) { bool re = bms->RegisterBundleEventCallback(uriBundleEventCallback); if (!re) { -- Gitee From 92129c642f961cac98eb623727161c17604d2aed Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 03:26:04 +0000 Subject: [PATCH 14/19] add uninstall observer Signed-off-by: gongyuechen --- .../include/uri_bundle_event_callback.h | 2 +- .../src/uri_permission_manager_stub_impl.cpp | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 0902f8ad3a9..821ed62c051 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -35,7 +35,7 @@ public: */ void OnReceiveEvent(const EventFwk::CommonEventData eventData) override; private: - sptr upms; + sptr upms_; }; } // namespace OHOS } // namespace AAFwk \ No newline at end of file diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 186f4f9c3dc..8fbd8a5c7af 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -187,16 +187,20 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun } Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); - std::vector uriList; + std::map> uriLists; { std::lock_guard guard(mutex_); for (auto iter = uriMap_.begin(); iter != uriMap_.end();) { auto& list = iter->second; - for (auto it = list.begin(); it != list.end(); it++) { + for (auto it = list.begin(); it != list.end();) { if (it->targetTokenId == tokenId || it->fromTokenId == tokenId) { HILOG_INFO("Erase an info form list."); - list.erase(it); - uriList.emplace_back(iter->first); + uriLists[it->fromTokenId].emplace_back(iter->first); + auto currentIter = it; + it++; + list.erase(currentIter); + } else { + it++; } } if (list.size() == 0) { @@ -213,8 +217,10 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun return; } - if (!uriList.empty()) { - storageMgrProxy->DeleteShareFile(tokenId, uriList); + if (!uriLists.empty()) { + for (auto iter = uriMap_.begin(); iter != uriMap_.end();iter++) { + storageMgrProxy->DeleteShareFile(iter->first, iter->second); + } } } -- Gitee From 149f225049c1ba05cf75c7a20a3e91255cfe2d57 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 03:54:14 +0000 Subject: [PATCH 15/19] add uninstall observer Signed-off-by: gongyuechen --- .../src/uri_permission_manager_stub_impl.cpp | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 8fbd8a5c7af..ad71adfdd11 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -177,15 +177,6 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bundleName) { HILOG_DEBUG("Start to remove all uri permission for uninstalled app."); - auto callerTokenId = IPCSkeleton::GetCallingTokenID(); - Security::AccessToken::NativeTokenInfo nativeInfo; - Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(callerTokenId, nativeInfo); - HILOG_DEBUG("callerprocessName : %{public}s", nativeInfo.processName.c_str()); - if (nativeInfo.processName != "foundation") { - HILOG_ERROR("RevokeAllUriPermissions can only be called by foundation"); - return; - } - Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); std::map> uriLists; { @@ -195,10 +186,8 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun for (auto it = list.begin(); it != list.end();) { if (it->targetTokenId == tokenId || it->fromTokenId == tokenId) { HILOG_INFO("Erase an info form list."); - uriLists[it->fromTokenId].emplace_back(iter->first); - auto currentIter = it; - it++; - list.erase(currentIter); + uriLists[it->targetTokenId].emplace_back(iter->first); + list.erase(it++;); } else { it++; } -- Gitee From e005bbcfd94b5f23c51675d6c38328ea2c588ef2 Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 06:00:48 +0000 Subject: [PATCH 16/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/src/uri_permission_manager_stub_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index ad71adfdd11..80ab6739a0e 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -187,7 +187,7 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun if (it->targetTokenId == tokenId || it->fromTokenId == tokenId) { HILOG_INFO("Erase an info form list."); uriLists[it->targetTokenId].emplace_back(iter->first); - list.erase(it++;); + list.erase(it++); } else { it++; } @@ -207,7 +207,7 @@ void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bun } if (!uriLists.empty()) { - for (auto iter = uriMap_.begin(); iter != uriMap_.end();iter++) { + for (auto iter = uriLists.begin(); iter != uriLists.end(); iter++) { storageMgrProxy->DeleteShareFile(iter->first, iter->second); } } -- Gitee From 541db2292dfe8b1ac4fe81d601a76cef11179cbc Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 06:23:07 +0000 Subject: [PATCH 17/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_bundle_event_callback.h | 2 ++ services/uripermmgr/src/uri_bundle_event_callback.cpp | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 821ed62c051..4de4a1de8bd 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -16,6 +16,8 @@ #include "bundle_event_callback_host.h" #include "common_event_support.h" #include "hilog_wrapper.h" +#include "uri_permission_manager_stub_impl.h" + namespace OHOS { namespace AAFwk { /** diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 05723a14aae..8405e4fefe6 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -13,7 +13,6 @@ * limitations under the License. */ #include "uri_bundle_event_callback.h" -#include "uri_permission_manager_stub_impl.h" namespace OHOS { namespace AAFwk { UriBundleEventCallback(sptr impl) -- Gitee From 7847eace8ebba43655737bd3d250273bb431c7af Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 06:42:44 +0000 Subject: [PATCH 18/19] add uninstall observer Signed-off-by: gongyuechen --- services/uripermmgr/include/uri_bundle_event_callback.h | 3 ++- services/uripermmgr/src/uri_bundle_event_callback.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/services/uripermmgr/include/uri_bundle_event_callback.h b/services/uripermmgr/include/uri_bundle_event_callback.h index 4de4a1de8bd..87d5bc3ca48 100644 --- a/services/uripermmgr/include/uri_bundle_event_callback.h +++ b/services/uripermmgr/include/uri_bundle_event_callback.h @@ -27,7 +27,8 @@ namespace AAFwk { */ class UriBundleEventCallback : public AppExecFwk::BundleEventCallbackHost { public: - UriBundleEventCallback(sptr impl); + UriBundleEventCallback() = default; + explicit UriBundleEventCallback(sptr impl); ~UriBundleEventCallback() = default; /** * @brief The main callback function that will be called by BundleManager diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 8405e4fefe6..13506d96a5d 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -15,7 +15,7 @@ #include "uri_bundle_event_callback.h" namespace OHOS { namespace AAFwk { -UriBundleEventCallback(sptr impl) +UriBundleEventCallback::UriBundleEventCallback(sptr impl) { upms_ = impl; } -- Gitee From cb08a469277f7b34a5964b04cbb7987889a020fb Mon Sep 17 00:00:00 2001 From: gongyuechen Date: Fri, 26 May 2023 07:54:57 +0000 Subject: [PATCH 19/19] add uninstall observer Signed-off-by: gongyuechen --- .../uripermmgr/include/uri_permission_manager_stub_impl.h | 2 +- services/uripermmgr/src/uri_bundle_event_callback.cpp | 4 +++- services/uripermmgr/src/uri_permission_manager_stub_impl.cpp | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/services/uripermmgr/include/uri_permission_manager_stub_impl.h b/services/uripermmgr/include/uri_permission_manager_stub_impl.h index 3dddff1c5f3..25f369594fe 100644 --- a/services/uripermmgr/include/uri_permission_manager_stub_impl.h +++ b/services/uripermmgr/include/uri_permission_manager_stub_impl.h @@ -46,7 +46,7 @@ public: const std::string targetBundleName, int autoremove) override; void RevokeUriPermission(const Security::AccessToken::AccessTokenID tokenId) override; - void RevokeAllUriPermissions(const std::string bundleName); + void RevokeAllUriPermissions(int tokenId); int RevokeUriPermissionManually(const Uri &uri, const std::string bundleName) override; sptr ConnectBundleManager(); diff --git a/services/uripermmgr/src/uri_bundle_event_callback.cpp b/services/uripermmgr/src/uri_bundle_event_callback.cpp index 13506d96a5d..a47abf5cb91 100644 --- a/services/uripermmgr/src/uri_bundle_event_callback.cpp +++ b/services/uripermmgr/src/uri_bundle_event_callback.cpp @@ -15,6 +15,7 @@ #include "uri_bundle_event_callback.h" namespace OHOS { namespace AAFwk { +const std::string KEY_TOKEN = "accessTokenId"; UriBundleEventCallback::UriBundleEventCallback(sptr impl) { upms_ = impl; @@ -25,6 +26,7 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even // action contains the change type of haps. std::string action = want.GetAction(); std::string bundleName = want.GetElement().GetBundleName(); + int token = want.GetIntParam(KEY_TOKEN, 0); // verify data if (action.empty() || bundleName.empty()) { HILOG_ERROR("OnReceiveEvent failed, empty action/bundleName"); @@ -37,7 +39,7 @@ void UriBundleEventCallback::OnReceiveEvent(const EventFwk::CommonEventData even HILOG_ERROR("Uri permission manager is nullptr"); return; } - upms_->RevokeAllUriPermissions(bundleName); + upms_->RevokeAllUriPermissions(token); } } } // namespace AAFwk diff --git a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp index 80ab6739a0e..9bfdc9c1c1a 100644 --- a/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp +++ b/services/uripermmgr/src/uri_permission_manager_stub_impl.cpp @@ -174,10 +174,9 @@ void UriPermissionManagerStubImpl::RevokeUriPermission(const TokenId tokenId) } } -void UriPermissionManagerStubImpl::RevokeAllUriPermissions(const std::string bundleName) +void UriPermissionManagerStubImpl::RevokeAllUriPermissions(int tokenId) { HILOG_DEBUG("Start to remove all uri permission for uninstalled app."); - Security::AccessToken::AccessTokenID tokenId = GetTokenIdByBundleName(bundleName); std::map> uriLists; { std::lock_guard guard(mutex_); -- Gitee