diff --git a/frontend/device/generic/device.lua b/frontend/device/generic/device.lua index e8f671c6c..335e8ce70 100644 --- a/frontend/device/generic/device.lua +++ b/frontend/device/generic/device.lua @@ -184,6 +184,10 @@ function Device:usbPlugOut() self.charging_mode = false end +-- Hardware specific method to initialize network manager module +function Device:initNetworkManager() +end + --[[ prepare for application shutdown --]] diff --git a/frontend/device/kindle/device.lua b/frontend/device/kindle/device.lua index 6538f6745..cf5485fe2 100644 --- a/frontend/device/kindle/device.lua +++ b/frontend/device/kindle/device.lua @@ -4,11 +4,34 @@ local DEBUG = require("dbg") local function yes() return true end local function no() return false end -- luacheck: ignore +local function kindleEnableWifi(toggle) + local haslipc, lipc = pcall(require, "liblipclua") + local lipc_handle = nil + if haslipc and lipc then + lipc_handle = lipc.init("com.github.koreader.networkmgr") + end + if lipc_handle then + lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle) + lipc_handle:close() + end +end + + local Kindle = Generic:new{ model = "Kindle", isKindle = yes, } +function Kindle:initNetworkManager(NetworkMgr) + NetworkMgr.turnOnWifi = function() + kindleEnableWifi(1) + end + + NetworkMgr.turnOffWifi = function() + kindleEnableWifi(0) + end +end + local Kindle2 = Kindle:new{ model = "Kindle2", hasKeyboard = yes, diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index d3c134cd2..8157a4502 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -5,6 +5,26 @@ local dbg = require("dbg") local function yes() return true end +local function koboEnableWifi(toggle) + if toggle == 1 then + os.execute("lsmod | grep -q sdio_wifi_pwr || insmod /drivers/$PLATFORM/wifi/sdio_wifi_pwr.ko") + os.execute("lsmod | grep -q dhd || insmod /drivers/$PLATFORM/wifi/dhd.ko") + os.execute("sleep 2") + os.execute("ifconfig eth0 up") + os.execute("wlarm_le -i eth0 up") + os.execute("pidof wpa_supplicant >/dev/null || cd / && env -u LD_LIBRARY_PATH wpa_supplicant -s -i eth0 -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant -B") + os.execute("sleep 1") + os.execute("cd / && env -u LD_LIBRARY_PATH /sbin/udhcpc -S -i eth0 -s /etc/udhcpc.d/default.script -t15 -T10 -A3 -b -q >/dev/null 2>&1 &") + else + os.execute("killall udhcpc default.script wpa_supplicant 2>/dev/null") + os.execute("wlarm_le -i eth0 down") + os.execute("ifconfig eth0 down") + os.execute("rmmod -r dhd") + os.execute("rmmod -r sdio_wifi_pwr") + end +end + + local Kobo = Generic:new{ model = "Kobo", isKobo = yes, @@ -138,6 +158,16 @@ function Kobo:init() end end +function Kobo:initNetworkManager(NetworkMgr) + NetworkMgr.turnOffWifi = function() + koboEnableWifi(0) + end + + NetworkMgr.turnOnWifi = function() + koboEnableWifi(1) + end +end + local probeEvEpochTime -- this function will update itself after the first touch event probeEvEpochTime = function(self, ev) diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua index fe8183873..1c94e86e7 100644 --- a/frontend/device/pocketbook/device.lua +++ b/frontend/device/pocketbook/device.lua @@ -38,6 +38,11 @@ local KEY_COVERCLOSE = 0x03 local function yes() return true end +local function pocketbookEnableWifi(toggle) + os.execute("/ebrmain/bin/netagent " .. (toggle == 1 and "connect" or "disconnect")) +end + + local PocketBook = Generic:new{ model = "PocketBook", isPocketBook = yes, @@ -73,6 +78,16 @@ function PocketBook:init() Generic.init(self) end +function PocketBook:initNetworkManager(NetworkMgr) + NetworkMgr.turnOnWifi = function() + pocketbookEnableWifi(1) + end + + NetworkMgr.turnOffWifi = function() + pocketbookEnableWifi(0) + end +end + local PocketBook840 = PocketBook:new{ isTouchDevice = yes, hasKeys = yes, diff --git a/frontend/ui/networkmgr.lua b/frontend/ui/networkmgr.lua index a9b8c330d..9bbe0883c 100644 --- a/frontend/ui/networkmgr.lua +++ b/frontend/ui/networkmgr.lua @@ -4,62 +4,15 @@ local UIManager = require("ui/uimanager") local Device = require("device") local T = require("ffi/util").template local _ = require("gettext") -local NetworkMgr = {} - -local function kindleEnableWifi(toggle) - local haslipc, lipc = pcall(require, "liblipclua") - local lipc_handle = nil - if haslipc and lipc then - lipc_handle = lipc.init("com.github.koreader.networkmgr") - end - if lipc_handle then - lipc_handle:set_int_property("com.lab126.cmd", "wirelessEnable", toggle) - lipc_handle:close() - end -end -local function koboEnableWifi(toggle) - if toggle == 1 then - os.execute("lsmod | grep -q sdio_wifi_pwr || insmod /drivers/$PLATFORM/wifi/sdio_wifi_pwr.ko") - os.execute("lsmod | grep -q dhd || insmod /drivers/$PLATFORM/wifi/dhd.ko") - os.execute("sleep 2") - os.execute("ifconfig eth0 up") - os.execute("wlarm_le -i eth0 up") - os.execute("pidof wpa_supplicant >/dev/null || cd / && env -u LD_LIBRARY_PATH wpa_supplicant -s -i eth0 -c /etc/wpa_supplicant/wpa_supplicant.conf -C /var/run/wpa_supplicant -B") - os.execute("sleep 1") - os.execute("cd / && env -u LD_LIBRARY_PATH /sbin/udhcpc -S -i eth0 -s /etc/udhcpc.d/default.script -t15 -T10 -A3 -b -q >/dev/null 2>&1 &") - else - os.execute("killall udhcpc default.script wpa_supplicant 2>/dev/null") - os.execute("wlarm_le -i eth0 down") - os.execute("ifconfig eth0 down") - os.execute("rmmod -r dhd") - os.execute("rmmod -r sdio_wifi_pwr") - end -end -local function pocketbookEnableWifi(toggle) - os.execute("/ebrmain/bin/netagent " .. (toggle == 1 and "connect" or "disconnect")) -end +local NetworkMgr = {} -function NetworkMgr:turnOnWifi() - if Device:isKindle() then - kindleEnableWifi(1) - elseif Device:isKobo() then - koboEnableWifi(1) - elseif Device:isPocketBook() then - pocketbookEnableWifi(1) - end -end +-- Device specific method, needs to be initialized in Device:initNetworkManager +function NetworkMgr:turnOnWifi() end -function NetworkMgr:turnOffWifi() - if Device:isKindle() then - kindleEnableWifi(0) - elseif Device:isKobo() then - koboEnableWifi(0) - elseif Device:isPocketBook() then - pocketbookEnableWifi(0) - end -end +-- Device specific method, needs to be initialized in Device:initNetworkManager +function NetworkMgr:turnOffWifi() end function NetworkMgr:promptWifiOn() UIManager:show(ConfirmBox:new{ @@ -152,4 +105,6 @@ if NETWORK_PROXY then NetworkMgr:setHTTPProxy(NETWORK_PROXY) end +Device:initNetworkManager(NetworkMgr) + return NetworkMgr