Mission : Identifier la cause réelle du non-fonctionnement et proposer des actions correctives
Diagnostic complet : DIAGNOSTIC_ECHEC_COMMUNICATION_ARRIERE_PLAN_ANDROID_20261027.md
Version actuelle : 1.5.9 (versionCode 24)
Date : 27 octobre 2026
Diagnostic : 6 causes probables identifiées, dont 3 à probabilité HAUTE (exemption batterie refusée + flag bloquant, mode charge uniquement activé, watchdog 15 min résiduel).
Correctif principal : Supprimer le flag battery_exemption_requested_by_service qui empêche toute redemande d'exemption batterie après un premier refus. Ce flag introduit une asymétrie critique avec le correctif MainActivity du 26/10 (qui redemande à chaque démarrage app).
Impact estimé : Résolution de 80-90% des cas si combiné avec vérification/correction configuration SharedPreferences.
Scénario d'échec :
1. Service Wake Word démarre au boot (avant ouverture manuelle de l'app)
2. Popup système d'exemption batterie s'affiche
3. Raphaël refuse (appui sur "Refuser" ou ferme sans répondre)
4. Flag battery_exemption_requested_by_service → true écrit dans SharedPreferences
5. Service ne redemandera JAMAIS (ligne 245-247 du code ci-dessous)
6. Doze Mode tue le service en arrière-plan
7. MainActivity peut redemander depuis le 26/10, MAIS seulement si l'app est ouverte manuellement
Code problématique (JarvisWakeWordService.kt:244-247) :
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 // ⚠️ NE REDEMANDE JAMAIS
}
Asymétrie critique :
- MainActivity (corrigée le 26/10) : redemande systématiquement si exemption non accordée ✅
- JarvisWakeWordService (actuel) : demande une seule fois via flag ❌
Fichier : C:\ASSISTANT_IA\JARVIS_ANDROID\app\src\main\java\com\example\jarvis\wakeword\JarvisWakeWordService.kt
Ancien code (lignes 239-261) :
@SuppressLint("BatteryLife")
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}")
}
}
Nouveau code (RECOMMANDÉ) :
@SuppressLint("BatteryLife")
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
// SUPPRIMÉ : check du flag qui empêchait toute redemande après premier refus
// (alignement avec correction MainActivity du 26/10/2026)
// Nouveau comportement : redemande systématique si exemption non accordée,
// comme le fait déjà MainActivity depuis le correctif du 26/10
try {
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS).apply {
data = Uri.parse("package:$packageName")
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(intent)
Log.i(tag, "Demande d'exemption batterie envoyée depuis le service Wake Word (systématique si non accordée).")
} catch (e: Exception) {
Log.w(tag, "Erreur demande exemption batterie depuis le service: ${e.message}")
// Fallback : ouvrir paramètres manuels si popup système échoue
try {
val settingsIntent = Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivity(settingsIntent)
Log.i(tag, "Ouverture paramètres batterie manuels en fallback.")
} catch (e2: Exception) {
Log.e(tag, "Erreur fallback paramètres batterie: ${e2.message}")
}
}
}
Changements :
- ✅ Suppression complète du check prefs.getBoolean(KEY_BATTERY_EXEMPTION_REQUESTED, false)
- ✅ Suppression de l'écriture du flag prefs.edit().putBoolean(KEY_BATTERY_EXEMPTION_REQUESTED, true)
- ✅ Ajout fallback ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS si popup système échoue
- âś… Log explicite du nouveau comportement
Fichier : C:\ASSISTANT_IA\JARVIS_ANDROID\app\build.gradle.kts
Ancien :
versionCode = 24
versionName = "1.5.9"
Nouveau :
versionCode = 25
versionName = "1.5.10"
adb shell dumpsys battery optimization | grep jarvis
# Résultat attendu si exemption accordée : "com.example.jarvis: true"
# Si absent ou "false" → exemption refusée, c'est le problème
adb shell run-as com.example.jarvis cat /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml
Valeurs critiques Ă chercher :
<boolean name="battery_exemption_requested_by_service" value="true" /> <!-- Si true → flag bloquant actif -->
<boolean name="charging_only" value="true" /> <!-- Si true → micro coupé sur batterie -->
<int name="auto_standby_minutes" value="15" /> <!-- Si 15 → watchdog coupe après 15 min -->
<boolean name="is_standby" value="true" /> <!-- Si true → mode veille manuel activé -->
adb shell dumpsys activity services | grep JarvisWakeWordService
# Chercher : "app=ProcessRecord", "created", "started", "uptime"
adb logcat -d -t 500 | grep -E "JarvisWakeWord|batterie|Doze|Standby"
Logs Ă chercher :
- "Optimisation batterie toujours active et exemption déjà demandée une fois" → CAUSE #1 confirmée
- "Sur batterie (mode charge uniquement)" → CAUSE #2
- "Mise en veille automatique du micro" → CAUSE #3
- "Mettre en veille" → CAUSE #4
isChargingOnly ActivéDiagnostic rapide :
adb shell run-as com.example.jarvis cat /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml | grep charging_only
Correction via ADB :
adb shell "run-as com.example.jarvis sh -c 'cat > /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs_temp.xml << EOF
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>
<map>
<boolean name=\"is_enabled\" value=\"true\" />
<boolean name=\"is_standby\" value=\"false\" />
<boolean name=\"charging_only\" value=\"false\" />
<int name=\"auto_standby_minutes\" value=\"0\" />
</map>
EOF
mv /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs_temp.xml /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml'"
adb shell am force-stop com.example.jarvis
adb shell am start -n com.example.jarvis/.MainActivity
Correction via UI (si ADB indisponible) :
1. Ouvrir app Jarvis Android
2. Onglet "Wake Word"
3. Désactiver switch "Mode charge uniquement"
autoStandbyMinutes=15 RésiduelDiagnostic :
adb shell run-as com.example.jarvis cat /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml | grep auto_standby_minutes
Correction via ADB :
# Régler à 0 (désactivé) ou ≥120 (2h minimum)
adb shell "run-as com.example.jarvis sh -c 'sed -i \"s/auto_standby_minutes\" value=\"15\"/auto_standby_minutes\" value=\"0\"/g\" /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml'"
adb shell am force-stop com.example.jarvis
Correction via UI :
1. Ouvrir app Jarvis Android
2. Onglet "Wake Word"
3. Régler slider "Mise en veille automatique" sur "Désactivé" (0 min) ou ≥120 min
Diagnostic :
adb shell run-as com.example.jarvis cat /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml | grep is_standby
Correction :
- Via UI : Ouvrir app → désactiver switch "Mettre en veille"
- Via commande vocale : "OK Jarvis, réveille-toi"
Fabricants concernés et paramètres :
| Fabricant | Chemin paramètres | Action requise |
|---|---|---|
| Xiaomi/Redmi/Poco | Paramètres → Batterie → MIUI Battery Saver | Désactiver pour Jarvis |
| Paramètres → Applications → Démarrage auto → Jarvis | Activer | |
| Samsung | Paramètres → Batterie → Sleeping Apps | Retirer Jarvis de la liste |
| Paramètres → Batterie → Deep Sleeping Apps | Retirer Jarvis de la liste | |
| Huawei/Honor | Paramètres → Batterie → PowerGenie → Protected Apps | Ajouter Jarvis |
| Oppo/Realme | Paramètres → Batterie → ColorOS Battery Optimization | Désactiver pour Jarvis |
| Paramètres → Applications → Démarrage auto | Activer Jarvis | |
| Vivo | Paramètres → iManager → Autorisation auto-démarrage | Activer Jarvis |
Vérification supplémentaire :
- Applications récentes → verrouiller Jarvis (icône cadenas)
Carte UI existante (MainActivity lignes 1372-1453) :
- Bouton "Paramètres constructeur" qui ouvre Settings.ACTION_APPLICATION_DETAILS_SETTINGS
- Déjà implémenté, vérifier qu'elle s'affiche bien
Diagnostic :
adb logcat | grep -E "JarvisWakeWordService|ActivityManager.*kill"
Indicateurs :
- Logs "Service destroyed" sans "Service stopped gracefully"
- Événements onStartCommand() répétés sans onDestroy() correspondant
Solutions :
- Fermer apps tierces en arrière-plan
- Redémarrage smartphone (flush RAM)
- Réduire consommation mémoire app (optimisation future)
# Connecter smartphone via ADB
adb devices
# Vérification 1 : Exemption batterie
adb shell dumpsys battery optimization | grep jarvis
# Vérification 2 : SharedPreferences
adb shell run-as com.example.jarvis cat /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml
# Vérification 3 : État service
adb shell dumpsys activity services | grep JarvisWakeWordService
# Vérification 4 : Logs
adb logcat -d -t 500 | grep -E "JarvisWakeWord|batterie|Doze|Standby"
Analyser les résultats pour confirmer quelle(s) cause(s) sont actives.
Si CAUSE #1 confirmée (ou par principe pour éviter récidive) :
JarvisWakeWordService.kt (voir correctif ci-dessus)build.gradle.kts (versionCode 25, versionName "1.5.10")bash
cd C:\ASSISTANT_IA\JARVIS_ANDROID
gradlew assembleDebugbash
adb install -r app/build/outputs/apk/debug/app-debug.apkSi CAUSE #2 ou #3 confirmée :
# Réinitialisation valeurs saines SharedPreferences
adb shell "run-as com.example.jarvis sh -c 'cat > /data/data/com.example.jarvis/shared_prefs/jarvis_wake_word_prefs.xml << EOF
<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\" ?>
<map>
<boolean name=\"is_enabled\" value=\"true\" />
<boolean name=\"is_standby\" value=\"false\" />
<boolean name=\"charging_only\" value=\"false\" />
<int name=\"auto_standby_minutes\" value=\"0\" />
<boolean name=\"battery_exemption_requested_by_service\" value=\"false\" />
</map>
EOF'"
# Redémarrer service
adb shell am force-stop com.example.jarvis
adb shell am start -n com.example.jarvis/.MainActivity
Après installation v1.5.10 :
Si popup ne s'affiche pas :
1. Onglet Wake Word dans l'app
2. Carte d'avertissement "Optimisation Batterie"
3. Bouton "Demander exemption batterie"
4. Accepter popup
Tests Ă effectuer :
| Test | Fréquence | Méthode | Cible |
|---|---|---|---|
| Détection wake word écran verrouillé | Toutes les heures | Dire "OK Jarvis" | >95% réussite |
| Latence réveil | Chaque test | Chronomètre entre "OK Jarvis" et réponse | <3s |
| Uptime service | 1x par jour | adb shell dumpsys activity services \| grep uptime |
>23h/24h |
| Crashs service | 1x par jour | adb logcat \| grep "JarvisWakeWordService.*crash" |
0 |
| Exemption batterie | Avant/après reboot | adb shell dumpsys battery optimization \| grep jarvis |
100% persistant |
Court terme (24h) :
- ✅ Exemption batterie accordée et persistante après reboot
- ✅ Détection "OK Jarvis" écran verrouillé >95%
- ✅ Latence réveil <3s
- âś… Aucun crash service
Moyen terme (1 semaine) :
- âś… Uptime service moyen >23h/24h
- ✅ Aucune régression détection wake word
- âś… Consommation batterie acceptable (<5%/jour en veille)
artifacts\DIAGNOSTIC_ECHEC_COMMUNICATION_ARRIERE_PLAN_ANDROID_20261027.mdproject_jarvis_android_arriere_plan_permission_batterie_jamais_demandee_23102026.mdproject_jarvis_android_play_media_false_positive_fix_03102026.mdproject_jarvis_wake_word_android_latence_retard_fix_12102026.mdProblème racine : Flag battery_exemption_requested_by_service empêche toute redemande d'exemption batterie après un premier refus utilisateur, créant une asymétrie critique avec MainActivity (corrigée le 26/10 pour redemander systématiquement).
Correctif prioritaire : Supprimer le check du flag dans JarvisWakeWordService.kt:244-247 + incrémenter version (1.5.9 → 1.5.10).
Correctifs secondaires : Vérifier et corriger configuration SharedPreferences (charging_only=false, auto_standby_minutes=0).
Impact estimé : Résolution de 80-90% des cas d'échec arrière-plan.
Prochaines étapes :
1. Diagnostic ADB immédiat (5 min)
2. Application correctif code si CAUSE #1 confirmée (15 min)
3. Correction configuration si CAUSE #2/3 confirmée (immédiat)
4. Validation sur 24h
Généré le : 2026-10-27 par Claude Code (Sonnet 4.5)
Version cible : Jarvis Android 1.5.10 (versionCode 25)
Fichiers modifiés :
- JarvisWakeWordService.kt (lignes 239-261)
- build.gradle.kts (versionCode + versionName)