From 3a9cb659d1bef6eabb3581d8ee21269f3d0a865e Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 13 Mar 2016 23:42:58 +0800 Subject: [PATCH] add OTA update on Android --- .editorconfig | 6 +---- Makefile | 16 ++++++++++++++ .../ui/elements/common_info_menu_table.lua | 3 ++- frontend/ui/otamanager.lua | 22 +++++++++++++------ platform/android/llapp_main.lua | 16 ++++++++++++++ platform/android/luajit-launcher | 2 +- 6 files changed, 51 insertions(+), 14 deletions(-) diff --git a/.editorconfig b/.editorconfig index 10681860d..904eab0e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -14,11 +14,7 @@ indent_style = space indent_size = 2 trim_trailing_whitespace = false -[Makefile] -indent_style = tab -indent_size = 8 - -[Makefile.def] +[Makefile*] indent_style = tab indent_size = 8 diff --git a/Makefile b/Makefile index a5dd37531..56b8802d3 100644 --- a/Makefile +++ b/Makefile @@ -277,6 +277,22 @@ utupdate: all androidupdate: all mkdir -p $(ANDROID_LAUNCHER_DIR)/assets/module -rm $(ANDROID_LAUNCHER_DIR)/assets/module/koreader-* + # create zip package + cd $(INSTALL_DIR)/koreader && \ + zip -9 -r \ + ../../koreader-android-$(MACHINE)-$(VERSION).zip \ + * -x "resources/fonts/*" "resources/icons/src/*" "spec/*" + # generate android update package index file + zipinfo -1 koreader-android-$(MACHINE)-$(VERSION).zip > \ + $(INSTALL_DIR)/koreader/ota/package.index + rm -f koreader-android-$(MACHINE)-$(VERSION).zip + echo "ota/package.index" >> $(INSTALL_DIR)/koreader/ota/package.index + cp $(INSTALL_DIR)/koreader/git-rev $(INSTALL_DIR)/koreader/ota-rev + # make gzip android update for zsync OTA update + cd $(INSTALL_DIR)/koreader && \ + tar czafh ../../koreader-android-$(MACHINE)-$(VERSION).targz \ + -T ota/package.index --no-recursion + # make android update apk cd $(INSTALL_DIR)/koreader && 7z a -l -mx=1 \ ../../$(ANDROID_LAUNCHER_DIR)/assets/module/koreader-g$(REVISION).7z * \ -x!resources/fonts -x!resources/icons/src -x!spec diff --git a/frontend/ui/elements/common_info_menu_table.lua b/frontend/ui/elements/common_info_menu_table.lua index 7b1ff9d7a..b068a536f 100644 --- a/frontend/ui/elements/common_info_menu_table.lua +++ b/frontend/ui/elements/common_info_menu_table.lua @@ -5,7 +5,8 @@ local _ = require("gettext") local common_info = {} -if Device:isKindle() or Device:isKobo() or Device:isPocketBook() then +if Device:isKindle() or Device:isKobo() or Device:isPocketBook() + or Device:isAndroid() then local OTAManager = require("ui/otamanager") table.insert(common_info, OTAManager:getOTAMenuTable()) end diff --git a/frontend/ui/otamanager.lua b/frontend/ui/otamanager.lua index 9b4eb471d..d2be52530 100644 --- a/frontend/ui/otamanager.lua +++ b/frontend/ui/otamanager.lua @@ -25,9 +25,9 @@ local OTAManager = { "nightly", }, zsync_template = "koreader-%s-latest-%s.zsync", - installed_package = ota_dir .. "/koreader.installed.tar", + installed_package = ota_dir .. "koreader.installed.tar", package_indexfile = "ota/package.index", - updated_package = ota_dir .. "/koreader.updated.tar", + updated_package = ota_dir .. "koreader.updated.tar", } local ota_channels = { @@ -42,6 +42,8 @@ function OTAManager:getOTAModel() return "kobo" elseif Device:isPocketBook() then return "pocketbook" + elseif Device:isAndroid() then + return "android" else return "" end @@ -152,7 +154,7 @@ function OTAManager:fetchAndProcessUpdate() UIManager:show(ConfirmBox:new{ text = _("Error updating KOReader. Would you like to delete temporary files?"), ok_callback = function() - os.execute("rm " .. ota_dir .. "/ko*") + os.execute("rm " .. ota_dir .. "ko*") end, }) end @@ -164,13 +166,19 @@ end function OTAManager:_buildLocalPackage() -- TODO: validate the installed package? - local installed_package = lfs.currentdir() .. "/" .. self.installed_package + local installed_package = self.installed_package if lfs.attributes(installed_package, "mode") == "file" then return 0 end - return os.execute(string.format( - "./tar cvf %s -C .. -T %s --no-recursion", - self.installed_package, self.package_indexfile)) + if Device:isAndroid() then + return os.execute(string.format( + "./tar cvf %s -T %s --no-recursion", + self.installed_package, self.package_indexfile)) + else + return os.execute(string.format( + "./tar cvf %s -C .. -T %s --no-recursion", + self.installed_package, self.package_indexfile)) + end end function OTAManager:zsync() diff --git a/platform/android/llapp_main.lua b/platform/android/llapp_main.lua index 3eab5d099..85088f006 100644 --- a/platform/android/llapp_main.lua +++ b/platform/android/llapp_main.lua @@ -29,11 +29,27 @@ local file = A.jni:context(A.app.activity.vm, function(JNI) end) A.LOGI("intent file path " .. (file or "")) +-- update koreader from ota +local function update() + local new_update = "/sdcard/koreader/ota/koreader.update.tar" + local installed = "/sdcard/koreader/ota/koreader.installed.tar" + local update_file = io.open(new_update, "r") + if update_file ~= nil then + io.close(update_file) + if os.execute("tar xf " .. new_update) == 0 then + os.execute("mv " .. new_update .. " " .. installed) + end + end + +end + -- run koreader patch before koreader startup pcall(function() dofile("/sdcard/koreader/patch.lua") end) -- set proper permission for sdcv A.execute("chmod", "755", "./sdcv") +A.execute("chmod", "755", "./tar") +A.execute("chmod", "755", "./zsync") -- set TESSDATA_PREFIX env var ffi.C.putenv("TESSDATA_PREFIX=/sdcard/koreader/data") diff --git a/platform/android/luajit-launcher b/platform/android/luajit-launcher index 08f23b83e..f0284840b 160000 --- a/platform/android/luajit-launcher +++ b/platform/android/luajit-launcher @@ -1 +1 @@ -Subproject commit 08f23b83e882b16b587cf0ec8e267b5c7708a71f +Subproject commit f0284840b3a8d618381b1e4cb6ca330369a02eb5