From 75ff5dcaae013a7431d0f45b2ff413f88fef74f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Fern=C3=A1ndez?= Date: Wed, 19 Jun 2019 01:57:52 +0200 Subject: [PATCH] Add Device:Info for android and use it in report a bug infomessage. Move local function getCodename to top, use android.app.activity.sdkVersion directly, instead of relying on Device.firmware_rev --- frontend/device/android/device.lua | 67 ++++++++++++------- .../ui/elements/common_info_menu_table.lua | 8 ++- 2 files changed, 49 insertions(+), 26 deletions(-) diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index 57da72ef0..93920eef6 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -15,6 +15,31 @@ local function canUpdateApk() return (android.prop.flavor ~= "fdroid") end +local function getCodename() + local api = android.app.activity.sdkVersion + local codename = "" + + if api > 27 then + codename = "Pie" + elseif api == 27 or api == 26 then + codename = "Oreo" + elseif api == 25 or api == 24 then + codename = "Nougat" + elseif api == 23 then + codename = "Marshmallow" + elseif api == 22 or api == 21 then + codename = "Lollipop" + elseif api == 19 then + codename = "KitKat" + elseif api < 19 and api >= 16 then + codename = "Jelly Bean" + elseif api < 16 and api >= 14 then + codename = "Ice Cream Sandwich" + end + + return codename +end + local Device = Generic:new{ isAndroid = yes, model = android.prop.product, @@ -140,34 +165,28 @@ function Device:retrieveNetworkInfo() end end -function Device:exit() - android.LOGI(string.format("Stopping %s main activity", android.prop.name)); - android.lib.ANativeActivity_finish(android.app.activity) -end +function Device:info() + local is_eink, eink_platform = android.isEink() -local function getCodename() - local api = Device.firmware_rev - local codename = nil + local common_text = T(_("%1\n\nOS: Android %2, api %3\nBuild flavor: %4\n"), + android.prop.product, getCodename(), Device.firmware_rev, android.prop.flavor) - if api > 27 then - codename = "Pie" - elseif api == 27 or api == 26 then - codename = "Oreo" - elseif api == 25 or api == 24 then - codename = "Nougat" - elseif api == 23 then - codename = "Marshmallow" - elseif api == 22 or api == 21 then - codename = "Lollipop" - elseif api == 19 then - codename = "KitKat" - elseif api < 19 and api >= 16 then - codename = "Jelly Bean" - elseif api < 16 and api >= 14 then - codename = "Ice Cream Sandwich" + local eink_text = "" + if is_eink then + eink_text = T(_("\nE-ink display supported.\nPlatform: %1\n"), eink_platform) + end + + local wakelocks_text = "" + if android.needsWakelocks() then + wakelocks_text = _("\nThis device needs CPU, screen and touchscreen always on.\nScreen timeout will be ignored while the app is in the foreground!\n") end - return codename or "" + return common_text..eink_text..wakelocks_text +end + +function Device:exit() + android.LOGI(string.format("Stopping %s main activity", android.prop.name)); + android.lib.ANativeActivity_finish(android.app.activity) end android.LOGI(string.format("Android %s - %s (API %d) - flavor: %s", diff --git a/frontend/ui/elements/common_info_menu_table.lua b/frontend/ui/elements/common_info_menu_table.lua index 6fe313bdb..1cffe2a10 100644 --- a/frontend/ui/elements/common_info_menu_table.lua +++ b/frontend/ui/elements/common_info_menu_table.lua @@ -53,10 +53,14 @@ common_info.report_bug = { text = _("Report a bug"), keep_menu_open = true, callback = function() - local model = Device.model + local device = Device.model + if Device:isAndroid() then + device = Device:info() + end + UIManager:show(InfoMessage:new{ text = T(_("Please report bugs to \nhttps://github.com/koreader/koreader/issues\n\nVersion:\n%1\n\nDetected device:\n%2"), - version, model), + version, device), }) end }