Add Android control app and embedded server

Inspired by HNKServer/honoka-chan-apk-server, but implemented as a JNI-based embedded runtime instead of the original approach.

- Add an Android Compose controller app that starts and stops honoka-chan through JNI, shows runtime and health status, manages data directory mounting, and supports backup import/export for data.db
- Add an embeddable Go server entrypoint plus JNI-exported status, health, and reload hooks so desktop and Android builds share the same startup and shutdown path
- Add Android build scripts, runtime packaging, and project documentation, including generated default config.json content for honoka_runtime.zip
- Add runtime bundle hash tracking so updated honoka_runtime.zip assets are automatically redeployed while preserving config.json and user data files
- Add in-app service settings for unlock_all_special_rotation with immediate config persistence and automatic reload when the service is running
- Split SQLite driver selection by platform, using go-sqlite3 on Android and modernc.org/sqlite elsewhere to avoid Android x86_64 seccomp crashes
- Update startup, database initialization, and system health/reload handlers to support the embedded runtime and Android control flow

Signed-off-by: Sean Du <do4suki@gmail.com>
This commit is contained in:
2026-06-12 19:17:21 +08:00
parent 5c2d68f979
commit 91bbc7f607
64 changed files with 3230 additions and 286 deletions
+81 -27
View File
@@ -1,7 +1,7 @@
package db
import (
_ "modernc.org/sqlite"
"sync"
"xorm.io/xorm"
)
@@ -10,37 +10,91 @@ var (
UserDb = "assets/data.db"
MainEng *xorm.Engine
UserEng *xorm.Engine
mu sync.Mutex
)
func userSQLiteDSN(dbPath string) string {
return dbPath +
"?_pragma=busy_timeout(5000)" +
"&_pragma=journal_mode(WAL)" +
"&_pragma=synchronous(NORMAL)"
func Init(mainDbPath, userDbPath string) error {
mu.Lock()
defer mu.Unlock()
if mainDbPath == "" {
mainDbPath = MainDb
}
if userDbPath == "" {
userDbPath = UserDb
}
if MainEng != nil || UserEng != nil {
if MainDb == mainDbPath && UserDb == userDbPath {
return nil
}
if err := closeLocked(); err != nil {
return err
}
}
mainEng, err := xorm.NewEngine(sqliteDriverName, mainSQLiteDSN(mainDbPath))
if err != nil {
return err
}
if err := prepareMainSQLiteEngine(mainEng); err != nil {
mainEng.Close()
return err
}
if err := mainEng.Ping(); err != nil {
mainEng.Close()
return err
}
mainEng.SetMaxOpenConns(10)
mainEng.SetMaxIdleConns(5)
userEng, err := xorm.NewEngine(sqliteDriverName, userSQLiteDSN(userDbPath))
if err != nil {
mainEng.Close()
return err
}
if err := prepareUserSQLiteEngine(userEng); err != nil {
mainEng.Close()
userEng.Close()
return err
}
if err := userEng.Ping(); err != nil {
mainEng.Close()
userEng.Close()
return err
}
userEng.SetMaxOpenConns(10)
userEng.SetMaxIdleConns(5)
MainDb = mainDbPath
UserDb = userDbPath
MainEng = mainEng
UserEng = userEng
return nil
}
func init() {
eng, err := xorm.NewEngine("sqlite", MainDb)
if err != nil {
panic(err)
func Close() error {
mu.Lock()
defer mu.Unlock()
return closeLocked()
}
func closeLocked() error {
var firstErr error
if MainEng != nil {
if err := MainEng.Close(); err != nil && firstErr == nil {
firstErr = err
}
MainEng = nil
}
err = eng.Ping()
if err != nil {
panic(err)
if UserEng != nil {
if err := UserEng.Close(); err != nil && firstErr == nil {
firstErr = err
}
UserEng = nil
}
eng.SetMaxOpenConns(10)
eng.SetMaxIdleConns(5)
MainEng = eng
eng, err = xorm.NewEngine("sqlite", userSQLiteDSN(UserDb))
if err != nil {
panic(err)
}
err = eng.Ping()
if err != nil {
panic(err)
}
eng.SetMaxOpenConns(10)
eng.SetMaxIdleConns(5)
UserEng = eng
return firstErr
}