Fix memory leak in TCMS when TCSession.destroy() is not called.
TCMS stores sessions in a Map and remove it when the session is
destroyed. Memory leak happens if the client forget to call
TCSession.destroy() or does not have a chance to call before the process
is dead.
Solution:
1. Use linkToDeath() to remove the cached session when client process
is dead. TCSessionID now contains a binder to make this possible.
2. Install a Cleaner to TCSession object such that destroy() is called
whenever the session object is going to be GCed. This is needed
because some clients may have a long lifecycle, e.g. apps that are
bounded by system.
BUG:149012454
Test: Write an app that creates a TC session, but not calling destory().
Then make sure TCMS removed the session in the following situations:
1. The app is killed
2. TCSession object is GCed (By forcing GC)
By checking the output dumpsys textclassificataion, we can know
that the session object is removed
Test: mts-tradefed run mts-extservices
Test: Sanity test: smart selection + smart replies
Change-Id: Ifb7dcb23e1f50d4b3e97a6ce40e63b57193f2892
3 files changed