From adf3d29c2fe7836312325b5f83f230ea366c0373 Mon Sep 17 00:00:00 2001 From: hwyml Date: Tue, 3 Sep 2024 16:10:09 +0800 Subject: [PATCH] clear db when user stopped Signed-off-by: hwyml Change-Id: I08b617d1ae5a12a7613fcc62538c2818a2b10996 --- services/native/include/usb_right_manager.h | 1 + services/native/src/usb_right_manager.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/services/native/include/usb_right_manager.h b/services/native/include/usb_right_manager.h index c5835fb5..eaefa39c 100644 --- a/services/native/include/usb_right_manager.h +++ b/services/native/include/usb_right_manager.h @@ -51,6 +51,7 @@ public: bool IsSystemApp(); int32_t CleanUpRightExpired(std::vector &devices); static int32_t CleanUpRightUserDeleted(int32_t &totalUsers, int32_t &deleteUsers); + static int32_t CleanUpRightUserStopped(int32_t uid); static int32_t IsOsAccountExists(int32_t id, bool &isAccountExists); static int32_t CleanUpRightAppUninstalled(int32_t uid, const std::string &bundleName); int32_t HasSetFuncRight(int32_t functions); diff --git a/services/native/src/usb_right_manager.cpp b/services/native/src/usb_right_manager.cpp index 3372378f..e366af19 100644 --- a/services/native/src/usb_right_manager.cpp +++ b/services/native/src/usb_right_manager.cpp @@ -88,6 +88,10 @@ public: USB_HILOGD(MODULE_USB_SERVICE, "recv event user delete: event=%{public}s, delete detail[%{public}d/%{public}d]: %{public}d", wantAction.c_str(), deleteUsers, totalUsers, ret); + } else if (wantAction == CommonEventSupport::COMMON_EVENT_USER_STOPPED) { + int32_t uid = data.GetCode(); + int32_t ret = UsbRightManager::CleanUpRightUserStopped(uid); + USB_HILOGD(MODULE_USB_SERVICE, "on user %{public}d stopped, ret=%{public}d", uid, ret); } } }; @@ -103,6 +107,7 @@ int32_t UsbRightManager::Init() /* subscribe uid/user remove event */ matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_UID_REMOVED); matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_REMOVED); + matchingSkills.AddEvent(CommonEventSupport::COMMON_EVENT_USER_STOPPED); CommonEventSubscribeInfo subscriberInfo(matchingSkills); std::shared_ptr subscriber = std::make_shared(subscriberInfo); bool ret = CommonEventManager::SubscribeCommonEvent(subscriber); @@ -674,6 +679,17 @@ int32_t UsbRightManager::CleanUpRightUserDeleted(int32_t &totalUsers, int32_t &d return USB_RIGHT_OK; } +int32_t UsbRightManager::CleanUpRightUserStopped(int32_t uid) +{ + std::shared_ptr helper = UsbRightDbHelper::GetInstance(); + if (helper == nullptr) { + USB_HILOGE(MODULE_USB_SERVICE, "CleanUpRightUserStopped %{public}d: helper is null", uid); + return false; + } + + return helper->DeleteUidRightRecord(uid); +} + int32_t UsbRightManager::CleanUpRightTemporaryExpired(const std::string &deviceName) { std::shared_ptr helper = UsbRightDbHelper::GetInstance(); -- Gitee