display network settings based on device capabilities + fix android basic network info

pull/4615/head
Martín Fernández 5 years ago committed by Frans de Jonge
parent f3a36f8285
commit 04e17424d0

@ -1,9 +1,11 @@
local Generic = require("device/generic/device") local Generic = require("device/generic/device")
local _, android = pcall(require, "android") local A, android = pcall(require, "android") -- luacheck: ignore
local ffi = require("ffi") local ffi = require("ffi")
local C = ffi.C local C = ffi.C
local lfs = require("libs/libkoreader-lfs") local lfs = require("libs/libkoreader-lfs")
local logger = require("logger") local logger = require("logger")
local _ = require("gettext")
local T = require("ffi/util").template
local function yes() return true end local function yes() return true end
local function no() return false end local function no() return false end
@ -90,6 +92,15 @@ function Device:initNetworkManager(NetworkMgr)
end end
end end
function Device:retrieveNetworkInfo()
local ssid, ip, gw = android.getNetworkInfo()
if ip == 0 or gw == 0 then
return _("Not connected")
else
return T(_("Connected to %1\n IP address: %2\n gateway: %3"), ssid, ip, gw)
end
end
function Device:exit() function Device:exit()
android.log_name = 'luajit-launcher' android.log_name = 'luajit-launcher'
android.LOGI("Finishing luajit launcher main activity"); android.LOGI("Finishing luajit launcher main activity");

