1 /*
2 * Copyright (c) 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_subscriber.h"
17
18 #include "common_event_support.h"
19 #include "hc_log.h"
20 #include "want.h"
21
22 namespace OHOS {
23 namespace DevAuth {
AccountSubscriber(const EventFwk::CommonEventSubscribeInfo & subscriberInfo,const OsAccountEventNotifier & notifier)24 AccountSubscriber::AccountSubscriber(const EventFwk::CommonEventSubscribeInfo &subscriberInfo,
25 const OsAccountEventNotifier ¬ifier)
26 : EventFwk::CommonEventSubscriber(subscriberInfo), notifier_(notifier)
27 {}
28
OnReceiveEvent(const EventFwk::CommonEventData & eventData)29 void AccountSubscriber::OnReceiveEvent(const EventFwk::CommonEventData &eventData)
30 {
31 const OHOS::AAFwk::Want& want = eventData.GetWant();
32 std::string action = want.GetAction();
33 int32_t userId = eventData.GetCode();
34 LOGI("[AccountSubscriber]: OnReceiveEvent action: %s, userId: %d.", action.c_str(), userId);
35
36 if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_UNLOCKED) {
37 notifier_.notifyOsAccountUnlocked(userId);
38 } else if (action == EventFwk::CommonEventSupport::COMMON_EVENT_USER_REMOVED) {
39 notifier_.notifyOsAccountRemoved(userId);
40 } else {
41 LOGE("[AccountSubscriber]: OnReceiveEvent invalid action!");
42 }
43 }
44 } // namespace DevAuth
45 } // namespace OHOS
46