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
This commit is contained in:
Aleksandar Kiridzic
2022-12-20 22:47:42 +00:00
committed by Aleksandar Kiridžić
parent 3233852193
commit 03c345ad69
2 changed files with 3 additions and 1 deletions

View File

@@ -2422,6 +2422,7 @@ public class TextToSpeech {
@Override
public void onDisconnected() {
onServiceDisconnected(/* componentName= */ null);
mSession = null;
}
@Override

View File

@@ -83,7 +83,7 @@ final class TextToSpeechManagerPerUserService extends
ServiceConnector.Impl<ITextToSpeechService> {
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;
}
}