Fix TetheringServiceTest#testTetheringManagerLeak flaky

The clearance of the weak reference to TetheringManager can't be a
confirmation check of the completion running of its finalization.
The weak references to a weakly-reachable object will be cleared
before it becomes eligible for finalization. Calling of
System.runFinalization() method doesn't guarantee finalizers are
executed synchronously. In fact, finalizer of TetheringManager is
running in a different thread in this test.

GCs and finalizers behaviors could be vary on different JVMs.
Due to the unsynchronization, besides the weak reference of
TetheringManager, we need to add retries to the checking of
unregister Tethering internal callback as well.

Bug: 243340454
Test: atest TetheringServiceTest#testTetheringManagerLeak --iterations 10000
Change-Id: I8231146f26deb0825dadb70d8d0dbdc963989558
1 file changed