修复包卸载中调用过多kvstore

Signed-off-by: swg3156201044 <shiweigang2@huawei.com>
This commit is contained in:
swg3156201044 2024-09-04 08:43:09 +00:00
parent fedba77a6f
commit 13a96cae25
10 changed files with 90 additions and 0 deletions

View File

@ -103,12 +103,14 @@ ohos_moduletest("domain_account_frameworks_module_mock_test") {
cflags = [ "-pipe" ]
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -122,6 +124,7 @@ ohos_moduletest("domain_account_frameworks_module_mock_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"src/domain_account_client_module_test.cpp",
"src/mock_domain_auth_callback.cpp",
"src/mock_domain_auth_callback_for_listener.cpp",
@ -180,6 +183,9 @@ ohos_moduletest("domain_account_frameworks_module_mock_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
if (os_account_enable_multiple_os_accounts || use_clang_coverage) {
@ -192,12 +198,14 @@ ohos_moduletest("domain_account_client_mock_plugin_so_module_test") {
cflags = [ "-pipe" ]
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -211,6 +219,7 @@ ohos_moduletest("domain_account_client_mock_plugin_so_module_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"src/domain_account_client_mock_plugin_so_module_test.cpp",
"src/mock_domain_get_access_token_callback.cpp",
"src/mock_domain_has_domain_info_callback.cpp",
@ -266,6 +275,9 @@ ohos_moduletest("domain_account_client_mock_plugin_so_module_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
if (os_account_enable_multiple_os_accounts || use_clang_coverage) {

View File

@ -85,12 +85,14 @@ ohos_moduletest("AccountInnerSdkModuleMockTest") {
module_out_path = module_output_path
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -111,6 +113,7 @@ ohos_moduletest("AccountInnerSdkModuleMockTest") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
]
sources += account_service_sources
sources += [ "account_mgr_inner_sdk_func_test.cpp" ]
@ -165,6 +168,9 @@ ohos_moduletest("AccountInnerSdkModuleMockTest") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
if (os_account_enable_multiple_os_accounts || use_clang_coverage) {

View File

@ -105,12 +105,14 @@ ohos_moduletest("os_account_frameworks_module_mock_test") {
module_out_path = module_output_path
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -130,6 +132,7 @@ ohos_moduletest("os_account_frameworks_module_mock_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"os_account_manager_module_test.cpp",
]
sources += account_service_sources
@ -182,6 +185,9 @@ ohos_moduletest("os_account_frameworks_module_mock_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
cflags_cc += [ "-DENABLE_MULTIPLE_OS_ACCOUNTS" ]
@ -202,12 +208,14 @@ ohos_moduletest("os_account_manager_no_bms_mock_test") {
module_out_path = module_output_path
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -226,6 +234,7 @@ ohos_moduletest("os_account_manager_no_bms_mock_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"${services_path}/accountmgr/src/bundle_manager_adapter/bundle_manager_adapter.cpp",
"os_account_manager_no_bms_mock_test.cpp",
]
@ -275,6 +284,9 @@ ohos_moduletest("os_account_manager_no_bms_mock_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
cflags_cc += [ "-DENABLE_MULTIPLE_OS_ACCOUNTS" ]

View File

@ -24,6 +24,7 @@
#include "iapp_account_authenticator_callback.h"
#include "iremote_object.h"
#include "want_params.h"
#include "safe_map.h"
namespace OHOS {
namespace AccountSA {
@ -109,6 +110,7 @@ public:
void OnAbilityStateChanged(const AppExecFwk::AbilityStateData &abilityStateData);
void AddMigratedAccount(int32_t localId);
void MoveData();
void SetOsAccountRemoved(int32_t localId, bool isRemoved);
private:
AppAccountControlManager() = default;
@ -141,6 +143,8 @@ private:
const std::shared_ptr<AppAccountDataStorage> &dataStoragePtr);
ErrCode RemoveAuthorizedAccountFromDataStorage(const std::string &authorizedApp, AppAccountInfo &appAccountInfo,
const std::shared_ptr<AppAccountDataStorage> &dataStoragePtr);
bool IsOsAccountRemoved(int32_t localId);
ErrCode RemoveAppAccountData(const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex);
private:
std::mutex mutex_;
@ -152,6 +156,7 @@ private:
std::set<int32_t> migratedAccounts_;
sptr<AppExecFwk::IAppMgr> iAppMgr_;
sptr<AppAccountAppStateObserver> appStateObserver_;
SafeMap<int32_t, bool> removedOsAccounts_;
std::size_t ACCOUNT_MAX_SIZE = 1000;
std::size_t ASSOCIATED_DATA_CACHE_MAX_SIZE = 5;
};

View File

@ -37,6 +37,7 @@ void AccountEventSubscriberCallback::OnReceiveEvent(const EventFwk::CommonEventD
{
auto want = data.GetWant();
std::string action = want.GetAction();
ACCOUNT_LOGI("Receive event: %{public}s", action.c_str());
if (action == EventFwk::CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED) {
auto uid = want.GetIntParam(AppExecFwk::Constants::UID, -1);
callback_.OnPackageRemoved(uid);

View File

@ -81,6 +81,7 @@ void AppAccountCommonEventObserver::OnReceiveEvent(const CommonEventData &data)
{
auto want = data.GetWant();
std::string action = want.GetAction();
ACCOUNT_LOGI("Receive event: %{public}s", action.c_str());
if (action == CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED ||
action == CommonEventSupport::COMMON_EVENT_SANDBOX_PACKAGE_REMOVED) {
DealWithRemoveEvent(want, action);

View File

@ -1041,10 +1041,36 @@ void AppAccountControlManager::RemoveAssociatedDataCacheByAccount(const uid_t &u
}
}
void AppAccountControlManager::SetOsAccountRemoved(int32_t localId, bool isRemoved)
{
if (isRemoved) {
removedOsAccounts_.EnsureInsert(localId, true);
} else {
removedOsAccounts_.Erase(localId);
}
}
bool AppAccountControlManager::IsOsAccountRemoved(int32_t localId)
{
bool isRemoved = false;
return removedOsAccounts_.Find(localId, isRemoved);
}
ErrCode AppAccountControlManager::OnPackageRemoved(
const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
{
RemoveAssociatedDataCacheByUid(uid);
int32_t localId = uid / UID_TRANSFORM_DIVISOR;
if (IsOsAccountRemoved(localId)) {
ACCOUNT_LOGI("Account %{public}d is removed", localId);
return ERR_OK;
}
return RemoveAppAccountData(uid, bundleName, appIndex);
}
ErrCode AppAccountControlManager::RemoveAppAccountData(
const uid_t &uid, const std::string &bundleName, const uint32_t &appIndex)
{
auto dataStoragePtr = GetDataStorage(uid);
if (dataStoragePtr == nullptr) {
ACCOUNT_LOGE("dataStoragePtr is nullptr");

View File

@ -29,6 +29,7 @@
#include "hitrace_adapter.h"
#include "account_hisysevent_adapter.h"
#include "account_permission_manager.h"
#include "app_account_control_manager.h"
#include "ohos_account_kits.h"
#include "os_account_constants.h"
#include "os_account_control_file_manager.h"
@ -386,6 +387,7 @@ ErrCode IInnerOsAccountManager::SendMsgForAccountCreate(
theme_thread.join();
}
#endif
AppAccountControlManager::GetInstance().SetOsAccountRemoved(osAccountInfo.GetLocalId(), false);
osAccountInfo.SetIsCreateCompleted(true);
errCode = osAccountControl_->UpdateOsAccount(osAccountInfo);
if (errCode != ERR_OK) {
@ -883,6 +885,7 @@ ErrCode IInnerOsAccountManager::CheckTypeNumber(const OsAccountType& type)
ErrCode IInnerOsAccountManager::SendMsgForAccountRemove(OsAccountInfo &osAccountInfo)
{
int32_t localId = osAccountInfo.GetLocalId();
AppAccountControlManager::GetInstance().SetOsAccountRemoved(localId, true);
ErrCode errCode = OsAccountInterface::SendToBMSAccountDelete(osAccountInfo);
if (errCode != ERR_OK) {
ACCOUNT_LOGE("SendToBMSAccountDelete failed, id %{public}d, errCode %{public}d", localId, errCode);

View File

@ -380,12 +380,14 @@ ohos_unittest("OsAccountInnerAccmgrBundleAdapterMockTest") {
module_out_path = module_output_path
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -405,6 +407,7 @@ ohos_unittest("OsAccountInnerAccmgrBundleAdapterMockTest") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"${services_path}/accountmgr/test/mock/os_account/os_account_interface.cpp",
"${services_path}/accountmgr/test/unittest/os_account/mock/mock_os_account_musl.cpp",
"os_account_inner_account_mgr_mock.cpp",
@ -463,6 +466,9 @@ ohos_unittest("OsAccountInnerAccmgrBundleAdapterMockTest") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
if (os_account_enable_multiple_os_accounts || use_clang_coverage) {
cflags_cc += [ "-DENABLE_MULTIPLE_OS_ACCOUNTS" ]
}
@ -485,12 +491,14 @@ ohos_unittest("OsAccountEventManagerMultipleThreadTest") {
module_out_path = module_output_path
include_dirs = [
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -510,6 +518,7 @@ ohos_unittest("OsAccountEventManagerMultipleThreadTest") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"os_account_event_manager_multiple_thread_test.cpp",
]
sources += account_service_sources
@ -563,6 +572,9 @@ ohos_unittest("OsAccountEventManagerMultipleThreadTest") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
cflags_cc += [ "-DENABLE_MULTIPLE_OS_ACCOUNTS" ]

View File

@ -75,12 +75,14 @@ ohos_moduletest("account_command_create_module_mock_test") {
include_dirs = [
"${ability_runtime_path}/tools/test/systemtest/aa",
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -102,6 +104,7 @@ ohos_moduletest("account_command_create_module_mock_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"${tools_path}/acm/src/account_command.cpp",
"account_command_create_module_test.cpp",
"account_command_util.cpp",
@ -160,6 +163,9 @@ ohos_moduletest("account_command_create_module_mock_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
}
@ -177,12 +183,14 @@ ohos_moduletest("account_command_delete_module_mock_test") {
include_dirs = [
"${ability_runtime_path}/tools/test/systemtest/aa",
"${app_account_innerkits_native_path}/include",
"${os_account_dfx_path}/hidumper_adapter",
"${services_path}/accountmgr/include/bundle_manager_adapter",
"${services_path}/accountmgr/include/ability_manager_adapter",
"${services_path}/accountmgr/include",
"${os_account_dfx_path}/hitrace_adapter",
"${services_path}/accountmgr/include/account_iam",
"${services_path}/accountmgr/include/appaccount",
"${services_path}/accountmgr/include/domain_account",
"${services_path}/accountmgr/include/osaccount",
"${bundle_framework_path}/interfaces/inner_api/appexecfwk_core/include",
@ -204,6 +212,7 @@ ohos_moduletest("account_command_delete_module_mock_test") {
"${services_path}/accountmgr/src/account_iam/account_iam_mgr_stub.cpp",
"${services_path}/accountmgr/src/account_iam/account_iam_service.cpp",
"${services_path}/accountmgr/src/account_iam/inner_account_iam_manager.cpp",
"${services_path}/accountmgr/src/appaccount/app_account_control_manager.cpp",
"${tools_path}/acm/src/account_command.cpp",
"account_command_delete_module_test.cpp",
"account_command_util.cpp",
@ -262,6 +271,9 @@ ohos_moduletest("account_command_delete_module_mock_test") {
cflags_cc += [ "-DHAS_CES_PART" ]
external_deps += [ "common_event_service:cesfwk_innerkits" ]
}
if (has_kv_store_part) {
external_deps += [ "kv_store:distributeddata_inner" ]
}
cflags_cc += [ "-DACCOUNT_TEST" ]
cflags_cc += [ "-DBUNDLE_ADAPTER_MOCK" ]
}