1 /*
2 * Copyright (c) 2021-2022 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_meter.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)36 bool AccountEventProvider::EventPublish(const std::string& event, int32_t userId)
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 want.SetParam("userId", userId);
44 } else {
45 data.SetCode(userId);
46 }
47 data.SetWant(want);
48 StartTrace(HITRACE_TAG_ACCOUNT_MANAGER, "Ohos account event publish.");
49 /* publish */
50 if (!CommonEventManager::PublishCommonEvent(data)) {
51 ACCOUNT_LOGE("PublishCommonEvent failed! event %{public}s. userId is %{public}d", event.c_str(), userId);
52 ReportOhosAccountOperationFail(userId, EVENT_PUBLISH, false, "PublishCommonEvent failed");
53 return false;
54 } else {
55 ACCOUNT_LOGI("PublishCommonEvent succeed! event %{public}s.", event.c_str());
56 }
57 FinishTrace(HITRACE_TAG_ACCOUNT_MANAGER);
58 #else // HAS_CES_PART
59 ACCOUNT_LOGI("No common event part, do not publish anything! event %{public}s.", event.c_str());
60 #endif // HAS_CES_PART
61 return true;
62 }
63 } // namespace AccountSA
64 } // namespace OHOS