Date : 2026-10-27
Version analysée : 1.5.9 (versionCode 23, targetSdk 36 = Android 16)
Analyste : Claude Code (Agent Antigravity Secours)
Conclusion : Aucun bug de code détecté. Trois facteurs de configuration résiduelle bloquent la communication en arrière-plan :
onCreate() (ligne 239-261)battery_exemption_requested_by_service)isChargingOnly (lignes 145-159)ACTION_DEVICE_IDLE_MODE_CHANGED et ré-acquiert les locks si relâchés (lignes 75-94)Fichier : JarvisWakeWordManager.kt:190-193
if (isEnabled && !isStandby && autoStandbyMinutes > 0) {
val elapsedMinutes = (System.currentTimeMillis() - lastActivityTimestamp) / 60_000
if (elapsedMinutes >= autoStandbyMinutes) {
Log.i(tag, "💤 Délai d'inactivité de $autoStandbyMinutes min atteint -> Mise en veille automatique du micro !")
Comportement :
- Timer déclenché toutes les 10 secondes
- Si aucune activité vocale pendant autoStandbyMinutes → appelle enterStandby()
- enterStandby() → pauseEngine() → micro coupé + WakeLock relâché + Doze Mode autorisé
Valeur résiduelle connue : 15 minutes (hérité v1.5.2, documenté dans mémoire 23/10)
Impact :
- ✅ UI affiche "Jarvis actif"
- ❌ Micro réellement coupé après 15 min
- ❌ Aucun indicateur visuel de cette veille auto
Localisation config : SharedPreferences (probablement jarvis_wake_word_prefs ou default)
Fichier : JarvisWakeWordService.kt:145-159
private val powerReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action ?: return
val manager = JarvisWakeWordManager.getInstance(this@JarvisWakeWordService)
if (!manager.isEnabled || !manager.isChargingOnly) return
if (action == Intent.ACTION_POWER_CONNECTED) {
Log.i(tag, "🔌 Smartphone branché sur secteur -> Réveil automatique de l'écoute !")
resumeEngine()
} else if (action == Intent.ACTION_POWER_DISCONNECTED) {
Log.i(tag, "🔋 Smartphone sur batterie -> Mise en veille automatique (mode chargeur actif) !")
pauseEngine("Sur batterie")
}
}
}
Comportement :
- Si isChargingOnly == true → écoute active UNIQUEMENT sur secteur
- Dès ACTION_POWER_DISCONNECTED → pauseEngine("Sur batterie")
- Notification affiche "🌙 En veille (Micro 100% coupé — Sur batterie)"
Impact :
- Conçu pour économie batterie maximale
- Incompatible avec usage nomade (poche, déplacements)
Localisation config : JarvisWakeWordManager SharedPreferences
Contexte Android :
- Doze Mode (API 23+) gèle périodiquement les apps non exemptées
- WakeLocks sont "retenus mais ignorés" pendant fenêtres Doze si isIgnoringBatteryOptimizations == false
- Documentation officielle Android confirme ce comportement
Implémentation actuelle :
// Ligne 411-414
if (!isBatteryIgnoredState.value) {
requestBatteryOptimizationExemption()
}
battery_exemption_onboarding_shown)// Lignes 239-261
private fun requestBatteryExemptionIfNeeded() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
if (pm.isIgnoringBatteryOptimizations(packageName)) return
val prefs: SharedPreferences = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
if (prefs.getBoolean(KEY_BATTERY_EXEMPTION_REQUESTED, false)) {
Log.w(tag, "Optimisation batterie toujours active et exemption déjà demandée une fois -- Doze Mode peut geler l'écoute en arrière-plan.")
return
}
try {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
data = Uri.parse("package:$packageName")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
prefs.edit().putBoolean(KEY_BATTERY_EXEMPTION_REQUESTED, true).apply()
Log.i(tag, "Demande d'exemption batterie envoyée depuis le service Wake Word.")
} catch (e: Exception) {
Log.w(tag, "Erreur demande exemption batterie depuis le service: ${e.message}")
}
}
⚠️ Limitation critique :
- Le service demande UNE SEULE FOIS
- Si utilisateur refuse au popup système → flag mis à true quand même
- Ne redemandera plus JAMAIS automatiquement
- Seul recours : carte manuelle dans MainActivity
Impact si refusée :
- Doze Mode intervient après ~30 min écran éteint (variable selon fabricant)
- Services gelés périodiquement (fenêtres maintenance)
- WakeLocks/WifiLock ignorés pendant gel
- Liaison réseau coupée → perte audio bidirectionnelle
# Depuis ADB (smartphone connecté USB)
adb shell
run-as com.example.jarvis
cd shared_prefs
cat jarvis_wake_word_prefs.xml
cat com.example.jarvis_preferences.xml
Chercher :
- <int name="autoStandbyMinutes" value="?" />
- <boolean name="isChargingOnly" value="?" />
- <boolean name="battery_exemption_requested_by_service" value="?" />
- <boolean name="battery_exemption_onboarding_shown" value="?" />
# Depuis ADB
adb shell dumpsys deviceidle whitelist
# Chercher com.example.jarvis dans la liste
# OU depuis smartphone directement
Paramètres → Batterie → Optimisation batterie → Afficher toutes les apps → Chercher "JARVIS"
# Statut doit être "Non optimisée" ou "Désactivé"
# Activer logs verbeux Doze
adb shell dumpsys deviceidle enable
# Capturer logs pendant transition écran éteint → Doze
adb logcat -v time *:W | grep -E "(JarvisWakeWordService|JarvisVoiceService|DeviceIdle|Doze)"
# Chercher :
# - "Transition Doze Mode détectée : isDeviceIdleMode=true"
# - "WakeLock relâché par l'OS pendant Doze"
# - "Optimisation batterie toujours active et exemption déjà demandée"
# Forcer entrée Doze (smartphone débranché, écran éteint)
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle step
adb shell dumpsys deviceidle step
# Répéter jusqu'à "STATE_IDLE"
# Tester communication vocale pendant Doze forcé
# Si coupure → exemption batterie absente confirmée
Action : Réinitialiser SharedPreferences problématiques
// Depuis MainActivity ou outil développeur
val prefs = getSharedPreferences("jarvis_wake_word_prefs", Context.MODE_PRIVATE)
prefs.edit().apply {
putInt("autoStandbyMinutes", 0) // 0 = désactivé
putBoolean("isChargingOnly", false)
apply()
}
// Redémarrer service
JarvisWakeWordService.stop(this)
JarvisWakeWordService.start(this)
OU depuis ADB :
adb shell
run-as com.example.jarvis
cd shared_prefs
# Éditer manuellement XML ou supprimer pour reset
rm jarvis_wake_word_prefs.xml
Si exemption refusée :
1. Ouvrir l'app Jarvis
2. Carte d'avertissement accueil → bouton "Autoriser"
3. OU manuellement : Paramètres → Batterie → Optimisation batterie → JARVIS → "Ne pas optimiser"
Si popup jamais apparu :
- Vérifier logs pour exception ligne 259 de JarvisWakeWordService
- Permission REQUEST_IGNORE_BATTERY_OPTIMIZATIONS déclarée (✅ confirmé AndroidManifest.xml ligne 14)
Problème : Demande unique du service trop permissive
Solution : Ajouter vérification périodique SANS popup harcelant
// Dans JarvisWakeWordService.onStartCommand (avant resumeEngine)
private fun verifyBatteryExemptionSilent() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) return
val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
if (!pm.isIgnoringBatteryOptimizations(packageName)) {
// Logger + envoyer notification discrète (pas popup système)
Log.e(tag, "⚠️ ALERTE : Exemption batterie ABSENTE - Doze Mode gelera le service !")
// Notification persistante CRITIQUE invitant à ouvrir MainActivity
showCriticalBatteryExemptionWarning()
}
}
| Configuration | autoStandbyMinutes | isChargingOnly | Exemption Batterie | Comportement Attendu |
|---|---|---|---|---|
| Optimal | 0 (désactivé) | false | Accordée | Écoute continue 24/7 |
| Résiduel v1.5.2 | 15 | false | Accordée | ❌ Coupe après 15 min inactivité |
| Économie batterie | 0 | true | Accordée | ❌ Coupe dès débranchement |
| Sans exemption | 0 | false | Refusée | ❌ Gelé par Doze après ~30 min écran éteint |
| Pire cas | 15 | true | Refusée | ❌ Triple blocage (inactivité + batterie + Doze) |
project_jarvis_android_arriere_plan_permission_batterie_jamais_demandee_23102026.mdartifacts\DIAGNOSTIC_DYSFONCTIONNEMENT_WAKE_WORD_ANDROID.mdGénéré le : 2026-10-27
Agent : Claude Code (Antigravity Secours)
Fichiers analysés : 4 (MainActivity.kt, JarvisWakeWordService.kt, JarvisVoiceService.kt, AndroidManifest.xml)