mirror of
https://github.com/koreader/koreader
synced 2024-11-20 03:25:34 +00:00
Add Device:otaModel() (#12014)
Devices with a single target might want to specify it in `Device.ota_model` Devices with multiple targets want to override the function or to specify `ota_model` variants for each target.
This commit is contained in:
parent
e26fdc7f14
commit
617618d587
@ -116,6 +116,22 @@ local Device = Generic:extend{
|
||||
end,
|
||||
}
|
||||
|
||||
function Device:otaModel()
|
||||
-- "x86", "x64", "arm", "arm64", "ppc", "mips" or "mips64".
|
||||
local arch = jit.arch
|
||||
local model
|
||||
if arch == "arm64" then
|
||||
model = "android-arm64"
|
||||
elseif arch == "x86" then
|
||||
model = "android-x86"
|
||||
elseif arch == "x64" then
|
||||
model = "android-x86_64"
|
||||
else
|
||||
model = "android"
|
||||
end
|
||||
return model, "link"
|
||||
end
|
||||
|
||||
function Device:init()
|
||||
self.screen = require("ffi/framebuffer_android"):new{device = self, debug = logger.dbg}
|
||||
self.powerd = require("device/android/powerd"):new{device = self}
|
||||
|
@ -22,6 +22,7 @@ end
|
||||
|
||||
local Cervantes = Generic:extend{
|
||||
model = "Cervantes",
|
||||
ota_model = "cervantes",
|
||||
isCervantes = yes,
|
||||
isAlwaysPortrait = yes,
|
||||
isTouchDevice = yes,
|
||||
|
@ -516,6 +516,12 @@ function Device:simulateResume() end
|
||||
-- Put device into standby, input devices (buttons, touchscreen ...) stay enabled
|
||||
function Device:standby(max_duration) end
|
||||
|
||||
|
||||
-- Returns a string, used to determine the platform to fetch OTA updates
|
||||
function Device:otaModel()
|
||||
return self.ota_model, "ota"
|
||||
end
|
||||
|
||||
--[[--
|
||||
Device specific method for performing haptic feedback.
|
||||
|
||||
|
@ -15,6 +15,37 @@ require("ffi/fbink_input_h")
|
||||
local function yes() return true end
|
||||
local function no() return false end -- luacheck: ignore
|
||||
|
||||
-- Try to detect WARIO+ Kindle boards (i.MX6 & i.MX7)
|
||||
local function isWarioOrMore()
|
||||
local cpu_hw = nil
|
||||
-- Parse cpuinfo line by line, until we find the Hardware description
|
||||
for line in io.lines("/proc/cpuinfo") do
|
||||
if line:find("^Hardware") then
|
||||
cpu_hw = line:match("^Hardware%s*:%s([%g%s]*)$")
|
||||
end
|
||||
end
|
||||
-- NOTE: I couldn't dig up a cpuinfo dump from an Oasis 2 to check the CPU part value,
|
||||
-- but for Wario (Cortex A9), matching that to 0xc09 would work, too.
|
||||
-- On the other hand, I'm already using the Hardware match in MRPI, so, that sealed the deal ;).
|
||||
|
||||
-- If we've got a Hardware string, check if it mentions an i.MX 6 or 7 or a MTK...
|
||||
if cpu_hw then
|
||||
if cpu_hw:find("i%.MX%s?[6-7]") or cpu_hw:find("MT8110") then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Try to detect Kindle running hardfp firmware
|
||||
local function isHardFP()
|
||||
local util = require("util")
|
||||
return util.pathExists("/lib/ld-linux-armhf.so.3")
|
||||
end
|
||||
|
||||
local function kindleGetSavedNetworks()
|
||||
local haslipc, lipc = pcall(require, "libopenlipclua") -- use our lua lipc library with access to hasharray properties
|
||||
local lipc_handle
|
||||
@ -495,6 +526,22 @@ function Kindle:openInputDevices()
|
||||
self.input.open("fake_events")
|
||||
end
|
||||
|
||||
function Kindle:otaModel()
|
||||
local model
|
||||
if self:isTouchDevice() or self.model == "Kindle4" then
|
||||
if isHardFP() then
|
||||
model = "kindlehf"
|
||||
elseif isWarioOrMore() then
|
||||
model = "kindlepw2"
|
||||
else
|
||||
model = "kindle"
|
||||
end
|
||||
else
|
||||
model = "kindle-legacy"
|
||||
end
|
||||
return model, "ota"
|
||||
end
|
||||
|
||||
function Kindle:init()
|
||||
-- Check if the device supports deep sleep/quick boot
|
||||
if lfs.attributes("/sys/devices/platform/falconblk/uevent", "mode") == "file" then
|
||||
|
@ -92,6 +92,7 @@ end
|
||||
|
||||
local Kobo = Generic:extend{
|
||||
model = "Kobo",
|
||||
ota_model = "kobo",
|
||||
isKobo = yes,
|
||||
isTouchDevice = yes, -- all of them are
|
||||
hasOTAUpdates = yes,
|
||||
|
@ -21,6 +21,7 @@ local app_name = "koreader.app"
|
||||
|
||||
local PocketBook = Generic:extend{
|
||||
model = "PocketBook",
|
||||
ota_model = "pocketbook",
|
||||
isPocketBook = yes,
|
||||
hasOTAUpdates = yes,
|
||||
hasWifiToggle = yes,
|
||||
|
@ -32,6 +32,7 @@ local isRm2, rm_model = getModel()
|
||||
local Remarkable = Generic:extend{
|
||||
isRemarkable = yes,
|
||||
model = rm_model,
|
||||
ota_model = "remarkable",
|
||||
hasKeys = yes,
|
||||
needsScreenRefreshAfterResume = no,
|
||||
hasOTAUpdates = yes,
|
||||
@ -308,4 +309,3 @@ if isRm2 then
|
||||
else
|
||||
return Remarkable1
|
||||
end
|
||||
|
||||
|
@ -108,8 +108,15 @@ local Device = Generic:extend{
|
||||
window = G_reader_settings:readSetting("sdl_window", {}),
|
||||
}
|
||||
|
||||
function Device:otaModel()
|
||||
if self.ota_model then
|
||||
return self.ota_model, "link"
|
||||
end
|
||||
end
|
||||
|
||||
local AppImage = Device:extend{
|
||||
model = "AppImage",
|
||||
ota_model = "appimage",
|
||||
hasOTAUpdates = yes,
|
||||
isDesktop = yes,
|
||||
}
|
||||
|
@ -49,89 +49,10 @@ local ota_channels = {
|
||||
nightly = _("Development"),
|
||||
}
|
||||
|
||||
-- Try to detect Kindle running hardfp firmware
|
||||
function OTAManager:_isKindleHardFP()
|
||||
local util = require("util")
|
||||
return util.pathExists("/lib/ld-linux-armhf.so.3")
|
||||
end
|
||||
|
||||
-- Try to detect WARIO+ Kindle boards (i.MX6 & i.MX7)
|
||||
function OTAManager:_isKindleWarioOrMore()
|
||||
local cpu_hw = nil
|
||||
-- Parse cpuinfo line by line, until we find the Hardware description
|
||||
for line in io.lines("/proc/cpuinfo") do
|
||||
if line:find("^Hardware") then
|
||||
cpu_hw = line:match("^Hardware%s*:%s([%g%s]*)$")
|
||||
end
|
||||
end
|
||||
-- NOTE: I couldn't dig up a cpuinfo dump from an Oasis 2 to check the CPU part value,
|
||||
-- but for Wario (Cortex A9), matching that to 0xc09 would work, too.
|
||||
-- On the other hand, I'm already using the Hardware match in MRPI, so, that sealed the deal ;).
|
||||
|
||||
-- If we've got a Hardware string, check if it mentions an i.MX 6 or 7 or a MTK...
|
||||
if cpu_hw then
|
||||
if cpu_hw:find("i%.MX%s?[6-7]") or cpu_hw:find("MT8110") then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- "x86", "x64", "arm", "arm64", "ppc", "mips" or "mips64".
|
||||
local arch = jit.arch
|
||||
|
||||
function OTAManager:getOTAModel()
|
||||
if Device:isAndroid() then
|
||||
if arch == "arm64" then
|
||||
return "android-arm64"
|
||||
elseif arch == "x86" then
|
||||
return "android-x86"
|
||||
elseif arch == "x64" then
|
||||
return "android-x86_64"
|
||||
end
|
||||
return "android"
|
||||
elseif Device:isSDL() then
|
||||
return "appimage"
|
||||
elseif Device:isCervantes() then
|
||||
return "cervantes"
|
||||
elseif Device:isKindle() then
|
||||
if Device:isTouchDevice() or Device.model == "Kindle4" then
|
||||
if self:_isKindleHardFP() then
|
||||
return "kindlehf"
|
||||
elseif self:_isKindleWarioOrMore() then
|
||||
return "kindlepw2"
|
||||
else
|
||||
return "kindle"
|
||||
end
|
||||
else
|
||||
return "kindle-legacy"
|
||||
end
|
||||
elseif Device:isKobo() then
|
||||
return "kobo"
|
||||
elseif Device:isPocketBook() then
|
||||
return "pocketbook"
|
||||
elseif Device:isRemarkable() then
|
||||
return "remarkable"
|
||||
elseif Device:isSonyPRSTUX() then
|
||||
return "sony-prstux"
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
|
||||
function OTAManager:getOTAType()
|
||||
local ota_model = self:getOTAModel()
|
||||
|
||||
if ota_model == "" then return end
|
||||
|
||||
if ota_model:find("android") or ota_model:find("appimage") then
|
||||
return "link"
|
||||
end
|
||||
|
||||
return "ota"
|
||||
local platform, kind = Device:otaModel()
|
||||
if not platform then return "none" end
|
||||
return kind
|
||||
end
|
||||
|
||||
function OTAManager:getOTAServer()
|
||||
@ -152,23 +73,29 @@ function OTAManager:setOTAChannel(channel)
|
||||
G_reader_settings:saveSetting("ota_channel", channel)
|
||||
end
|
||||
|
||||
function OTAManager:getLinkFilename()
|
||||
return self.link_template:format(self:getOTAModel(), self:getOTAChannel())
|
||||
end
|
||||
|
||||
function OTAManager:getZsyncFilename()
|
||||
return self.zsync_template:format(self:getOTAModel(), self:getOTAChannel())
|
||||
function OTAManager:getFilename(kind)
|
||||
if type(kind) ~= "string" then return end
|
||||
local model = Device:otaModel()
|
||||
local channel = self:getOTAChannel()
|
||||
if kind == "ota" then
|
||||
return self.zsync_template:format(model, channel)
|
||||
elseif kind == "link" then
|
||||
return self.link_template:format(model, channel)
|
||||
end
|
||||
end
|
||||
|
||||
function OTAManager:checkUpdate()
|
||||
if Device:isDeprecated() then return -1 end
|
||||
|
||||
local http = require("socket.http")
|
||||
local ltn12 = require("ltn12")
|
||||
local socket = require("socket")
|
||||
local socketutil = require("socketutil")
|
||||
|
||||
local update_file = (self:getOTAType() == "link") and self:getLinkFilename() or self:getZsyncFilename()
|
||||
local update_kind = self:getOTAType()
|
||||
if not update_kind then return -1 end
|
||||
|
||||
local update_file = self:getFilename(update_kind)
|
||||
if not update_file then return -2 end
|
||||
|
||||
local ota_update_file = self:getOTAServer() .. update_file
|
||||
local local_update_file = ota_dir .. update_file
|
||||
@ -241,6 +168,10 @@ function OTAManager:fetchAndProcessUpdate()
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = T(_("Device no longer supported.\n\nPlease check %1"), "https://github.com/koreader/koreader/wiki/deprecated-devices")
|
||||
})
|
||||
elseif ota_version == -2 then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Unable to determine OTA model.")
|
||||
})
|
||||
elseif ota_version == nil then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Unable to contact OTA server. Try again later, or try another mirror."),
|
||||
|
Loading…
Reference in New Issue
Block a user