mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
android: switch to connectivity manager
Co-Authored-By: Frans de Jonge <fransdejonge@gmail.com>
This commit is contained in:
@@ -230,22 +230,21 @@ end
|
||||
|
||||
function Device:initNetworkManager(NetworkMgr)
|
||||
function NetworkMgr:turnOnWifi(complete_callback)
|
||||
android.setWifiEnabled(true)
|
||||
if complete_callback then
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:scheduleIn(1, complete_callback)
|
||||
end
|
||||
android.openWifiSettings()
|
||||
end
|
||||
function NetworkMgr:turnOffWifi(complete_callback)
|
||||
android.openWifiSettings()
|
||||
end
|
||||
|
||||
function NetworkMgr:turnOffWifi(complete_callback)
|
||||
android.setWifiEnabled(false)
|
||||
if complete_callback then
|
||||
local UIManager = require("ui/uimanager")
|
||||
UIManager:scheduleIn(1, complete_callback)
|
||||
end
|
||||
function NetworkMgr:openSettings()
|
||||
android.openWifiSettings()
|
||||
end
|
||||
NetworkMgr.isWifiOn = function()
|
||||
return android.isWifiEnabled()
|
||||
|
||||
function NetworkMgr:isWifiOn()
|
||||
local ok = android.getNetworkInfo()
|
||||
ok = tonumber(ok)
|
||||
if not ok then return false end
|
||||
return ok == 1
|
||||
end
|
||||
end
|
||||
|
||||
@@ -254,12 +253,23 @@ function Device:performHapticFeedback(type)
|
||||
end
|
||||
|
||||
function Device:retrieveNetworkInfo()
|
||||
local ssid, ip, gw = android.getNetworkInfo()
|
||||
if ip == "0" or gw == "0" then
|
||||
local ok, type = android.getNetworkInfo()
|
||||
ok, type = tonumber(ok), tonumber(type)
|
||||
if not ok or not type or type == C.ANETWORK_NONE then
|
||||
return _("Not connected")
|
||||
else
|
||||
local BD = require("ui/bidi")
|
||||
return T(_("Connected to %1\n IP address: %2\n gateway: %3"), BD.wrap(ssid), BD.ltr(ip), BD.ltr(gw))
|
||||
if type == C.ANETWORK_WIFI then
|
||||
return _("Connected to Wi-Fi")
|
||||
elseif type == C.ANETWORK_MOBILE then
|
||||
return _("Connected to mobile data network")
|
||||
elseif type == C.ANETWORK_ETHERNET then
|
||||
return _("Connected to Ethernet")
|
||||
elseif type == C.ANETWORK_BLUETOOTH then
|
||||
return _("Connected to Bluetooth")
|
||||
elseif type == C.ANETWORK_VPN then
|
||||
return _("Connected to VPN")
|
||||
end
|
||||
return _("Unknown connection")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -153,6 +153,16 @@ function NetworkMgr:isOnline()
|
||||
return socket.dns.toip("dns.msftncsi.com") ~= nil
|
||||
end
|
||||
|
||||
function NetworkMgr:isNetworkInfoAvailable()
|
||||
if Device:isAndroid() then
|
||||
-- always available
|
||||
return true
|
||||
else
|
||||
--- @todo also show network info when device is authenticated to router but offline
|
||||
return self:isWifiOn()
|
||||
end
|
||||
end
|
||||
|
||||
function NetworkMgr:setHTTPProxy(proxy)
|
||||
local http = require("socket.http")
|
||||
http.PROXY = proxy
|
||||
@@ -165,6 +175,18 @@ function NetworkMgr:setHTTPProxy(proxy)
|
||||
end
|
||||
|
||||
function NetworkMgr:getWifiMenuTable()
|
||||
if Device:isAndroid() then
|
||||
return {
|
||||
text = _("Wi-Fi settings"),
|
||||
enabled_func = function() return true end,
|
||||
callback = function() NetworkMgr:openSettings() end,
|
||||
}
|
||||
else
|
||||
return self:getWifiToggleMenuTable()
|
||||
end
|
||||
end
|
||||
|
||||
function NetworkMgr:getWifiToggleMenuTable()
|
||||
return {
|
||||
text = _("Wi-Fi connection"),
|
||||
enabled_func = function() return Device:hasWifiToggle() and not Device:isEmulator() end,
|
||||
@@ -267,8 +289,7 @@ function NetworkMgr:getInfoMenuTable()
|
||||
return {
|
||||
text = _("Network info"),
|
||||
keep_menu_open = true,
|
||||
--- @todo also show network info when device is authenticated to router but offline
|
||||
enabled_func = function() return self:isWifiOn() end,
|
||||
enabled_func = function() return self:isNetworkInfoAvailable() end,
|
||||
callback = function()
|
||||
if Device.retrieveNetworkInfo then
|
||||
UIManager:show(InfoMessage:new{
|
||||
|
||||
Submodule platform/android/luajit-launcher updated: 9dae1481b0...b0cbf2690b
Reference in New Issue
Block a user