Merge lp:~morphis/aethercast/add-urfkill-support into lp:aethercast

Proposed by Simon Fels
Status: Superseded
Proposed branch: lp:~morphis/aethercast/add-urfkill-support
Merge into: lp:aethercast
Prerequisite: lp:~morphis/aethercast/fix-integraion-tests
Diff against target: 246 lines (+14/-159)
4 files modified
src/CMakeLists.txt (+1/-0)
src/w11tng/networkmanager.cpp (+4/-3)
src/w11tng/rfkillmanager.cpp (+1/-125)
src/w11tng/rfkillmanager.h (+8/-31)
To merge this branch: bzr merge lp:~morphis/aethercast/add-urfkill-support
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+298490@code.launchpad.net

This proposal supersedes a proposal from 2016-06-28.

This proposal has been superseded by a proposal from 2016-06-28.

Commit message

Add URfkill support to manage kill switches on selected devices

Some devices don't use the rfkill provided from the kernel to managed the kill state of WiFi. They are using a libhardware_legacy from Android through libhybris to manage the WiFi power state. We have to use urfkill in those cases rather than relying on the rfkill provided from the kernel.

Fixes LP #1579676

Description of the change

Add URfkill support to manage kill switches on selected devices

Some devices don't use the rfkill provided from the kernel to managed the kill state of WiFi. They are using a libhardware_legacy from Android through libhybris to manage the WiFi power state. We have to use urfkill in those cases rather than relying on the rfkill provided from the kernel.

To post a comment you must log in.

Unmerged revisions

153. By Simon Fels

