From 1e2d693a946687bb3b740233bb202d66fd7da43f Mon Sep 17 00:00:00 2001 From: Adam He Date: Thu, 27 Feb 2020 14:10:04 -0800 Subject: [PATCH] Fix explicit intent for instant app tests. Add null checks to ensure RemoteInlineSuggestionRenderService is not being called if service component cannot be found. Fixes: 150315090 Fixes: 150318779 Fixes: 150319014 Fixes: 150039791 Fixes: 150304313 Test: atest CtsAutoFillServiceTestCases --instant Test: atest CtsInputMethodServiceHostTestCases --instant Change-Id: Ie8c84b12a0dc8e7415d94e4edb919de27827b799 --- .../autofill/AutofillManagerServiceImpl.java | 12 +++++++---- .../RemoteAugmentedAutofillService.java | 7 ++++--- .../com/android/server/autofill/Session.java | 20 ++++++++++++++----- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index 872f0eb6657ae..6fbe1410bbad0 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -1650,11 +1650,15 @@ final class AutofillManagerServiceImpl mRemoteInlineSuggestionRenderService = getRemoteInlineSuggestionRenderServiceLocked(); } - RemoteInlineSuggestionRenderService getRemoteInlineSuggestionRenderServiceLocked() { - final ComponentName componentName = RemoteInlineSuggestionRenderService - .getServiceComponentName(getContext(), mUserId); - + @Nullable RemoteInlineSuggestionRenderService getRemoteInlineSuggestionRenderServiceLocked() { if (mRemoteInlineSuggestionRenderService == null) { + final ComponentName componentName = RemoteInlineSuggestionRenderService + .getServiceComponentName(getContext(), mUserId); + if (componentName == null) { + Slog.w(TAG, "No valid component found for InlineSuggestionRenderService"); + return null; + } + mRemoteInlineSuggestionRenderService = new RemoteInlineSuggestionRenderService( getContext(), componentName, InlineSuggestionRenderService.SERVICE_INTERFACE, mUserId, new InlineSuggestionRenderCallbacksImpl(), diff --git a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java index dcc91811905a1..2420e69b5d908 100644 --- a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java +++ b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java @@ -149,7 +149,7 @@ final class RemoteAugmentedAutofillService @Nullable InlineSuggestionsRequest inlineSuggestionsRequest, @Nullable Function inlineSuggestionsCallback, @NonNull Runnable onErrorCallback, - @NonNull RemoteInlineSuggestionRenderService remoteRenderService) { + @Nullable RemoteInlineSuggestionRenderService remoteRenderService) { long requestTime = SystemClock.elapsedRealtime(); AtomicReference cancellationRef = new AtomicReference<>(); @@ -240,9 +240,10 @@ final class RemoteAugmentedAutofillService @Nullable List inlineActions, @NonNull AutofillId focusedId, @Nullable Function inlineSuggestionsCallback, @NonNull IAutoFillManagerClient client, @NonNull Runnable onErrorCallback, - @NonNull RemoteInlineSuggestionRenderService remoteRenderService) { + @Nullable RemoteInlineSuggestionRenderService remoteRenderService) { if (inlineSuggestionsData == null || inlineSuggestionsData.isEmpty() - || inlineSuggestionsCallback == null || request == null) { + || inlineSuggestionsCallback == null || request == null + || remoteRenderService == null) { return; } mCallbacks.setLastResponse(sessionId); diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 6fb65cae24829..7d970ed2c62c9 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -594,8 +594,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState /** * Returns whether inline suggestions are enabled for Autofill. */ - private boolean isInlineSuggestionsEnabled() { - return mService.isInlineSuggestionsEnabled(); + private boolean isInlineSuggestionsEnabledLocked() { + return mService.isInlineSuggestionsEnabled() + || mService.getRemoteInlineSuggestionRenderServiceLocked() != null; } /** @@ -603,7 +604,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState */ private void maybeRequestInlineSuggestionsRequestThenFillLocked(@NonNull ViewState viewState, int newState, int flags) { - if (isInlineSuggestionsEnabled()) { + if (isInlineSuggestionsEnabledLocked()) { mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId); } @@ -2662,6 +2663,14 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState Log.w(TAG, "InlineSuggestionsRequest unavailable"); return false; } + + final RemoteInlineSuggestionRenderService remoteRenderService = + mService.getRemoteInlineSuggestionRenderServiceLocked(); + if (remoteRenderService == null) { + Log.w(TAG, "RemoteInlineSuggestionRenderService not found"); + return false; + } + InlineSuggestionsResponse inlineSuggestionsResponse = InlineSuggestionFactory.createInlineSuggestionsResponse( inlineSuggestionsRequest.get(), @@ -2670,11 +2679,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState synchronized (mLock) { requestHideFillUi(mCurrentViewId); } - }, mService.getRemoteInlineSuggestionRenderServiceLocked()); + }, remoteRenderService); if (inlineSuggestionsResponse == null) { Slog.w(TAG, "InlineSuggestionFactory created null response"); return false; } + return mInlineSuggestionSession.onInlineSuggestionsResponse(mCurrentViewId, inlineSuggestionsResponse); } @@ -2957,7 +2967,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState // 2. standard autofill provider doesn't support inline (and returns null response) // 3. standard autofill provider supports inline, but isn't called because the field // doesn't want autofill - if (mForAugmentedAutofillOnly || !isInlineSuggestionsEnabled()) { + if (mForAugmentedAutofillOnly || !isInlineSuggestionsEnabledLocked()) { if (sDebug) Slog.d(TAG, "Create inline request for augmented autofill"); mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId); }