1 //
2 // Copyright (C) 2014 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #include "shill/cellular/mobile_operator_info.h"
18
19 #include <sstream>
20
21 #include "shill/cellular/mobile_operator_info_impl.h"
22 #include "shill/logging.h"
23
24 namespace shill {
25
26 using base::FilePath;
27 using std::string;
28 using std::stringstream;
29 using std::vector;
30
31 namespace Logging {
32 static auto kModuleLogScope = ScopeLogger::kCellular;
ObjectID(const MobileOperatorInfo * m)33 static string ObjectID(const MobileOperatorInfo* m) {
34 return "(mobile_operator_info)";
35 }
36 }
37
38 // /////////////////////////////////////////////////////////////////////////////
39 // MobileOperatorInfo implementation note:
40 // MobileOperatorInfo simply forwards all operations to |impl_|.
41 // It also logs the functions/arguments/results at sane log levels. So the
42 // implementation need not leave a trace itself.
43
MobileOperatorInfo(EventDispatcher * dispatcher,const string & info_owner)44 MobileOperatorInfo::MobileOperatorInfo(EventDispatcher* dispatcher,
45 const string& info_owner)
46 : impl_(new MobileOperatorInfoImpl(dispatcher, info_owner)) {}
47
~MobileOperatorInfo()48 MobileOperatorInfo::~MobileOperatorInfo() {}
49
GetLogPrefix(const char * func) const50 string MobileOperatorInfo::GetLogPrefix(const char* func) const {
51 return impl_->info_owner() + ": " + func;
52 }
53
ClearDatabasePaths()54 void MobileOperatorInfo::ClearDatabasePaths() {
55 SLOG(this, 3) << GetLogPrefix(__func__);
56 impl_->ClearDatabasePaths();
57 }
58
AddDatabasePath(const FilePath & absolute_path)59 void MobileOperatorInfo::AddDatabasePath(const FilePath& absolute_path) {
60 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << absolute_path.value()
61 << ")";
62 impl_->AddDatabasePath(absolute_path);
63 }
64
Init()65 bool MobileOperatorInfo::Init() {
66 auto result = impl_->Init();
67 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
68 return result;
69 }
70
AddObserver(MobileOperatorInfo::Observer * observer)71 void MobileOperatorInfo::AddObserver(MobileOperatorInfo::Observer* observer) {
72 SLOG(this, 3) << GetLogPrefix(__func__);
73 impl_->AddObserver(observer);
74 }
75
RemoveObserver(MobileOperatorInfo::Observer * observer)76 void MobileOperatorInfo::RemoveObserver(
77 MobileOperatorInfo::Observer* observer) {
78 SLOG(this, 3) << GetLogPrefix(__func__);
79 impl_->RemoveObserver(observer);
80 }
81
IsMobileNetworkOperatorKnown() const82 bool MobileOperatorInfo::IsMobileNetworkOperatorKnown() const {
83 auto result = impl_->IsMobileNetworkOperatorKnown();
84 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
85 return result;
86 }
87
IsMobileVirtualNetworkOperatorKnown() const88 bool MobileOperatorInfo::IsMobileVirtualNetworkOperatorKnown() const {
89 auto result = impl_->IsMobileVirtualNetworkOperatorKnown();
90 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
91 return result;
92 }
93
uuid() const94 const string& MobileOperatorInfo::uuid() const {
95 const auto& result = impl_->uuid();
96 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
97 return result;
98 }
99
operator_name() const100 const string& MobileOperatorInfo::operator_name() const {
101 const auto& result = impl_->operator_name();
102 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
103 return result;
104 }
105
country() const106 const string& MobileOperatorInfo::country() const {
107 const auto& result = impl_->country();
108 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
109 return result;
110 }
111
mccmnc() const112 const string& MobileOperatorInfo::mccmnc() const {
113 const auto& result = impl_->mccmnc();
114 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
115 return result;
116 }
117
sid() const118 const string& MobileOperatorInfo::sid() const {
119 const auto& result = impl_->sid();
120 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
121 return result;
122 }
123
nid() const124 const string& MobileOperatorInfo::nid() const {
125 const auto& result = impl_->nid();
126 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
127 return result;
128 }
129
mccmnc_list() const130 const vector<string>& MobileOperatorInfo::mccmnc_list() const {
131 const auto& result = impl_->mccmnc_list();
132 if (SLOG_IS_ON(Cellular, 3)) {
133 stringstream pp_result;
134 for (const auto& mccmnc : result) {
135 pp_result << mccmnc << " ";
136 }
137 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result["
138 << pp_result.str() << "]";
139 }
140 return result;
141 }
142
sid_list() const143 const vector<string>& MobileOperatorInfo::sid_list() const {
144 const auto& result = impl_->sid_list();
145 if (SLOG_IS_ON(Cellular, 3)) {
146 stringstream pp_result;
147 for (const auto& sid : result) {
148 pp_result << sid << " ";
149 }
150 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result["
151 << pp_result.str() << "]";
152 }
153 return result;
154 }
155
156 const vector<MobileOperatorInfo::LocalizedName> &
operator_name_list() const157 MobileOperatorInfo::operator_name_list() const {
158 const auto& result = impl_->operator_name_list();
159 if (SLOG_IS_ON(Cellular, 3)) {
160 stringstream pp_result;
161 for (const auto& operator_name : result) {
162 pp_result << "(" << operator_name.name << ", " << operator_name.language
163 << ") ";
164 }
165 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result["
166 << pp_result.str() << "]";
167 }
168 return result;
169 }
170
171 const ScopedVector<MobileOperatorInfo::MobileAPN> &
apn_list() const172 MobileOperatorInfo::apn_list() const {
173 const auto& result = impl_->apn_list();
174 if (SLOG_IS_ON(Cellular, 3)) {
175 stringstream pp_result;
176 for (const auto& mobile_apn : result) {
177 pp_result << "(apn: " << mobile_apn->apn
178 << ", username: " << mobile_apn->username
179 << ", password: " << mobile_apn->password;
180 pp_result << ", operator_name_list: '";
181 for (const auto& operator_name : mobile_apn->operator_name_list) {
182 pp_result << "(" << operator_name.name << ", " << operator_name.language
183 << ") ";
184 }
185 pp_result << "') ";
186 }
187 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result["
188 << pp_result.str() << "]";
189 }
190 return result;
191 }
192
olp_list() const193 const vector<MobileOperatorInfo::OnlinePortal>& MobileOperatorInfo::olp_list()
194 const {
195 const auto& result = impl_->olp_list();
196 if (SLOG_IS_ON(Cellular, 3)) {
197 stringstream pp_result;
198 for (const auto& olp : result) {
199 pp_result << "(url: " << olp.url << ", method: " << olp.method
200 << ", post_data: " << olp.post_data << ") ";
201 }
202 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result["
203 << pp_result.str() << "]";
204 }
205 return result;
206 }
207
activation_code() const208 const string& MobileOperatorInfo::activation_code() const {
209 const auto& result = impl_->activation_code();
210 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
211 return result;
212 }
213
requires_roaming() const214 bool MobileOperatorInfo::requires_roaming() const {
215 auto result = impl_->requires_roaming();
216 SLOG(this, 3) << GetLogPrefix(__func__) << ": Result[" << result << "]";
217 return result;
218 }
219
UpdateIMSI(const string & imsi)220 void MobileOperatorInfo::UpdateIMSI(const string& imsi) {
221 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << imsi << ")";
222 impl_->UpdateIMSI(imsi);
223 }
224
UpdateICCID(const string & iccid)225 void MobileOperatorInfo::UpdateICCID(const string& iccid) {
226 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << iccid << ")";
227 impl_->UpdateICCID(iccid);
228 }
229
UpdateMCCMNC(const string & mccmnc)230 void MobileOperatorInfo::UpdateMCCMNC(const string& mccmnc) {
231 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << mccmnc << ")";
232 impl_->UpdateMCCMNC(mccmnc);
233 }
234
UpdateSID(const string & sid)235 void MobileOperatorInfo::UpdateSID(const string& sid) {
236 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << sid << ")";
237 impl_->UpdateSID(sid);
238 }
239
UpdateNID(const string & nid)240 void MobileOperatorInfo::UpdateNID(const string& nid) {
241 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << nid << ")";
242 impl_->UpdateNID(nid);
243 }
244
UpdateOperatorName(const string & operator_name)245 void MobileOperatorInfo::UpdateOperatorName(const string& operator_name) {
246 SLOG(this, 3) << GetLogPrefix(__func__) << "(" << operator_name << ")";
247 impl_->UpdateOperatorName(operator_name);
248 }
249
UpdateOnlinePortal(const string & url,const string & method,const string & post_data)250 void MobileOperatorInfo::UpdateOnlinePortal(const string& url,
251 const string& method,
252 const string& post_data) {
253 SLOG(this, 3) << GetLogPrefix(__func__)
254 << "(" << url
255 << ", " << method
256 << ", " << post_data << ")";
257 impl_->UpdateOnlinePortal(url, method, post_data);
258 }
259
Reset()260 void MobileOperatorInfo::Reset() {
261 SLOG(this, 3) << GetLogPrefix(__func__);
262 impl_->Reset();
263 }
264
265 } // namespace shill
266