mirror of
https://gitee.com/openharmony/account_os_account
synced 2024-11-23 10:10:11 +00:00
commit
0a098bd110
@ -49,6 +49,7 @@ ohos_shared_library("accountmgr") {
|
||||
|
||||
sources = [
|
||||
"src/account_dump_helper.cpp",
|
||||
"src/account_event_provider.cpp",
|
||||
"src/account_helper_data.cpp",
|
||||
"src/account_mgr_service.cpp",
|
||||
"src/account_state_machine.cpp",
|
||||
@ -75,6 +76,8 @@ ohos_shared_library("accountmgr") {
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"ces_standard:cesfwk_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
32
services/accountmgr/include/account_event_provider.h
Executable file
32
services/accountmgr/include/account_event_provider.h
Executable file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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.
|
||||
*/
|
||||
|
||||
#ifndef ACCOUNT_ACCOUNT_EVENT_PROVIDER_H
|
||||
#define ACCOUNT_ACCOUNT_EVENT_PROVIDER_H
|
||||
|
||||
#include <string>
|
||||
#include "account_error_no.h"
|
||||
#include "nocopyable.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
class AccountEventProvider {
|
||||
public:
|
||||
static bool EventPublish(const std::string& event);
|
||||
};
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
||||
|
||||
#endif // ACCOUNT_ACCOUNT_EVENT_PROVIDER_H
|
@ -20,6 +20,7 @@
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_event_provider.h"
|
||||
#include "account_info.h"
|
||||
#include "account_stub.h"
|
||||
#include "iaccount.h"
|
||||
|
@ -17,8 +17,10 @@
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include "account_error_no.h"
|
||||
#include "account_event_provider.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "common_event_support.h"
|
||||
#include "ohos_account_manager.h"
|
||||
#include "perf_stat.h"
|
||||
#include "string_ex.h"
|
||||
@ -180,6 +182,14 @@ bool AccountDumpHelper::ProcessTwoParameter(const std::string& arg1, const std::
|
||||
if (retRes) {
|
||||
result.append("handle input simulate event ok\n");
|
||||
}
|
||||
} else if (arg1 == ARGS_OUTPUT_SIMULATE) {
|
||||
bool errCode = AccountEventProvider::EventPublish(arg2);
|
||||
if (errCode == true) {
|
||||
result.append("Event outPut simulation success\n");
|
||||
retRes = true;
|
||||
} else {
|
||||
result.append("Event outPut simulation failed\n");
|
||||
}
|
||||
} else if (arg1 == ARGS_SET_LOG_LEVEL) {
|
||||
retRes = SetLogLevel(arg2, result);
|
||||
} else {
|
||||
|
42
services/accountmgr/src/account_event_provider.cpp
Executable file
42
services/accountmgr/src/account_event_provider.cpp
Executable file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <common_event_data.h>
|
||||
#include <common_event_support.h>
|
||||
#include "account_event_provider.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "common_event_manager.h"
|
||||
#include "ohos/aafwk/content/want.h"
|
||||
|
||||
using namespace OHOS::EventFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
bool AccountEventProvider::EventPublish(const std::string& event)
|
||||
{
|
||||
Want want;
|
||||
want.SetAction(event);
|
||||
CommonEventData data;
|
||||
data.SetWant(want);
|
||||
|
||||
/* publish */
|
||||
bool ret = CommonEventManager::PublishCommonEvent(data);
|
||||
if (ret != true) {
|
||||
ACCOUNT_LOGE("publish event failed: %{public}d", ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
} // namespace AccountSA
|
||||
} // namespace OHOS
|
@ -16,6 +16,7 @@
|
||||
#include "account_mgr_service.h"
|
||||
#include "account_dump_helper.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "common_event_support.h"
|
||||
#include "datetime_ex.h"
|
||||
#include "device_account_info.h"
|
||||
#include "directory_ex.h"
|
||||
|
@ -14,12 +14,16 @@
|
||||
*/
|
||||
|
||||
#include "ohos_account_manager.h"
|
||||
#include "account_event_provider.h"
|
||||
#include "account_helper_data.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_mgr_service.h"
|
||||
#include "common_event_support.h"
|
||||
#include "hisysevent.h"
|
||||
#include "system_ability_definition.h"
|
||||
|
||||
using namespace OHOS::EventFwk;
|
||||
|
||||
namespace OHOS {
|
||||
namespace AccountSA {
|
||||
@ -154,6 +158,7 @@ bool OhosAccountManager::HandleEvent(const std::string &eventStr)
|
||||
bool OhosAccountManager::LoginOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
std::int32_t oldStatus = currentAccount_.ohosAccountStatus_;
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LoginOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
@ -168,6 +173,12 @@ bool OhosAccountManager::LoginOhosAccount(const std::string &name, const std::st
|
||||
ACCOUNT_LOGE("LoginOhosAccount: SetAccount failed");
|
||||
return false;
|
||||
}
|
||||
bool errCode = AccountEventProvider::EventPublish(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGIN);
|
||||
if (errCode != true) {
|
||||
ACCOUNT_LOGE("publish account login event failed");
|
||||
ReportPublishFailureEvent(errCode, oldStatus);
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LoginOhosAccount success");
|
||||
return true;
|
||||
}
|
||||
@ -183,6 +194,7 @@ bool OhosAccountManager::LoginOhosAccount(const std::string &name, const std::st
|
||||
bool OhosAccountManager::LogoutOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
std::int32_t oldStatus = currentAccount_.ohosAccountStatus_;
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoutOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
@ -192,6 +204,12 @@ bool OhosAccountManager::LogoutOhosAccount(const std::string &name, const std::s
|
||||
ret = ClearAccount(); // clear account info with ACCOUNT_STATE_LOGOUT
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoutOhosAccount: ClearAccount failed");
|
||||
return false;
|
||||
}
|
||||
bool errCode = AccountEventProvider::EventPublish(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOUT);
|
||||
if (errCode != true) {
|
||||
ACCOUNT_LOGE("publish account logout event failed");
|
||||
ReportPublishFailureEvent(errCode, oldStatus);
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LogoutOhosAccount success");
|
||||
@ -209,6 +227,7 @@ bool OhosAccountManager::LogoutOhosAccount(const std::string &name, const std::s
|
||||
bool OhosAccountManager::LogoffOhosAccount(const std::string &name, const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
std::int32_t oldStatus = currentAccount_.ohosAccountStatus_;
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoffOhosAccount: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
@ -218,6 +237,12 @@ bool OhosAccountManager::LogoffOhosAccount(const std::string &name, const std::s
|
||||
ret = ClearAccount(ACCOUNT_STATE_LOGOFF); // clear account info with ACCOUNT_STATE_LOGOFF
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("LogoffOhosAccount: ClearAccount failed");
|
||||
return false;
|
||||
}
|
||||
bool errCode = AccountEventProvider::EventPublish(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOFF);
|
||||
if (errCode != true) {
|
||||
ACCOUNT_LOGE("publish account logoff event failed");
|
||||
ReportPublishFailureEvent(errCode, oldStatus);
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("LogoffOhosAccount success");
|
||||
@ -236,6 +261,7 @@ bool OhosAccountManager::HandleOhosAccountTokenInvalidEvent(const std::string &n
|
||||
const std::string &uid, const std::string &eventStr)
|
||||
{
|
||||
std::lock_guard<std::mutex> mutexLock(mgrMutex_);
|
||||
std::int32_t oldStatus = currentAccount_.ohosAccountStatus_;
|
||||
bool ret = HandleEvent(eventStr); // update account status
|
||||
if (!ret) {
|
||||
ACCOUNT_LOGE("HandleOhosAccountTokenInvalidEvent: HandleEvent %{public}s failed", eventStr.c_str());
|
||||
@ -248,6 +274,12 @@ bool OhosAccountManager::HandleOhosAccountTokenInvalidEvent(const std::string &n
|
||||
if (!ret) {
|
||||
// moving on even if failed to update account info
|
||||
ACCOUNT_LOGW("Handle TokenInvalid event: SetAccount failed");
|
||||
}
|
||||
bool errCode = AccountEventProvider::EventPublish(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_TOKEN_INVALID);
|
||||
if (errCode != true) {
|
||||
ACCOUNT_LOGE("publish account token invalid event failed");
|
||||
ReportPublishFailureEvent(errCode, oldStatus);
|
||||
return false;
|
||||
}
|
||||
ACCOUNT_LOGI("HandleOhosAccountTokenInvalidEvent success");
|
||||
return true;
|
||||
|
@ -34,6 +34,7 @@ group("unittest") {
|
||||
|
||||
deps = [
|
||||
"unittest/account_dump_helper_test:unittest",
|
||||
"unittest/account_event_provider_test:unittest",
|
||||
"unittest/account_mgr_service_test:unittest",
|
||||
"unittest/account_mgr_stub_test:unittest",
|
||||
"unittest/ohos_account_data_deal_test:unittest",
|
||||
|
@ -38,6 +38,7 @@ ohos_unittest("AccountDumpHelperTest") {
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_event_provider.cpp",
|
||||
"${services_path}/accountmgr/src/account_helper_data.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
"${services_path}/accountmgr/src/ohos_account_data_deal.cpp",
|
||||
@ -59,7 +60,10 @@ ohos_unittest("AccountDumpHelperTest") {
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"ces_standard:cesfwk_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "account_error_no.h"
|
||||
#include "account_info.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "account_event_provider.h"
|
||||
#include "ohos_account_manager.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
77
services/accountmgr/test/unittest/account_event_provider_test/BUILD.gn
Executable file
77
services/accountmgr/test/unittest/account_event_provider_test/BUILD.gn
Executable file
@ -0,0 +1,77 @@
|
||||
# Copyright (c) 2021 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.
|
||||
|
||||
import("//base/account/os_account/os_account.gni")
|
||||
import("//build/ohos.gni")
|
||||
import("//build/test.gni")
|
||||
|
||||
module_output_path = "os_account_standard/accountmgrservice"
|
||||
|
||||
config("accountmgr_event_provider_test_config") {
|
||||
include_dirs = [
|
||||
"./include",
|
||||
"${common_path}/log/include",
|
||||
"${common_path}/perf_stat/include",
|
||||
"${common_path}/account_error/include",
|
||||
"${services_path}/accountmgr/include",
|
||||
"${innerkits_path}/include",
|
||||
"//third_party/json/include",
|
||||
"//utils/native/base/include",
|
||||
"//utils/system/safwk/native/include",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_unittest("AccountEventProviderTest") {
|
||||
module_out_path = module_output_path
|
||||
|
||||
sources = [
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${services_path}/accountmgr/src/account_event_provider.cpp",
|
||||
]
|
||||
sources += [ "account_event_provider_test.cpp" ]
|
||||
|
||||
configs = [
|
||||
":accountmgr_event_provider_test_config",
|
||||
"${services_path}/accountmgr/test:accountmgr_test_config",
|
||||
]
|
||||
|
||||
deps = [
|
||||
"//third_party/googletest:gmock_main",
|
||||
"//third_party/googletest:gtest_main",
|
||||
"//utils/native/base:utils",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"aafwk_standard:base",
|
||||
"aafwk_standard:intent",
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"ces_standard:cesfwk_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
"permission_standard:libpermissionsdk_standard",
|
||||
"safwk:system_ability_fwk",
|
||||
"samgr_L2:samgr_proxy",
|
||||
"startup_l2:syspara",
|
||||
]
|
||||
part_name = "os_account_standard"
|
||||
}
|
||||
|
||||
group("unittest") {
|
||||
testonly = true
|
||||
|
||||
deps = [ ":AccountEventProviderTest" ]
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (c) 2021 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 <gmock/gmock.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "account_event_provider.h"
|
||||
#include "account_error_no.h"
|
||||
#include "account_log_wrapper.h"
|
||||
#include "common_event_manager.h"
|
||||
#include <common_event_support.h>
|
||||
|
||||
using namespace testing::ext;
|
||||
using namespace OHOS;
|
||||
using namespace OHOS::AccountSA;
|
||||
using namespace OHOS::EventFwk;
|
||||
|
||||
class AccountEventProviderTest : public testing::Test {
|
||||
public:
|
||||
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
|
||||
void AccountEventProviderTest::SetUpTestCase() {}
|
||||
|
||||
void AccountEventProviderTest::TearDownTestCase() {}
|
||||
|
||||
void AccountEventProviderTest::SetUp(){}
|
||||
|
||||
void AccountEventProviderTest::TearDown() {}
|
||||
|
||||
/**
|
||||
* @tc.name: AccountEventProviderTest001
|
||||
* @tc.desc: Test account EventPublish interface
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: #I40129
|
||||
*/
|
||||
HWTEST_F(AccountEventProviderTest, AccountEventProviderTest001, TestSize.Level0)
|
||||
{
|
||||
bool ret = AccountEventProvider::EventPublish(EventFwk::CommonEventSupport::COMMON_EVENT_HWID_LOGOFF);
|
||||
EXPECT_EQ(true, ret);
|
||||
}
|
@ -39,6 +39,7 @@ ohos_unittest("account_mgr_test") {
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${innerkits_path}/accountmgr/src/account_proxy.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_event_provider.cpp",
|
||||
"${services_path}/accountmgr/src/account_helper_data.cpp",
|
||||
"${services_path}/accountmgr/src/account_mgr_service.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
@ -70,6 +71,8 @@ ohos_unittest("account_mgr_test") {
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"ces_standard:cesfwk_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
@ -40,6 +40,7 @@ ohos_unittest("AccountSAMgrStubTest") {
|
||||
"${common_path}/log/src/account_log_wrapper.cpp",
|
||||
"${common_path}/perf_stat/src/perf_stat.cpp",
|
||||
"${services_path}/accountmgr/src/account_dump_helper.cpp",
|
||||
"${services_path}/accountmgr/src/account_event_provider.cpp",
|
||||
"${services_path}/accountmgr/src/account_helper_data.cpp",
|
||||
"${services_path}/accountmgr/src/account_mgr_service.cpp",
|
||||
"${services_path}/accountmgr/src/account_state_machine.cpp",
|
||||
@ -68,6 +69,8 @@ ohos_unittest("AccountSAMgrStubTest") {
|
||||
"aafwk_standard:want",
|
||||
"appexecfwk_standard:appexecfwk_base",
|
||||
"appexecfwk_standard:appexecfwk_core",
|
||||
"ces_standard:cesfwk_core",
|
||||
"ces_standard:cesfwk_innerkits",
|
||||
"hisysevent_native:libhisysevent",
|
||||
"hiviewdfx_hilog_native:libhilog",
|
||||
"ipc:ipc_core",
|
||||
|
Loading…
Reference in New Issue
Block a user