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/device_binder_adaptor.h"
18
19 #include <binder/Status.h>
20 #include <utils/String16.h>
21
22 #include "shill/device.h"
23 #include "shill/logging.h"
24
25 using android::binder::Status;
26 using android::IBinder;
27 using android::sp;
28 using android::String16;
29 using android::system::connectivity::shill::IPropertyChangedCallback;
30 using std::string;
31 using std::vector;
32
33 namespace shill {
34
35 namespace Logging {
36 static auto kModuleLogScope = ScopeLogger::kBinder;
ObjectID(DeviceBinderAdaptor * d)37 static string ObjectID(DeviceBinderAdaptor* d) {
38 return "Device binder adaptor (id " + d->GetRpcIdentifier() + ", " +
39 d->device()->UniqueName() + ")";
40 }
41 } // namespace Logging
42
DeviceBinderAdaptor(Device * device,const string & id)43 DeviceBinderAdaptor::DeviceBinderAdaptor(Device* device, const string& id)
44 : BinderAdaptor(id), device_(device) {}
45
~DeviceBinderAdaptor()46 DeviceBinderAdaptor::~DeviceBinderAdaptor() { device_ = nullptr; }
47
EmitBoolChanged(const string & name,bool)48 void DeviceBinderAdaptor::EmitBoolChanged(const string& name, bool /*value*/) {
49 SLOG(this, 2) << __func__ << ": " << name;
50 SendPropertyChangedSignal(name);
51 }
52
EmitUintChanged(const string & name,uint32_t)53 void DeviceBinderAdaptor::EmitUintChanged(const string& name,
54 uint32_t /*value*/) {
55 SLOG(this, 2) << __func__ << ": " << name;
56 SendPropertyChangedSignal(name);
57 }
58
EmitUint16Changed(const string & name,uint16_t)59 void DeviceBinderAdaptor::EmitUint16Changed(const string& name,
60 uint16_t /*value*/) {
61 SLOG(this, 2) << __func__ << ": " << name;
62 SendPropertyChangedSignal(name);
63 }
64
EmitIntChanged(const string & name,int)65 void DeviceBinderAdaptor::EmitIntChanged(const string& name, int /*value*/) {
66 SLOG(this, 2) << __func__ << ": " << name;
67 SendPropertyChangedSignal(name);
68 }
69
EmitStringChanged(const string & name,const string &)70 void DeviceBinderAdaptor::EmitStringChanged(const string& name,
71 const string& /*value*/) {
72 SLOG(this, 2) << __func__ << ": " << name;
73 SendPropertyChangedSignal(name);
74 }
75
EmitStringmapChanged(const string & name,const Stringmap &)76 void DeviceBinderAdaptor::EmitStringmapChanged(const string& name,
77 const Stringmap& /*value*/) {
78 SLOG(this, 2) << __func__ << ": " << name;
79 SendPropertyChangedSignal(name);
80 }
81
EmitStringmapsChanged(const string & name,const Stringmaps &)82 void DeviceBinderAdaptor::EmitStringmapsChanged(const string& name,
83 const Stringmaps& /*value*/) {
84 SLOG(this, 2) << __func__ << ": " << name;
85 SendPropertyChangedSignal(name);
86 }
87
EmitStringsChanged(const string & name,const Strings &)88 void DeviceBinderAdaptor::EmitStringsChanged(const string& name,
89 const Strings& /*value*/) {
90 SLOG(this, 2) << __func__ << ": " << name;
91 SendPropertyChangedSignal(name);
92 }
93
EmitKeyValueStoreChanged(const string & name,const KeyValueStore &)94 void DeviceBinderAdaptor::EmitKeyValueStoreChanged(
95 const string& name, const KeyValueStore& /*value*/) {
96 SLOG(this, 2) << __func__ << ": " << name;
97 SendPropertyChangedSignal(name);
98 }
99
EmitRpcIdentifierChanged(const std::string & name,const std::string &)100 void DeviceBinderAdaptor::EmitRpcIdentifierChanged(
101 const std::string& name, const std::string& /*value*/) {
102 SLOG(this, 2) << __func__ << ": " << name;
103 SendPropertyChangedSignal(name);
104 }
105
EmitRpcIdentifierArrayChanged(const string & name,const vector<string> &)106 void DeviceBinderAdaptor::EmitRpcIdentifierArrayChanged(
107 const string& name, const vector<string>& /*value*/) {
108 SLOG(this, 2) << __func__ << ": " << name;
109 SendPropertyChangedSignal(name);
110 }
111
GetInterface(String16 * _aidl_return)112 Status DeviceBinderAdaptor::GetInterface(String16* _aidl_return) {
113 // STUB IMPLEMENTATION.
114 // TODO(samueltan): replace this with proper implementation.
115 return Status::ok();
116 }
117
GetSelectedService(sp<IBinder> * _aidl_return)118 Status DeviceBinderAdaptor::GetSelectedService(sp<IBinder>* _aidl_return) {
119 // STUB IMPLEMENTATION.
120 // TODO(samueltan): replace this with proper implementation.
121 return Status::ok();
122 }
123
RegisterPropertyChangedSignalHandler(const sp<IPropertyChangedCallback> & callback)124 Status DeviceBinderAdaptor::RegisterPropertyChangedSignalHandler(
125 const sp<IPropertyChangedCallback>& callback) {
126 AddPropertyChangedSignalHandler(callback);
127 return Status::ok();
128 }
129
130 } // namespace shill
131