1 /*
2  * Copyright (C) 2021 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 "get_radio_state_callback.h"
17 
18 #include "telephony_log_wrapper.h"
19 
20 namespace OHOS {
21 namespace Telephony {
GetRadioStateCallback(IsRadioOnContext * context)22 GetRadioStateCallback::GetRadioStateCallback(IsRadioOnContext *context) : asyncContext_(context) {}
23 
OnGetRadioStateCallback(const bool isOn,const int32_t errorCode)24 void GetRadioStateCallback::OnGetRadioStateCallback(const bool isOn, const int32_t errorCode)
25 {
26     TELEPHONY_LOGI("OnGetRadioStateCallback isOn = %{public}d", isOn);
27     if (asyncContext_ == nullptr) {
28         TELEPHONY_LOGE("OnGetRadioStateCallback asyncContext null");
29         return;
30     }
31     std::unique_lock<std::mutex> callbackLock(asyncContext_->callbackMutex);
32     asyncContext_->resolved = errorCode == HRIL_ERR_SUCCESS;
33     if (asyncContext_->resolved) {
34         asyncContext_->isRadioOn = isOn;
35     } else {
36         asyncContext_->errorCode = TELEPHONY_ERR_RIL_CMD_FAIL;
37     }
38     asyncContext_->callbackEnd = true;
39     asyncContext_->cv.notify_all();
40     TELEPHONY_LOGI("OnGetRadioStateCallback end");
41 }
42 } // namespace Telephony
43 } // namespace OHOS