w11tng: refactor rfkill manager into a kernel specific and base class

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/CMakeLists.txt'
2--- src/CMakeLists.txt 2016-05-19 10:36:36 +0000
3+++ src/CMakeLists.txt 2016-06-28 08:31:28 +0000
4@@ -120,6 +120,7 @@
5
6 w11tng/networkmanager.cpp
7 w11tng/rfkillmanager.cpp
8+ w11tng/kernelrfkillmanager.cpp
9 w11tng/networkdevice.cpp
10 w11tng/interfaceselector.cpp
11 w11tng/p2pdevicestub.cpp
12
13=== modified file 'src/w11tng/networkmanager.cpp'
14--- src/w11tng/networkmanager.cpp 2016-05-19 05:24:46 +0000
15+++ src/w11tng/networkmanager.cpp 2016-06-28 08:31:28 +0000
16@@ -24,8 +24,9 @@
17 #include <ac/keep_alive.h>
18 #include <ac/networkutils.h>
19
20-#include "networkmanager.h"
21-#include "informationelement.h"
22+#include "w11tng/networkmanager.h"
23+#include "w11tng/informationelement.h"
24+#include "w11tng/kernelrfkillmanager.h"
25
26 namespace {
27 // We take two minutes as timeout here which corresponds to what wpa
28@@ -51,7 +52,7 @@
29 return sp;
30 }
31
32- rfkill_manager_ = RfkillManager::Create();
33+ rfkill_manager_ = KernelRfkillManager::Create();
34 rfkill_manager_->SetDelegate(sp);
35
36 return sp;
37
38=== modified file 'src/w11tng/rfkillmanager.cpp'
39--- src/w11tng/rfkillmanager.cpp 2016-05-19 05:24:46 +0000
40+++ src/w11tng/rfkillmanager.cpp 2016-06-28 08:31:28 +0000
41@@ -15,78 +15,10 @@
42 *
43 */
44
45-#include <string.h>
46-#include <errno.h>
47-
48-#include "ac/logger.h"
49-#include "ac/keep_alive.h"
50-
51-#include "rfkillmanager.h"
52-
53-namespace {
54-constexpr const char *kDevRfkillPath{"/dev/rfkill"};
55-
56-struct RfkillEvent {
57- uint32_t idx;
58- uint8_t type;
59- uint8_t op;
60- uint8_t soft;
61- uint8_t hard;
62-};
63-
64-enum RfkillOp {
65- kRfkillOpAdd = 0,
66- kRfkillOpDel,
67- kRfkillOpChange,
68- kRfkillOpChangeAll,
69-};
70-}
71+#include "w11tng/rfkillmanager.h"
72
73 namespace w11tng {
74-
75-RfkillManager::Ptr RfkillManager::Create() {
76- return std::shared_ptr<RfkillManager>(new RfkillManager)->FinalizeConstruction();
77-}
78-
79-RfkillManager::RfkillManager() :
80- watch_(0) {
81-}
82-
83 RfkillManager::~RfkillManager() {
84- if (watch_)
85- g_source_remove(watch_);
86-}
87-
88-RfkillManager::Ptr RfkillManager::FinalizeConstruction() {
89- auto sp = shared_from_this();
90-
91- auto fd = ::open(kDevRfkillPath, O_RDWR | O_CLOEXEC);
92- if (fd < 0) {
93- AC_ERROR("Failed to open rfkill device at %s: %s",
94- kDevRfkillPath, ::strerror(errno));
95- return sp;
96- }
97-
98- channel_.reset(g_io_channel_unix_new(fd));
99- g_io_channel_set_close_on_unref(channel_.get(), TRUE);
100- g_io_channel_set_encoding(channel_.get(), nullptr, nullptr);
101- g_io_channel_set_buffered(channel_.get(), FALSE);
102-
103- int flags = g_io_channel_get_flags(channel_.get());
104- flags |= G_IO_FLAG_NONBLOCK;
105- g_io_channel_set_flags(channel_.get(), GIOFlags(flags), nullptr);
106-
107- // We're reading the current state of all rfkill items to make sure
108- // have everything in sync
109- while (ProcessRfkillEvents());
110-
111- watch_ = g_io_add_watch_full(channel_.get(), G_PRIORITY_DEFAULT,
112- GIOCondition(G_IO_IN | G_IO_NVAL | G_IO_HUP | G_IO_ERR),
113- OnRfkillEvent,
114- new ac::WeakKeepAlive<RfkillManager>(sp),
115- [](gpointer user_data) { delete static_cast<ac::WeakKeepAlive<RfkillManager>*>(user_data); });
116-
117- return sp;
118 }
119
120 void RfkillManager::SetDelegate(const std::weak_ptr<Delegate> &delegate) {
121@@ -96,60 +28,4 @@
122 void RfkillManager::ResetDelegate() {
123 delegate_.reset();
124 }
125-
126-bool RfkillManager::IsBlocked(const Type &type) {
127- if (block_status_.find(type) == block_status_.end())
128- return false;
129-
130- return block_status_[type];
131-}
132-
133-bool RfkillManager::ProcessRfkillEvents() {
134- RfkillEvent event;
135- ::memset(&event, 0, sizeof(RfkillEvent));
136-
137- gsize len = 0;
138- auto status = g_io_channel_read_chars(channel_.get(), reinterpret_cast<gchar*>(&event),
139- sizeof(RfkillEvent),
140- &len, nullptr);
141-
142- if (status != G_IO_STATUS_NORMAL)
143- return false;
144-
145- if (len != sizeof(RfkillEvent))
146- return false;
147-
148- auto type = static_cast<Type>(event.type);
149-
150- switch (event.op) {
151- case RfkillOp::kRfkillOpAdd:
152- case RfkillOp::kRfkillOpChange:
153-
154- block_status_[type] = (event.soft || event.hard);
155-
156- AC_DEBUG("rfkill type %d is now %s",
157- static_cast<int>(event.type),
158- block_status_[type] ? "blocked" : "not blocked");
159-
160- if (auto sp = delegate_.lock())
161- sp->OnRfkillChanged(type);
162- break;
163- default:
164- break;
165- }
166-
167- return true;
168-}
169-
170-gboolean RfkillManager::OnRfkillEvent(GIOChannel *channel, GIOCondition cond, gpointer data) {
171- auto thiz = static_cast<ac::WeakKeepAlive<RfkillManager>*>(data)->GetInstance().lock();
172- if (!thiz)
173- return FALSE;
174-
175- if (cond & (G_IO_NVAL | G_IO_HUP | G_IO_ERR))
176- return FALSE;
177-
178- return static_cast<gboolean>(thiz->ProcessRfkillEvents());
179-}
180-
181 } // namespace w11tng
182
183=== modified file 'src/w11tng/rfkillmanager.h'
184--- src/w11tng/rfkillmanager.h 2016-05-19 05:24:46 +0000
185+++ src/w11tng/rfkillmanager.h 2016-06-28 08:31:28 +0000
186@@ -18,23 +18,13 @@
187 #ifndef W11TNG_RFKILL_MANAGER_H_
188 #define W11TNG_RFKILL_MANAGER_H_
189
190-#include <memory>
191-#include <map>
192-
193 #include "ac/non_copyable.h"
194 #include "ac/glib_wrapper.h"
195
196+#include <memory>
197+
198 namespace w11tng {
199-
200-template<typename T>
201-struct GIOChannelDeleter {
202- void operator()(T *object) const {
203- if (object)
204- g_io_channel_unref(object);
205- }
206-};
207-
208-class RfkillManager : public std::enable_shared_from_this<RfkillManager> {
209+class RfkillManager {
210 public:
211 typedef std::shared_ptr<RfkillManager> Ptr;
212
213@@ -53,29 +43,16 @@
214 virtual void OnRfkillChanged(const Type &type) = 0;
215 };
216
217- static Ptr Create();
218-
219- ~RfkillManager();
220+ virtual ~RfkillManager();
221
222 void SetDelegate(const std::weak_ptr<Delegate> &delegate);
223 void ResetDelegate();
224
225- bool IsBlocked(const Type &type);
226-
227-private:
228- RfkillManager();
229-
230- Ptr FinalizeConstruction();
231-
232- bool ProcessRfkillEvents();
233-
234- static gboolean OnRfkillEvent(GIOChannel *channel, GIOCondition cond, gpointer data);
235-
236-private:
237+ virtual bool IsBlocked(const Type &type) = 0;
238+
239+protected:
240 std::weak_ptr<Delegate> delegate_;
241- std::unique_ptr<GIOChannel, GIOChannelDeleter<GIOChannel>> channel_;
242- guint watch_;
243- std::map<Type,bool> block_status_;
244+
245 };
246 } // namespace w11tng
247

Subscribers

People subscribed via source and target branches

to all changes: