Fix bug 2025765.
Talkback produced a null pointer exception when being enabled and disabled
repeatedly due to a race condition between the onDestroy() of the service,
and the use of the service itself. The error occurs when one Talkback
thread initiates the destruction of the service (call to onDestroy()) when
it invokes shutdown() on its TextToSpeech instance (the client of the
service). At the same time, Talkback tries to say that "Accessibility" is
unchecked from another thread. During onDestroy(), the reference to the
TTS engine (sNativeSynth) is reset to null, which is used in the service
in speakInternalOnly(), and setLanguage().
The fix consists in the addition of a static variable that signals that
the service has entered onDestroy(). Once this flag is set, all method
invocations on sNativeSynth will be dismissed. Note that access to the
native resources used by sNativeSynth are synchronized at the native
layer, therefore preventing sNativeSynth.shutdown() to interfere with
a sNativeSynth.speak() call already underway.
1 file changed