@ -40,6 +40,7 @@ local Cervantes = Generic:new{
touch_probe_ev_epoch_time = true, touch_probe_ev_epoch_time = true,
hasOTAUpdates = yes, hasOTAUpdates = yes,
hasKeys = yes, hasKeys = yes,
hasWifiManager = yes,
-- do we support usb mass storage? -- do we support usb mass storage?
canToggleMassStorage = function() return isMassStorageSupported() end, canToggleMassStorage = function() return isMassStorageSupported() end,

@ -21,6 +21,8 @@ local Device = {
hasKeyboard = no, hasKeyboard = no,
hasKeys = no, hasKeys = no,
hasDPad = no, hasDPad = no,
hasWifiToggle = yes,
hasWifiManager = no,
isTouchDevice = no, isTouchDevice = no,
hasFrontlight = no, hasFrontlight = no,
needsTouchScreenProbe = no, needsTouchScreenProbe = no,

@ -25,6 +25,7 @@ local Kobo = Generic:new{
isTouchDevice = yes, -- all of them are isTouchDevice = yes, -- all of them are
hasBGRFrameBuffer = yes, -- True when >16bpp (i.e., on current FW) hasBGRFrameBuffer = yes, -- True when >16bpp (i.e., on current FW)
hasOTAUpdates = yes, hasOTAUpdates = yes,
hasWifiManager = yes,
-- most Kobos have X/Y switched for the touch screen -- most Kobos have X/Y switched for the touch screen
touch_switch_xy = true, touch_switch_xy = true,

@ -55,6 +55,7 @@ local PocketBook = Generic:new{
isPocketBook = yes, isPocketBook = yes,
isInBackGround = false, isInBackGround = false,
hasOTAUpdates = yes, hasOTAUpdates = yes,
hasWifiToggle = no,
} }
function PocketBook:init() function PocketBook:init()

@ -12,6 +12,7 @@ local Device = Generic:new{
hasKeyboard = yes, hasKeyboard = yes,
hasKeys = yes, hasKeys = yes,
hasDPad = yes, hasDPad = yes,
hasWifiToggle = no,
isTouchDevice = yes, isTouchDevice = yes,
needsScreenRefreshAfterResume = no, needsScreenRefreshAfterResume = no,
hasColorScreen = yes, hasColorScreen = yes,
@ -27,6 +28,8 @@ local Emulator = Device:new{
isEmulator = yes, isEmulator = yes,
hasEinkScreen = yes, hasEinkScreen = yes,
hasFrontlight = yes, hasFrontlight = yes,
hasWifiToggle = yes,
hasWifiManager = yes,
} }
local Linux = Device:new{ local Linux = Device:new{

@ -11,6 +11,7 @@ local SonyPRSTUX = Generic:new{
isSonyPRSTUX = yes, isSonyPRSTUX = yes,
hasKeys = yes, hasKeys = yes,
hasOTAUpdates = yes, hasOTAUpdates = yes,
hasWifiManager = yes,
} }

@ -129,7 +129,7 @@ end
function NetworkMgr:getWifiMenuTable() function NetworkMgr:getWifiMenuTable()
return { return {
text = _("Wi-Fi connection"), text = _("Wi-Fi connection"),
enabled_func = function() return Device:isAndroid() or Device:isCervantes() or Device:isKindle() or Device:isKobo() or Device:isSonyPRSTUX() end, enabled_func = function() return Device:hasWifiToggle() and not Device:isEmulator() end,
checked_func = function() return NetworkMgr:isWifiOn() end, checked_func = function() return NetworkMgr:isWifiOn() end,
callback = function(touchmenu_instance) callback = function(touchmenu_instance)
local wifi_status = NetworkMgr:isWifiOn() and NetworkMgr:isConnected() local wifi_status = NetworkMgr:isWifiOn() and NetworkMgr:isConnected()
@ -195,7 +195,7 @@ function NetworkMgr:getRestoreMenuTable()
return { return {
text = _("Automatically restore Wi-Fi connection after resume"), text = _("Automatically restore Wi-Fi connection after resume"),
checked_func = function() return G_reader_settings:isTrue("auto_restore_wifi") end, checked_func = function() return G_reader_settings:isTrue("auto_restore_wifi") end,
enabled_func = function() return Device:isKobo() or Device:isCervantes() end, enabled_func = function() return Device:hasWifiManager() and not Device:isEmulator() end,
callback = function() G_reader_settings:flipNilOrFalse("auto_restore_wifi") end, callback = function() G_reader_settings:flipNilOrFalse("auto_restore_wifi") end,
} }
end end
@ -221,7 +221,6 @@ function NetworkMgr:getInfoMenuTable()
} }
end end
function NetworkMgr:getBeforeWifiActionMenuTable() function NetworkMgr:getBeforeWifiActionMenuTable()
local wifi_enable_action_setting = G_reader_settings:readSetting("wifi_enable_action") or "prompt" local wifi_enable_action_setting = G_reader_settings:readSetting("wifi_enable_action") or "prompt"
local wifi_enable_actions = { local wifi_enable_actions = {
@ -257,18 +256,24 @@ function NetworkMgr:getDismissScanMenuTable()
return { return {
text = _("Dismiss Wi-Fi scan popup after connection"), text = _("Dismiss Wi-Fi scan popup after connection"),
checked_func = function() return G_reader_settings:nilOrTrue("auto_dismiss_wifi_scan") end, checked_func = function() return G_reader_settings:nilOrTrue("auto_dismiss_wifi_scan") end,
--enabled_func = function() return Device:isKobo() end, enabled_func = function() return Device:hasWifiManager() and not Device:isEmulator() end,
callback = function() G_reader_settings:flipNilOrTrue("auto_dismiss_wifi_scan") end, callback = function() G_reader_settings:flipNilOrTrue("auto_dismiss_wifi_scan") end,
} }
end end
function NetworkMgr:getMenuTable(common_settings) function NetworkMgr:getMenuTable(common_settings)
common_settings.network_wifi = self:getWifiMenuTable() if Device:hasWifiToggle() then
common_settings.network_wifi = self:getWifiMenuTable()
end
common_settings.network_proxy = self:getProxyMenuTable() common_settings.network_proxy = self:getProxyMenuTable()
common_settings.network_restore = self:getRestoreMenuTable()
common_settings.network_info = self:getInfoMenuTable() common_settings.network_info = self:getInfoMenuTable()
common_settings.network_before_wifi_action = self:getBeforeWifiActionMenuTable()
common_settings.network_dismiss_scan = self:getDismissScanMenuTable() if Device:hasWifiManager() then
common_settings.network_restore = self:getRestoreMenuTable()
common_settings.network_dismiss_scan = self:getDismissScanMenuTable()
common_settings.network_before_wifi_action = self:getBeforeWifiActionMenuTable()
end
end end
function NetworkMgr:showNetworkMenu(complete_callback) function NetworkMgr:showNetworkMenu(complete_callback)

Loading…
Cancel
Save