1 //
2 // Copyright (C) 2015 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/dbus/chromeos_mm1_sim_proxy.h"
18
19 #include <memory>
20
21 #include "shill/cellular/cellular_error.h"
22 #include "shill/logging.h"
23
24 using std::string;
25
26 namespace shill {
27
28 namespace Logging {
29 static auto kModuleLogScope = ScopeLogger::kDBus;
ObjectID(const dbus::ObjectPath * p)30 static string ObjectID(const dbus::ObjectPath* p) { return p->value(); }
31 } // namespace Logging
32
33 namespace mm1 {
34
ChromeosSimProxy(const scoped_refptr<dbus::Bus> & bus,const string & path,const string & service)35 ChromeosSimProxy::ChromeosSimProxy(const scoped_refptr<dbus::Bus>& bus,
36 const string& path,
37 const string& service)
38 : proxy_(
39 new org::freedesktop::ModemManager1::SimProxy(
40 bus, service, dbus::ObjectPath(path))) {}
41
~ChromeosSimProxy()42 ChromeosSimProxy::~ChromeosSimProxy() {}
43
44
SendPin(const string & pin,Error * error,const ResultCallback & callback,int timeout)45 void ChromeosSimProxy::SendPin(const string& pin,
46 Error* error,
47 const ResultCallback& callback,
48 int timeout) {
49 // pin is intentionally not logged.
50 SLOG(&proxy_->GetObjectPath(), 2) << __func__;
51 proxy_->SendPinAsync(pin,
52 base::Bind(&ChromeosSimProxy::OnOperationSuccess,
53 weak_factory_.GetWeakPtr(),
54 callback,
55 __func__),
56 base::Bind(&ChromeosSimProxy::OnOperationFailure,
57 weak_factory_.GetWeakPtr(),
58 callback,
59 __func__));
60 }
61
SendPuk(const string & puk,const string & pin,Error * error,const ResultCallback & callback,int timeout)62 void ChromeosSimProxy::SendPuk(const string& puk,
63 const string& pin,
64 Error* error,
65 const ResultCallback& callback,
66 int timeout) {
67 // pin and puk are intentionally not logged.
68 SLOG(&proxy_->GetObjectPath(), 2) << __func__;
69 proxy_->SendPukAsync(puk,
70 pin,
71 base::Bind(&ChromeosSimProxy::OnOperationSuccess,
72 weak_factory_.GetWeakPtr(),
73 callback,
74 __func__),
75 base::Bind(&ChromeosSimProxy::OnOperationFailure,
76 weak_factory_.GetWeakPtr(),
77 callback,
78 __func__));
79 }
80
EnablePin(const string & pin,const bool enabled,Error * error,const ResultCallback & callback,int timeout)81 void ChromeosSimProxy::EnablePin(const string& pin,
82 const bool enabled,
83 Error* error,
84 const ResultCallback& callback,
85 int timeout) {
86 // pin is intentionally not logged.
87 SLOG(&proxy_->GetObjectPath(), 2) << __func__ << ": " << enabled;
88 proxy_->EnablePinAsync(pin,
89 enabled,
90 base::Bind(&ChromeosSimProxy::OnOperationSuccess,
91 weak_factory_.GetWeakPtr(),
92 callback,
93 __func__),
94 base::Bind(&ChromeosSimProxy::OnOperationFailure,
95 weak_factory_.GetWeakPtr(),
96 callback,
97 __func__));
98 }
99
ChangePin(const string & old_pin,const string & new_pin,Error * error,const ResultCallback & callback,int timeout)100 void ChromeosSimProxy::ChangePin(const string& old_pin,
101 const string& new_pin,
102 Error* error,
103 const ResultCallback& callback,
104 int timeout) {
105 // old_pin and new_pin are intentionally not logged.
106 SLOG(&proxy_->GetObjectPath(), 2) << __func__;
107 proxy_->ChangePinAsync(old_pin,
108 new_pin,
109 base::Bind(&ChromeosSimProxy::OnOperationSuccess,
110 weak_factory_.GetWeakPtr(),
111 callback,
112 __func__),
113 base::Bind(&ChromeosSimProxy::OnOperationFailure,
114 weak_factory_.GetWeakPtr(),
115 callback,
116 __func__));
117 }
118
OnOperationSuccess(const ResultCallback & callback,const string & operation)119 void ChromeosSimProxy::OnOperationSuccess(const ResultCallback& callback,
120 const string& operation) {
121 SLOG(&proxy_->GetObjectPath(), 2) << __func__ << ": " << operation;
122 callback.Run(Error());
123 }
124
OnOperationFailure(const ResultCallback & callback,const string & operation,brillo::Error * dbus_error)125 void ChromeosSimProxy::OnOperationFailure(const ResultCallback& callback,
126 const string& operation,
127 brillo::Error* dbus_error) {
128 SLOG(&proxy_->GetObjectPath(), 2) << __func__ << ": " << operation;
129 Error error;
130 CellularError::FromMM1ChromeosDBusError(dbus_error, &error);
131 callback.Run(error);
132 }
133
134 } // namespace mm1
135 } // namespace shill
136