1 //
2 // Copyright (C) 2016 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/binder/manager_binder_adaptor.h"
18 
19 #include <binder/Status.h>
20 #include <binderwrapper/binder_wrapper.h>
21 #include <utils/String16.h>
22 #include <utils/String8.h>
23 
24 #include "shill/logging.h"
25 #include "shill/manager.h"
26 
27 using android::binder::Status;
28 using android::BinderWrapper;
29 using android::IBinder;
30 using android::sp;
31 using android::String16;
32 using android::String8;
33 using android::system::connectivity::shill::IPropertyChangedCallback;
34 using std::string;
35 using std::vector;
36 
37 namespace shill {
38 
39 namespace Logging {
40 static auto kModuleLogScope = ScopeLogger::kBinder;
ObjectID(ManagerBinderAdaptor * m)41 static string ObjectID(ManagerBinderAdaptor* m) {
42   return "Manager binder adaptor (id " + m->GetRpcIdentifier() + ")";
43 }
44 }  // namespace Logging
45 
ManagerBinderAdaptor(Manager * manager,const std::string & id)46 ManagerBinderAdaptor::ManagerBinderAdaptor(Manager* manager,
47                                            const std::string& id)
48     : BinderAdaptor(id), manager_(manager) {}
49 
~ManagerBinderAdaptor()50 ManagerBinderAdaptor::~ManagerBinderAdaptor() { manager_ = nullptr; }
51 
RegisterAsync(const base::Callback<void (bool)> &)52 void ManagerBinderAdaptor::RegisterAsync(
53     const base::Callback<void(bool)>& /*completion_callback*/) {
54   // Registration is performed synchronously in Binder.
55   BinderWrapper::Get()->RegisterService(
56       String8(getInterfaceDescriptor()).string(), this);
57 }
58 
EmitBoolChanged(const string & name,bool)59 void ManagerBinderAdaptor::EmitBoolChanged(const string& name, bool /*value*/) {
60   SLOG(this, 2) << __func__ << ": " << name;
61   SendPropertyChangedSignal(name);
62 }
63 
EmitUintChanged(const string & name,uint32_t)64 void ManagerBinderAdaptor::EmitUintChanged(const string& name,
65                                            uint32_t /*value*/) {
66   SLOG(this, 2) << __func__ << ": " << name;
67   SendPropertyChangedSignal(name);
68 }
69 
EmitIntChanged(const string & name,int)70 void ManagerBinderAdaptor::EmitIntChanged(const string& name, int /*value*/) {
71   SLOG(this, 2) << __func__ << ": " << name;
72   SendPropertyChangedSignal(name);
73 }
74 
EmitStringChanged(const string & name,const string &)75 void ManagerBinderAdaptor::EmitStringChanged(const string& name,
76                                              const string& /*value*/) {
77   SLOG(this, 2) << __func__ << ": " << name;
78   SendPropertyChangedSignal(name);
79 }
80 
EmitStringsChanged(const string & name,const vector<string> &)81 void ManagerBinderAdaptor::EmitStringsChanged(const string& name,
82                                               const vector<string>& /*value*/) {
83   SLOG(this, 2) << __func__ << ": " << name;
84   SendPropertyChangedSignal(name);
85 }
86 
EmitRpcIdentifierChanged(const string & name,const string &)87 void ManagerBinderAdaptor::EmitRpcIdentifierChanged(const string& name,
88                                                     const string& /*value*/) {
89   SLOG(this, 2) << __func__ << ": " << name;
90   SendPropertyChangedSignal(name);
91 }
92 
EmitRpcIdentifierArrayChanged(const string & name,const vector<string> &)93 void ManagerBinderAdaptor::EmitRpcIdentifierArrayChanged(
94     const string& name, const vector<string>& /*value*/) {
95   SLOG(this, 2) << __func__ << ": " << name;
96   SendPropertyChangedSignal(name);
97 }
98 
SetupApModeInterface(String16 * _aidl_return)99 Status ManagerBinderAdaptor::SetupApModeInterface(String16* _aidl_return) {
100   // STUB IMPLEMENTATION.
101   return Status::ok();
102 }
103 
SetupStationModeInterface(String16 * _aidl_return)104 Status ManagerBinderAdaptor::SetupStationModeInterface(String16* _aidl_return) {
105   // STUB IMPLEMENTATION.
106   // TODO(samueltan): replace this with proper implementation.
107   return Status::ok();
108 }
109 
ClaimInterface(const String16 & claimer_name,const String16 & interface_name)110 Status ManagerBinderAdaptor::ClaimInterface(const String16& claimer_name,
111                                             const String16& interface_name) {
112   // STUB IMPLEMENTATION.
113   // TODO(samueltan): replace this with proper implementation.
114   return Status::ok();
115 }
116 
ReleaseInterface(const String16 & claimer_name,const String16 & interface_name)117 Status ManagerBinderAdaptor::ReleaseInterface(const String16& claimer_name,
118                                               const String16& interface_name) {
119   // STUB IMPLEMENTATION.
120   // TODO(samueltan): replace this with proper implementation.
121   return Status::ok();
122 }
123 
ConfigureService(const android::os::PersistableBundle & properties,sp<IBinder> * _aidl_return)124 Status ManagerBinderAdaptor::ConfigureService(
125     const android::os::PersistableBundle& properties,
126     sp<IBinder>* _aidl_return) {
127   // STUB IMPLEMENTATION.
128   // TODO(samueltan): replace this with proper implementation.
129   return Status::ok();
130 }
131 
RequestScan(int32_t type)132 Status ManagerBinderAdaptor::RequestScan(int32_t type) {
133   // STUB IMPLEMENTATION.
134   // TODO(samueltan): replace this with proper implementation.
135   return Status::ok();
136 }
137 
GetDevices(vector<sp<IBinder>> * _aidl_return)138 Status ManagerBinderAdaptor::GetDevices(vector<sp<IBinder>>* _aidl_return) {
139   // STUB IMPLEMENTATION.
140   // TODO(samueltan): replace this with proper implementation.
141   return Status::ok();
142 }
143 
RegisterPropertyChangedSignalHandler(const sp<IPropertyChangedCallback> & callback)144 Status ManagerBinderAdaptor::RegisterPropertyChangedSignalHandler(
145     const sp<IPropertyChangedCallback>& callback) {
146   AddPropertyChangedSignalHandler(callback);
147   return Status::ok();
148 }
149 
150 }  // namespace shill
151