73 lines
2.9 KiB
Kotlin
73 lines
2.9 KiB
Kotlin
package com.kazeia
|
|
|
|
import android.app.Application
|
|
import android.app.NotificationChannel
|
|
import android.app.NotificationManager
|
|
import android.content.Context
|
|
import android.os.Build
|
|
|
|
class KazeiaApplication : Application() {
|
|
|
|
companion object {
|
|
const val CHANNEL_ID = "kazeia_service_channel"
|
|
|
|
/** Racine modèles STT/TTS — résolue par [KazeiaPaths]. */
|
|
val MODELS_DIR: String get() = KazeiaPaths.modelsDir
|
|
|
|
/** Racine modèles LLM ExecuTorch (`.pte`) — résolue par [KazeiaPaths]. */
|
|
val LLM_DIR: String get() = KazeiaPaths.llmDir
|
|
}
|
|
|
|
override fun attachBaseContext(base: Context) {
|
|
super.attachBaseContext(base)
|
|
// Résolution des racines modèles AVANT tout ContentProvider/Activity.
|
|
KazeiaPaths.init(base)
|
|
}
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
createNotificationChannel()
|
|
|
|
// QNN HTP sur DSP (.pte LLM ExecuTorch + TTS) : le skel `libQnnHtpV79Skel.so`
|
|
// est relayé au CDSP par FastRPC, qui le cherche via ADSP_LIBRARY_PATH. Sans
|
|
// ça, le DSP ne trouve pas le skel (errno 2) → device_handle échoue (14001) →
|
|
// chargement .pte renvoie handle 0. On pointe sur le dossier natif extrait de
|
|
// l'APK (où vit le skel) + chemins DSP système. Doit être posé AVANT toute
|
|
// ouverture de session QNN (bench, KazeiaService, TTS). Cf. Qwen3TtsEngine.
|
|
try {
|
|
val nativeLibDir = applicationInfo.nativeLibraryDir
|
|
android.system.Os.setenv(
|
|
"ADSP_LIBRARY_PATH",
|
|
"$nativeLibDir;/vendor/dsp/cdsp;/vendor/lib/rfsa/adsp;/vendor/dsp",
|
|
true
|
|
)
|
|
} catch (_: Throwable) {}
|
|
// Note: Unity native lib preloading was removed because Unity 6 GameActivity
|
|
// requires its own initialization sequence. Loading libs out of order causes
|
|
// native crashes. Unity handles lib loading internally in onCreate().
|
|
|
|
// Bench LLM (lib CPU-only) : `touch <files>/bench_llm.trigger`, relance app.
|
|
// Charge EngineLlmEngine + 3 prompts FR thérapeutiques.
|
|
val trigLlm = java.io.File(getExternalFilesDir(null), "bench_llm.trigger")
|
|
if (trigLlm.exists()) {
|
|
trigLlm.delete()
|
|
Thread { com.kazeia.llm.BenchLlmHarness.runBench(this@KazeiaApplication) }.start()
|
|
}
|
|
}
|
|
|
|
private fun createNotificationChannel() {
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
val channel = NotificationChannel(
|
|
CHANNEL_ID,
|
|
getString(R.string.notification_channel),
|
|
NotificationManager.IMPORTANCE_LOW
|
|
).apply {
|
|
description = getString(R.string.notification_text)
|
|
setShowBadge(false)
|
|
}
|
|
val manager = getSystemService(NotificationManager::class.java)
|
|
manager.createNotificationChannel(channel)
|
|
}
|
|
}
|
|
}
|