From 03c345ad693feade28b41b9b04e1572c395b9a06 Mon Sep 17 00:00:00 2001 From: Aleksandar Kiridzic Date: Tue, 20 Dec 2022 22:47:42 +0000 Subject: [PATCH] TTS: Fix binders leak due to a circular dependency A circular dependency was found which keeps binders alive even after shutdown: [client] SystemConnection --> SystemConnection#ITextToSpeechSession --> [server] TextToSpeechSessionConnection --> TextToSpeechSessionConnection#ITextToSpeechSessionCallback --> [client] SystemConnection --> ... Anulling SystemConnection#ITextToSpeechSession and TextToSpeechSessionConnection#ITextToSpeechSessionCallback on disconnection should make it available for garbage collection since then no intra-process references would remain. Fix confirmed with ahat. Bug: 233615470 Test: atest Change-Id: I7c9d25b7306d9ce68098c5a6ba0e65711daa3c25 --- core/java/android/speech/tts/TextToSpeech.java | 1 + .../server/texttospeech/TextToSpeechManagerPerUserService.java | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/java/android/speech/tts/TextToSpeech.java b/core/java/android/speech/tts/TextToSpeech.java index 7e8622a0e6946..21b14f4fe7db2 100644 --- a/core/java/android/speech/tts/TextToSpeech.java +++ b/core/java/android/speech/tts/TextToSpeech.java @@ -2422,6 +2422,7 @@ public class TextToSpeech { @Override public void onDisconnected() { onServiceDisconnected(/* componentName= */ null); + mSession = null; } @Override diff --git a/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java index 55cbc7261e648..f5f9b846c38b0 100644 --- a/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java +++ b/services/texttospeech/java/com/android/server/texttospeech/TextToSpeechManagerPerUserService.java @@ -83,7 +83,7 @@ final class TextToSpeechManagerPerUserService extends ServiceConnector.Impl { private final String mEngine; - private final ITextToSpeechSessionCallback mCallback; + private ITextToSpeechSessionCallback mCallback; private final DeathRecipient mUnbindOnDeathHandler; static void start(Context context, @UserIdInt int userId, String engine, @@ -156,6 +156,7 @@ final class TextToSpeechManagerPerUserService extends } catch (NoSuchElementException ex) { Slog.d(TAG, "The death recipient was not linked."); } + mCallback = null; } }