• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 "publish_event_adapter.h"
17 
18 #include "common_event_manager.h"
19 #include "iam_logger.h"
20 
21 #ifndef LOG_LABEL
22 #define LOG_LABEL UserIam::Common::LABEL_USER_AUTH_SA
23 namespace OHOS {
24 namespace UserIam {
25 namespace UserAuth {
26 namespace {
27 const std::string TAG_SCHEDULEID = "scheduleId";
28 const std::string USER_PIN_CREATED_EVENT = "USER_PIN_CREATED_EVENT";
29 const std::string USER_PIN_DELETED_EVENT = "USER_PIN_DELETED_EVENT";
30 const std::string USER_PIN_UPDATED_EVENT = "USER_PIN_UPDATED_EVENT";
31 
PublishEvent(EventFwk::CommonEventData data)32 void PublishEvent(EventFwk::CommonEventData data)
33 {
34     EventFwk::CommonEventPublishInfo publishInfo;
35     publishInfo.SetSticky(false);
36     if (!EventFwk::CommonEventManager::PublishCommonEvent(data, publishInfo)) {
37         IAM_LOGE("PublishCommonEvent failed, eventAction is %{public}s", data.GetWant().GetAction().c_str());
38         return;
39     }
40     IAM_LOGI("PublishCommonEvent succeed, eventAction is %{public}s", data.GetWant().GetAction().c_str());
41 }
42 } // namespace
43 
PublishDeletedEvent(int32_t userId)44 void PublishEventAdapter::PublishDeletedEvent(int32_t userId)
45 {
46     EventFwk::Want want;
47     want.SetAction(USER_PIN_DELETED_EVENT);
48     EventFwk::CommonEventData data(want);
49     data.SetCode(userId);
50     PublishEvent(data);
51     return;
52 }
53 
PublishCreatedEvent(int32_t userId,uint64_t scheduleId)54 void PublishEventAdapter::PublishCreatedEvent(int32_t userId, uint64_t scheduleId)
55 {
56     if (scheduleId == 0) {
57         IAM_LOGE("Bad Parameter!");
58         return;
59     }
60     EventFwk::Want want;
61     want.SetAction(USER_PIN_CREATED_EVENT);
62     want.SetParam(TAG_SCHEDULEID, std::to_string(scheduleId));
63     EventFwk::CommonEventData data(want);
64     data.SetCode(userId);
65     PublishEvent(data);
66     return;
67 }
68 
PublishUpdatedEvent(int32_t userId,uint64_t scheduleId)69 void PublishEventAdapter::PublishUpdatedEvent(int32_t userId, uint64_t scheduleId)
70 {
71     if (scheduleId == 0) {
72         IAM_LOGE("Bad Parameter!");
73         return;
74     }
75     EventFwk::Want want;
76     want.SetAction(USER_PIN_UPDATED_EVENT);
77     want.SetParam(TAG_SCHEDULEID, std::to_string(scheduleId));
78     EventFwk::CommonEventData data(want);
79     data.SetCode(userId);
80     PublishEvent(data);
81     return;
82 }
83 
84 } // namespace UserAuth
85 } // namespace UserIam
86 } // namespace OHOS
87 #endif