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 #include "mms_conn_callback_stub.h"
16
17 #include <condition_variable>
18 #include <memory>
19 #include <mutex>
20
21 #include "core_manager_inner.h"
22 #include "data_request.h"
23 #include "telephony_log_wrapper.h"
24
25 namespace OHOS {
26 namespace Telephony {
27 std::mutex DataRequest::ctx_;
28 bool DataRequest::networkReady_ = false;
29 std::condition_variable DataRequest::cv_;
30
NetAvailable(sptr<NetManagerStandard::NetHandle> & netHandle)31 int32_t MmsConnCallbackStub::NetAvailable(sptr<NetManagerStandard::NetHandle> &netHandle)
32 {
33 TELEPHONY_LOGI("MmsConnCallbackStub::NetAvailable");
34 if (netHandle == nullptr) {
35 TELEPHONY_LOGE("netHandle is nullptr");
36 return TELEPHONY_ERR_FAIL;
37 }
38 SyncNetworkResponse(true);
39 return ERR_NONE;
40 }
41
SyncNetworkResponse(bool netGot)42 void MmsConnCallbackStub::SyncNetworkResponse(bool netGot)
43 {
44 std::unique_lock<std::mutex> lck(DataRequest::ctx_);
45 DataRequest::networkReady_ = netGot;
46 TELEPHONY_LOGI("networkReady_ = %{public}d", DataRequest::networkReady_);
47 }
48
NetCapabilitiesChange(sptr<NetManagerStandard::NetHandle> & netHandle,const sptr<NetManagerStandard::NetAllCapabilities> & netAllCap)49 int32_t MmsConnCallbackStub::NetCapabilitiesChange(
50 sptr<NetManagerStandard::NetHandle> &netHandle, const sptr<NetManagerStandard::NetAllCapabilities> &netAllCap)
51 {
52 TELEPHONY_LOGI("MmsConnCallbackStub::NetCapabilitiesChange");
53 return ERR_NONE;
54 }
55
NetConnectionPropertiesChange(sptr<NetManagerStandard::NetHandle> & netHandle,const sptr<NetManagerStandard::NetLinkInfo> & info)56 int32_t MmsConnCallbackStub::NetConnectionPropertiesChange(
57 sptr<NetManagerStandard::NetHandle> &netHandle, const sptr<NetManagerStandard::NetLinkInfo> &info)
58 {
59 TELEPHONY_LOGI("MmsConnCallbackStub::NetConnectionPropertiesChange");
60 DataRequest::cv_.notify_one();
61 return ERR_NONE;
62 }
63
NetLost(sptr<NetManagerStandard::NetHandle> & netHandle)64 int32_t MmsConnCallbackStub::NetLost(sptr<NetManagerStandard::NetHandle> &netHandle)
65 {
66 TELEPHONY_LOGI("MmsConnCallbackStub::NetLost");
67 return ERR_NONE;
68 }
69
NetUnavailable()70 int32_t MmsConnCallbackStub::NetUnavailable()
71 {
72 SyncNetworkResponse(false);
73 TELEPHONY_LOGI("MmsConnCallbackStub::NetUnavailable");
74 return ERR_NONE;
75 }
76
NetBlockStatusChange(sptr<NetManagerStandard::NetHandle> & netHandle,bool blocked)77 int32_t MmsConnCallbackStub::NetBlockStatusChange(sptr<NetManagerStandard::NetHandle> &netHandle, bool blocked)
78 {
79 TELEPHONY_LOGI("MmsConnCallbackStub::NetBlockStatusChange");
80 return ERR_NONE;
81 }
82 } // namespace Telephony
83 } // namespace OHOS
84