From d21d3ddfef460635d10c6f7678b48f6920c34cd9 Mon Sep 17 00:00:00 2001 From: Joanne Date: Sat, 13 Aug 2022 00:07:06 +0800 Subject: Fix InlineSuggestionRenderService service connection leakage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The system reset the remote InlineRenderService and binds service when updateLocked() is called but the system doesn’t unbind it. The updatedLocked() will be called in many conditions like service change, autofill device config change, etc. These behaviors will occur during the test that causes the connection to increase more and more. To fix the issue, we don't reset the remote InlineRenderService and only bind the service if it doesn't be set yet and unbind it after per user service implementation destroyed. Bug: 242097472 Test: run cts and run command “dumpsys activity services com.google.android.ext.services”. The connection is the same after CTS is done. Test: atest android.autofillservice.cts.inline Test: atest android.autofillservice.cts.dropdown Test: manul. Test some top apps, the inline still works. Test: manual. Test with test app, the dropdown still works. Change-Id: Ia51ef58b1cc1926385c501c34bd756f7c223b313 --- .../server/autofill/AutofillManagerServiceImpl.java | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index fe85db286fa8..5a35474207f7 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -231,7 +231,7 @@ final class AutofillManagerServiceImpl sendStateToClients(/* resetClient= */ false); } updateRemoteAugmentedAutofillService(); - updateRemoteInlineSuggestionRenderServiceLocked(); + getRemoteInlineSuggestionRenderServiceLocked(); return enabledChanged; } @@ -685,8 +685,12 @@ final class AutofillManagerServiceImpl @GuardedBy("mLock") void resetExtServiceLocked() { - if (sVerbose) Slog.v(TAG, "reset autofill service."); + if (sVerbose) Slog.v(TAG, "reset autofill service in ExtServices."); mFieldClassificationStrategy.reset(); + if (mRemoteInlineSuggestionRenderService != null) { + mRemoteInlineSuggestionRenderService.destroy(); + mRemoteInlineSuggestionRenderService = null; + } } @GuardedBy("mLock") @@ -1583,18 +1587,6 @@ final class AutofillManagerServiceImpl return mFieldClassificationStrategy.getDefaultAlgorithm(); } - private void updateRemoteInlineSuggestionRenderServiceLocked() { - if (mRemoteInlineSuggestionRenderService != null) { - if (sVerbose) { - Slog.v(TAG, "updateRemoteInlineSuggestionRenderService(): " - + "destroying old remote service"); - } - mRemoteInlineSuggestionRenderService = null; - } - - mRemoteInlineSuggestionRenderService = getRemoteInlineSuggestionRenderServiceLocked(); - } - @Nullable RemoteInlineSuggestionRenderService getRemoteInlineSuggestionRenderServiceLocked() { if (mRemoteInlineSuggestionRenderService == null) { final ComponentName componentName = RemoteInlineSuggestionRenderService -- cgit v1.2.3-59-g8ed1b