• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "cellular_data_service_stub.h"
17 
18 #include <string_ex.h>
19 
20 #include "ipc_skeleton.h"
21 
22 #include "telephony_errors.h"
23 #include "telephony_log_wrapper.h"
24 
25 #include "cellular_data_controller.h"
26 #include "cellular_data_service.h"
27 
28 namespace OHOS {
29 namespace Telephony {
30 CellularDataServiceStub::CellularDataServiceStub() = default;
31 
32 CellularDataServiceStub::~CellularDataServiceStub() = default;
33 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)34 int32_t CellularDataServiceStub::OnRemoteRequest(
35     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
36 {
37     std::u16string myDescriptor = CellularDataServiceStub::GetDescriptor();
38     std::u16string remoteDescriptor = data.ReadInterfaceToken();
39     // NetManager has no transport description
40     if (myDescriptor != remoteDescriptor) {
41         TELEPHONY_LOGE("descriptor check fail!");
42         return TELEPHONY_ERR_DESCRIPTOR_MISMATCH;
43     }
44     std::map<uint32_t, Fun>::iterator it = eventIdFunMap_.find(code);
45     if (it != eventIdFunMap_.end()) {
46         return (this->*(it->second))(data, reply);
47     } else {
48         TELEPHONY_LOGE("event code is not exist");
49     }
50     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
51 }
52 
OnIsCellularDataEnabled(MessageParcel & data,MessageParcel & reply)53 int32_t CellularDataServiceStub::OnIsCellularDataEnabled(MessageParcel &data, MessageParcel &reply)
54 {
55     int32_t result = IsCellularDataEnabled();
56     if (!reply.WriteInt32(result)) {
57         TELEPHONY_LOGE("fail to write parcel");
58         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
59     }
60     return result;
61 }
62 
OnEnableCellularData(MessageParcel & data,MessageParcel & reply)63 int32_t CellularDataServiceStub::OnEnableCellularData(MessageParcel &data, MessageParcel &reply)
64 {
65     bool enable = data.ReadBool();
66     int32_t result = EnableCellularData(enable);
67     if (!reply.WriteInt32(result)) {
68         TELEPHONY_LOGE("fail to write parcel");
69         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
70     }
71     return result;
72 }
73 
OnGetCellularDataState(MessageParcel & data,MessageParcel & reply)74 int32_t CellularDataServiceStub::OnGetCellularDataState(MessageParcel &data, MessageParcel &reply)
75 {
76     int32_t result = GetCellularDataState();
77     if (!reply.WriteInt32(result)) {
78         TELEPHONY_LOGE("fail to write parcel");
79         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
80     }
81     return result;
82 }
83 
OnIsCellularDataRoamingEnabled(MessageParcel & data,MessageParcel & reply)84 int32_t CellularDataServiceStub::OnIsCellularDataRoamingEnabled(MessageParcel &data, MessageParcel &reply)
85 {
86     int32_t slotId = data.ReadInt32();
87     int32_t result = IsCellularDataRoamingEnabled(slotId);
88     if (!reply.WriteInt32(result)) {
89         TELEPHONY_LOGE("fail to write parcel");
90         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
91     }
92     return (int32_t)result;
93 }
94 
OnEnableCellularDataRoaming(MessageParcel & data,MessageParcel & reply)95 int32_t CellularDataServiceStub::OnEnableCellularDataRoaming(MessageParcel &data, MessageParcel &reply)
96 {
97     int32_t slotId = data.ReadInt32();
98     bool enable = data.ReadBool();
99     int32_t result = EnableCellularDataRoaming(slotId, enable);
100     if (!reply.WriteInt32(result)) {
101         TELEPHONY_LOGE("fail to write parcel");
102         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
103     }
104     return result;
105 }
106 
OnHandleApnChanged(MessageParcel & data,MessageParcel & reply)107 int32_t CellularDataServiceStub::OnHandleApnChanged(MessageParcel &data, MessageParcel &reply)
108 {
109     int32_t slotId = data.ReadInt32();
110     int32_t result = HandleApnChanged(slotId);
111     if (!reply.WriteInt32(result)) {
112         TELEPHONY_LOGE("fail to write parcel");
113         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
114     }
115     return result;
116 }
117 
OnGetDefaultCellularDataSlotId(MessageParcel & data,MessageParcel & reply)118 int32_t CellularDataServiceStub::OnGetDefaultCellularDataSlotId(MessageParcel &data, MessageParcel &reply)
119 {
120     int32_t result = GetDefaultCellularDataSlotId();
121     if (!reply.WriteInt32(result)) {
122         TELEPHONY_LOGE("fail to write parcel");
123         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
124     }
125     return result;
126 }
127 
OnSetDefaultCellularDataSlotId(MessageParcel & data,MessageParcel & reply)128 int32_t CellularDataServiceStub::OnSetDefaultCellularDataSlotId(MessageParcel &data, MessageParcel &reply)
129 {
130     int32_t slotId = data.ReadInt32();
131     int32_t result = SetDefaultCellularDataSlotId(slotId);
132     if (!reply.WriteInt32(result)) {
133         TELEPHONY_LOGE("fail to write parcel");
134         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
135     }
136     return result;
137 }
138 
OnGetCellularDataFlowType(MessageParcel & data,MessageParcel & reply)139 int32_t CellularDataServiceStub::OnGetCellularDataFlowType(MessageParcel &data, MessageParcel &reply)
140 {
141     int32_t result = GetCellularDataFlowType();
142     if (!reply.WriteInt32(result)) {
143         TELEPHONY_LOGE("fail to write parcel");
144         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
145     }
146     return result;
147 }
148 
OnHasInternetCapability(MessageParcel & data,MessageParcel & reply)149 int32_t CellularDataServiceStub::OnHasInternetCapability(MessageParcel &data, MessageParcel &reply)
150 {
151     int32_t slotId = data.ReadInt32();
152     int32_t cid = data.ReadInt32();
153     int32_t result = HasInternetCapability(slotId, cid);
154     if (!reply.WriteInt32(result)) {
155         TELEPHONY_LOGE("fail to write parcel");
156         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
157     }
158     return result;
159 }
160 
OnClearCellularDataConnections(MessageParcel & data,MessageParcel & reply)161 int32_t CellularDataServiceStub::OnClearCellularDataConnections(MessageParcel &data, MessageParcel &reply)
162 {
163     int32_t slotId = data.ReadInt32();
164     int32_t result = ClearCellularDataConnections(slotId);
165     if (!reply.WriteInt32(result)) {
166         TELEPHONY_LOGE("fail to write parcel");
167         return TELEPHONY_ERR_WRITE_REPLY_FAIL;
168     }
169     return result;
170 }
171 } // namespace Telephony
172 } // namespace OHOS