1/*
2 * Copyright (C) 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 "sms_state_handler.h"
17
18#include "sms_state_observer.h"
19#include "string_utils.h"
20#include "telephony_log_wrapper.h"
21
22namespace OHOS {
23namespace Telephony {
24bool SmsStateHandler::UnRegisterHandler()
25{
26    TELEPHONY_LOGI("SmsStateHandler::UnRegisterHandler entry");
27    if (smsStateObserver_ == nullptr) {
28        TELEPHONY_LOGE("SmsStateHandler::UnRegisterHandler smsStateObserver_ is null.");
29        return false;
30    }
31    smsStateObserver_->StopEventSubscriber();
32    return true;
33}
34
35bool SmsStateHandler::RegisterHandler()
36{
37    smsStateObserver_ = std::make_shared<SmsStateObserver>();
38    if (smsStateObserver_ == nullptr) {
39        TELEPHONY_LOGE("SmsStateHandler::RegisteHandler smsStateObserver_ is null.");
40        return false;
41    }
42    smsStateObserver_->StartEventSubscriber();
43    return true;
44}
45
46void SmsStateHandler::Init()
47{
48    TELEPHONY_LOGI("SmsStateHandler init");
49    if (!RegisterHandler()) {
50        TELEPHONY_LOGE("SmsStateHandler::Init register handle fail.");
51    }
52}
53
54void SmsStateHandler::UnInit()
55{
56    TELEPHONY_LOGI("SmsStateHandler UnInit");
57    if (!UnRegisterHandler()) {
58        TELEPHONY_LOGE("SmsStateHandler::UnInit unregister handle fail.");
59    }
60}
61} // namespace Telephony
62} // namespace OHOS
63