1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "account_event_provider.h"
17 #include "account_info.h"
18 #ifdef HAS_CES_PART
19 #include <common_event_data.h>
20 #include <common_event_support.h>
21 #endif // HAS_CES_PART
22 #include "account_log_wrapper.h"
23 #ifdef HAS_CES_PART
24 #include "common_event_manager.h"
25 #include "want.h"
26 #endif // HAS_CES_PART
27 #include "hisysevent_adapter.h"
28 #include "hitrace_adapter.h"
29
30 #ifdef HAS_CES_PART
31 using namespace OHOS::EventFwk;
32 #endif // HAS_CES_PART
33
34 namespace OHOS {
35 namespace AccountSA {
EventPublish(const std::string & event,int32_t userId,const DomainAccountEventData * report)36 bool AccountEventProvider::EventPublish(const std::string& event, int32_t userId, const DomainAccountEventData *report)
37 {
38 #ifdef HAS_CES_PART
39 Want want;
40 want.SetAction(event);
41 CommonEventData data;
42 if (event == EventFwk::CommonEventSupport::COMMON_EVENT_USER_INFO_UPDATED) {
43 data.SetCode(userId);
44 } else if (event == EventFwk::CommonEventSupport::COMMON_EVENT_DOMAIN_ACCOUNT_STATUS_CHANGED) {
45 if (report == nullptr) {
46 ACCOUNT_LOGE("Report is nullptr");
47 return false;
48 }
49 want.SetParam("domain", report->domainAccountInfo.domain_);
50 want.SetParam("accountName", report->domainAccountInfo.accountName_);
51 want.SetParam("event", report->event);
52 want.SetParam("status", report->status);
53 } else {
54 want.SetParam("userId", userId);
55 }
56
57 data.SetWant(want);
58 StartTraceAdapter("Ohos account event publish.");
59 /* publish */
60 if (!CommonEventManager::PublishCommonEvent(data)) {
61 ACCOUNT_LOGE("PublishCommonEvent failed! event %{public}s. userId is %{public}d", event.c_str(), userId);
62 ReportOhosAccountOperationFail(userId, EVENT_PUBLISH, false, "PublishCommonEvent failed");
63 return false;
64 } else {
65 ACCOUNT_LOGI("PublishCommonEvent succeed! event %{public}s.", event.c_str());
66 }
67 FinishTraceAdapter();
68 #else // HAS_CES_PART
69 ACCOUNT_LOGI("No common event part, do not publish anything! event %{public}s.", event.c_str());
70 #endif // HAS_CES_PART
71 return true;
72 }
73 } // namespace AccountSA
74 } // namespace OHOS