diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index e20347753..908442705 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -461,6 +461,28 @@ function Device:untar(archive, extract_to) return android.untar(archive, extract_to) end +function Device:download(link, name, ok_text) + local UIManager = require("ui/uimanager") + local ConfirmBox = require("ui/widget/confirmbox") + local InfoMessage = require("ui/widget/infomessage") + local ok = android.download(link, name) + if ok == C.ADOWNLOAD_EXISTS then + self:install() + elseif ok == C.ADOWNLOAD_OK then + android.ota.isRunning = true + UIManager:show(InfoMessage:new{ + text = ok_text, + timeout = 3, + }) + elseif ok == C.ADOWNLOAD_FAILED then + UIManager:show(ConfirmBox:new{ + text = _("Your device seems to be unable to download packages.\nRetry using the browser?"), + ok_text = _("Retry"), + ok_callback = function() self:openLink(link) end, + }) + end +end + function Device:install() local UIManager = require("ui/uimanager") local ConfirmBox = require("ui/widget/confirmbox") diff --git a/frontend/ui/otamanager.lua b/frontend/ui/otamanager.lua index 76de33d97..372566648 100644 --- a/frontend/ui/otamanager.lua +++ b/frontend/ui/otamanager.lua @@ -245,27 +245,8 @@ function OTAManager:fetchAndProcessUpdate() text = update_message, ok_text = update_ok_text, ok_callback = function() - local isAndroid, android = pcall(require, "android") - if isAndroid then - local ffi = require("ffi") - local C = ffi.C - -- try to download the package - local ok = android.download(link, ota_package) - if ok == C.ADOWNLOAD_EXISTS then - Device:install() - elseif ok == C.ADOWNLOAD_OK then - android.ota.isRunning = true - UIManager:show(InfoMessage:new{ - text = wait_for_download, - timeout = 3, - }) - elseif ok == C.ADOWNLOAD_FAILED then - UIManager:show(ConfirmBox:new{ - text = _("Your device seems to be unable to download packages.\nRetry using the browser?"), - ok_text = _("Retry"), - ok_callback = function() Device:openLink(link) end, - }) - end + if Device:isAndroid() then + Device:download(link, ota_package, wait_for_download) elseif Device:isSDL() then Device:openLink(link) end