Commit 6074090c authored by Stephane Zermatten's avatar Stephane Zermatten Committed by Commit Bot

[AA Direct Actions] Small bugfixes.

This change fixes the following small bugs:

- the argument experiment_ids was not declared for the
  list_assistant_actions direct action.

- there was no way for the caller to specify the user account to use for
  RPCs, like there is for AA in CCT, which could mean RPCs could fail
  with 401 in production if the user is not signed into Chrome.
  list_assistant_actions now has a new parameter for that.

- AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn() was
  checked too early, when creating direct action handler, that is, when
  creating the Activity. This meant that if it ever changed during the
  Activity's lifetime, the behavior would be incorrect. This change
  checks it for every call instead.

- If, after showing the onboarding, AA couldn't start, we could end
  up in a state where the onboarding UI was still showing. To solve
  this, this change transfers control of the UI only once AA is
  started. If that doesn't happen, the default behavior of
  OnboardingController triggers, which is to dismiss the UI.

Bug: b/138276953
Change-Id: Ibd6ea42c710dc95fb854eea57d5a0b64a585573d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1720711Reviewed-by: default avatarJordan Demeulenaere <jdemeulenaere@chromium.org>
Commit-Queue: Stephane Zermatten <szermatt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#681765}
parent 75e4793b
...@@ -9,7 +9,6 @@ import android.os.Bundle; ...@@ -9,7 +9,6 @@ import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayCoordinator;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
import org.chromium.chrome.browser.widget.ScrimView; import org.chromium.chrome.browser.widget.ScrimView;
import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController; import org.chromium.chrome.browser.widget.bottomsheet.BottomSheetController;
...@@ -37,8 +36,8 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl ...@@ -37,8 +36,8 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl
} }
@Override @Override
public void listActions( public void listActions(String userName, String experimentIds, Bundle arguments,
String experimentIds, Bundle arguments, Callback<Set<String>> callback) { Callback<Set<String>> callback) {
if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) { if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) {
callback.onResult(Collections.emptySet()); callback.onResult(Collections.emptySet());
return; return;
...@@ -49,7 +48,7 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl ...@@ -49,7 +48,7 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl
return; return;
} }
client.listDirectActions(experimentIds, toArgumentMap(arguments), callback); client.listDirectActions(userName, experimentIds, toArgumentMap(arguments), callback);
} }
@Override @Override
...@@ -71,15 +70,15 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl ...@@ -71,15 +70,15 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl
return; return;
} }
Callback<AssistantOverlayCoordinator> afterOnboarding = (overlayController) -> { Callback<AssistantOnboardingCoordinator> afterOnboarding = (onboardingCoordinator) -> {
Map<String, String> argumentMap = toArgumentMap(arguments); Map<String, String> argumentMap = toArgumentMap(arguments);
if (name.isEmpty()) { if (name.isEmpty()) {
callback.onResult(client.start(/* initialUrl= */ "", argumentMap, experimentIds, callback.onResult(client.start(/* initialUrl= */ "", argumentMap, experimentIds,
Bundle.EMPTY, overlayController)); Bundle.EMPTY, onboardingCoordinator));
return; return;
} }
callback.onResult(client.performDirectAction( callback.onResult(client.performDirectAction(
name, experimentIds, argumentMap, overlayController)); name, experimentIds, argumentMap, onboardingCoordinator));
}; };
if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) { if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) {
...@@ -91,7 +90,7 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl ...@@ -91,7 +90,7 @@ class AutofillAssistantActionHandlerImpl implements AutofillAssistantActionHandl
callback.onResult(false); callback.onResult(false);
return; return;
} }
afterOnboarding.onResult(coordinator.transferControls()); afterOnboarding.onResult(coordinator);
}); });
return; return;
} }
......
...@@ -14,7 +14,6 @@ import org.chromium.base.Callback; ...@@ -14,7 +14,6 @@ import org.chromium.base.Callback;
import org.chromium.base.ContextUtils; import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative; import org.chromium.base.annotations.CalledByNative;
import org.chromium.base.annotations.JNINamespace; import org.chromium.base.annotations.JNINamespace;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayCoordinator;
import org.chromium.components.signin.AccountManagerFacade; import org.chromium.components.signin.AccountManagerFacade;
import org.chromium.components.signin.OAuth2TokenService; import org.chromium.components.signin.OAuth2TokenService;
import org.chromium.content_public.browser.WebContents; import org.chromium.content_public.browser.WebContents;
...@@ -93,7 +92,7 @@ class AutofillAssistantClient { ...@@ -93,7 +92,7 @@ class AutofillAssistantClient {
* @param parameters autobot parameters to set during the whole flow * @param parameters autobot parameters to set during the whole flow
* @param experimentIds comma-separated set of experiments to use while running the flow * @param experimentIds comma-separated set of experiments to use while running the flow
* @param intentExtras extras of the original intent * @param intentExtras extras of the original intent
* @param overlayCoordinator if non-null, reuse existing UI elements, usually created to show * @param onboardingCoordinator if non-null, reuse existing UI elements, usually created to show
* onboarding. * onboarding.
* *
* @return true if the flow was started, false if the controller is in a state where * @return true if the flow was started, false if the controller is in a state where
...@@ -101,14 +100,14 @@ class AutofillAssistantClient { ...@@ -101,14 +100,14 @@ class AutofillAssistantClient {
* still fail after this method returns true; the failure will be displayed on the UI. * still fail after this method returns true; the failure will be displayed on the UI.
*/ */
boolean start(String initialUrl, Map<String, String> parameters, String experimentIds, boolean start(String initialUrl, Map<String, String> parameters, String experimentIds,
Bundle intentExtras, @Nullable AssistantOverlayCoordinator overlayCoordinator) { Bundle intentExtras, @Nullable AssistantOnboardingCoordinator onboardingCoordinator) {
if (mNativeClientAndroid == 0) return false; if (mNativeClientAndroid == 0) return false;
checkNativeClientIsAliveOrThrow(); checkNativeClientIsAliveOrThrow();
chooseAccountAsyncIfNecessary(parameters.get(PARAMETER_USER_EMAIL), intentExtras); chooseAccountAsyncIfNecessary(parameters.get(PARAMETER_USER_EMAIL), intentExtras);
return nativeStart(mNativeClientAndroid, initialUrl, experimentIds, return nativeStart(mNativeClientAndroid, initialUrl, experimentIds,
parameters.keySet().toArray(new String[parameters.size()]), parameters.keySet().toArray(new String[parameters.size()]),
parameters.values().toArray(new String[parameters.size()]), overlayCoordinator, parameters.values().toArray(new String[parameters.size()]), onboardingCoordinator,
AutofillAssistantServiceInjector.getServiceToInject()); AutofillAssistantServiceInjector.getServiceToInject());
} }
...@@ -135,15 +134,14 @@ class AutofillAssistantClient { ...@@ -135,15 +134,14 @@ class AutofillAssistantClient {
} }
/** Lists available direct actions. */ /** Lists available direct actions. */
public void listDirectActions( public void listDirectActions(String userName, String experimentIds,
String experimentIds, Map<String, String> arguments, Callback<Set<String>> callback) { Map<String, String> arguments, Callback<Set<String>> callback) {
if (mNativeClientAndroid == 0) { if (mNativeClientAndroid == 0) {
callback.onResult(Collections.emptySet()); callback.onResult(Collections.emptySet());
return; return;
} }
// TODO(b/134741524): An account shouldn't be necessary to fetch the list of actions. chooseAccountAsyncIfNecessary(userName.isEmpty() ? null : userName, null);
chooseAccountAsyncIfNecessary(null, null);
// The native side calls sendDirectActionList() on the callback once the controller has // The native side calls sendDirectActionList() on the callback once the controller has
// results. // results.
...@@ -158,22 +156,21 @@ class AutofillAssistantClient { ...@@ -158,22 +156,21 @@ class AutofillAssistantClient {
* @param actionId id of the action * @param actionId id of the action
* @param experimentIds comma-separated set of experiments to use while running the flow * @param experimentIds comma-separated set of experiments to use while running the flow
* @param arguments report these as autobot parameters while performing this specific action * @param arguments report these as autobot parameters while performing this specific action
* @param overlayCoordinator if non-null, reuse existing UI elements, usually created to show * @param onboardingcoordinator if non-null, reuse existing UI elements, usually created to show
* onboarding. * onboarding.
* @return true if the action was found started, false otherwise. The action can still fail * @return true if the action was found started, false otherwise. The action can still fail
* after this method returns true; the failure will be displayed on the UI. * after this method returns true; the failure will be displayed on the UI.
*/ */
public boolean performDirectAction(String actionId, String experimentIds, public boolean performDirectAction(String actionId, String experimentIds,
Map<String, String> arguments, @Nullable AssistantOverlayCoordinator overlay) { Map<String, String> arguments,
@Nullable AssistantOnboardingCoordinator onboardingCoordinator) {
if (mNativeClientAndroid == 0) return false; if (mNativeClientAndroid == 0) return false;
// TODO(b/134741524): Define a way of specifying a fallback account, for when the user is // Note that only listDirectActions can start AA, so only it needs
// not signed-in and allow direct actions when not signed in. // chooseAccountAsyncIfNecessary.
chooseAccountAsyncIfNecessary(null, null);
return nativePerformDirectAction(mNativeClientAndroid, actionId, experimentIds, return nativePerformDirectAction(mNativeClientAndroid, actionId, experimentIds,
arguments.keySet().toArray(new String[arguments.size()]), arguments.keySet().toArray(new String[arguments.size()]),
arguments.values().toArray(new String[arguments.size()]), overlay); arguments.values().toArray(new String[arguments.size()]), onboardingCoordinator);
} }
@CalledByNative @CalledByNative
...@@ -330,7 +327,7 @@ class AutofillAssistantClient { ...@@ -330,7 +327,7 @@ class AutofillAssistantClient {
private static native AutofillAssistantClient nativeFromWebContents(WebContents webContents); private static native AutofillAssistantClient nativeFromWebContents(WebContents webContents);
private native boolean nativeStart(long nativeClientAndroid, String initialUrl, private native boolean nativeStart(long nativeClientAndroid, String initialUrl,
String experimentIds, String[] parameterNames, String[] parameterValues, String experimentIds, String[] parameterNames, String[] parameterValues,
@Nullable AssistantOverlayCoordinator overlayCoordinator, long nativeService); @Nullable AssistantOnboardingCoordinator onboardingCoordinator, long nativeService);
private native void nativeOnAccessToken( private native void nativeOnAccessToken(
long nativeClientAndroid, boolean success, String accessToken); long nativeClientAndroid, boolean success, String accessToken);
private native String nativeGetPrimaryAccountName(long nativeClientAndroid); private native String nativeGetPrimaryAccountName(long nativeClientAndroid);
...@@ -340,5 +337,5 @@ class AutofillAssistantClient { ...@@ -340,5 +337,5 @@ class AutofillAssistantClient {
String[] argumentNames, String[] argumentValues, Object callback); String[] argumentNames, String[] argumentValues, Object callback);
private native boolean nativePerformDirectAction(long nativeClientAndroid, String actionId, private native boolean nativePerformDirectAction(long nativeClientAndroid, String actionId,
String experimentId, String[] argumentNames, String[] argumentValues, String experimentId, String[] argumentNames, String[] argumentValues,
@Nullable AssistantOverlayCoordinator overlay); @Nullable AssistantOnboardingCoordinator onboardingCoordinator);
} }
...@@ -43,7 +43,7 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule ...@@ -43,7 +43,7 @@ public class AutofillAssistantModuleEntryImpl implements AutofillAssistantModule
AutofillAssistantClient.fromWebContents(tab.getWebContents()) AutofillAssistantClient.fromWebContents(tab.getWebContents())
.start(initialUrl, parameters, experimentIds, intentExtras, .start(initialUrl, parameters, experimentIds, intentExtras,
onboardingCoordinator.transferControls()); onboardingCoordinator);
}); });
} }
......
...@@ -17,7 +17,6 @@ import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip; ...@@ -17,7 +17,6 @@ import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip;
import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip.Type; import org.chromium.chrome.browser.autofill_assistant.carousel.AssistantChip.Type;
import org.chromium.chrome.browser.autofill_assistant.header.AssistantHeaderModel; import org.chromium.chrome.browser.autofill_assistant.header.AssistantHeaderModel;
import org.chromium.chrome.browser.autofill_assistant.metrics.DropOutReason; import org.chromium.chrome.browser.autofill_assistant.metrics.DropOutReason;
import org.chromium.chrome.browser.autofill_assistant.overlay.AssistantOverlayCoordinator;
import org.chromium.chrome.browser.customtabs.CustomTabActivity; import org.chromium.chrome.browser.customtabs.CustomTabActivity;
import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController; import org.chromium.chrome.browser.snackbar.SnackbarManager.SnackbarController;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
...@@ -84,7 +83,7 @@ class AutofillAssistantUiController { ...@@ -84,7 +83,7 @@ class AutofillAssistantUiController {
@CalledByNative @CalledByNative
private static AutofillAssistantUiController create(ChromeActivity activity, private static AutofillAssistantUiController create(ChromeActivity activity,
boolean allowTabSwitching, long nativeUiController, boolean allowTabSwitching, long nativeUiController,
@Nullable AssistantOverlayCoordinator overlayCoordinator) { @Nullable AssistantOnboardingCoordinator onboardingCoordinator) {
assert activity != null; assert activity != null;
assert activity.getBottomSheetController() != null; assert activity.getBottomSheetController() != null;
...@@ -94,15 +93,16 @@ class AutofillAssistantUiController { ...@@ -94,15 +93,16 @@ class AutofillAssistantUiController {
sActiveChromeActivities.add(activity); sActiveChromeActivities.add(activity);
return new AutofillAssistantUiController(activity, activity.getBottomSheetController(), return new AutofillAssistantUiController(activity, activity.getBottomSheetController(),
allowTabSwitching, nativeUiController, overlayCoordinator); allowTabSwitching, nativeUiController, onboardingCoordinator);
} }
private AutofillAssistantUiController(ChromeActivity activity, BottomSheetController controller, private AutofillAssistantUiController(ChromeActivity activity, BottomSheetController controller,
boolean allowTabSwitching, long nativeUiController, boolean allowTabSwitching, long nativeUiController,
@Nullable AssistantOverlayCoordinator overlayCoordinator) { @Nullable AssistantOnboardingCoordinator onboardingCoordinator) {
mNativeUiController = nativeUiController; mNativeUiController = nativeUiController;
mActivity = activity; mActivity = activity;
mCoordinator = new AssistantCoordinator(activity, controller, overlayCoordinator); mCoordinator = new AssistantCoordinator(activity, controller,
onboardingCoordinator == null ? null : onboardingCoordinator.transferControls());
mActivityTabObserver = mActivityTabObserver =
new ActivityTabProvider.ActivityTabTabObserver(activity.getActivityTabProvider()) { new ActivityTabProvider.ActivityTabTabObserver(activity.getActivityTabProvider()) {
@Override @Override
......
...@@ -25,6 +25,7 @@ import org.junit.Test; ...@@ -25,6 +25,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.chromium.base.Callback; import org.chromium.base.Callback;
import org.chromium.base.ContextUtils;
import org.chromium.base.ThreadUtils; import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CallbackHelper; import org.chromium.base.test.util.CallbackHelper;
import org.chromium.base.test.util.CommandLineFlags; import org.chromium.base.test.util.CommandLineFlags;
...@@ -70,14 +71,16 @@ public class AutofillAssistantDirectActionHandlerTest { ...@@ -70,14 +71,16 @@ public class AutofillAssistantDirectActionHandlerTest {
mActivity.getScrim(), mActivity.getTabModelSelector()::getCurrentTab, mActivity.getScrim(), mActivity.getTabModelSelector()::getCurrentTab,
mModuleEntryProvider); mModuleEntryProvider);
AutofillAssistantPreferencesUtil.setInitialPreferences(false); ContextUtils.getAppSharedPreferences()
.edit()
.remove(AutofillAssistantPreferencesUtil.AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED)
.remove(AutofillAssistantPreferencesUtil.AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN)
.apply();
} }
@Test @Test
@MediumTest @MediumTest
public void testReportAvailableDirectActions() throws Exception { public void testReportAvailableDirectActions() throws Exception {
AutofillAssistantPreferencesUtil.setInitialPreferences(false);
FakeDirectActionReporter reporter = new FakeDirectActionReporter(); FakeDirectActionReporter reporter = new FakeDirectActionReporter();
mHandler.reportAvailableDirectActions(reporter); mHandler.reportAvailableDirectActions(reporter);
...@@ -85,7 +88,14 @@ public class AutofillAssistantDirectActionHandlerTest { ...@@ -85,7 +88,14 @@ public class AutofillAssistantDirectActionHandlerTest {
FakeDirectActionDefinition list = reporter.mActions.get(0); FakeDirectActionDefinition list = reporter.mActions.get(0);
assertEquals("list_assistant_actions", list.mId); assertEquals("list_assistant_actions", list.mId);
assertThat(list.mParameters, empty()); assertEquals(2, list.mParameters.size());
assertEquals("user_name", list.mParameters.get(0).mName);
assertEquals(Type.STRING, list.mParameters.get(0).mType);
assertEquals(false, list.mParameters.get(0).mRequired);
assertEquals("experiment_ids", list.mParameters.get(1).mName);
assertEquals(Type.STRING, list.mParameters.get(1).mType);
assertEquals(false, list.mParameters.get(1).mRequired);
assertEquals(1, list.mResults.size()); assertEquals(1, list.mResults.size());
assertEquals("names", list.mResults.get(0).mName); assertEquals("names", list.mResults.get(0).mName);
assertEquals(Type.STRING, list.mResults.get(0).mType); assertEquals(Type.STRING, list.mResults.get(0).mType);
...@@ -132,6 +142,15 @@ public class AutofillAssistantDirectActionHandlerTest { ...@@ -132,6 +142,15 @@ public class AutofillAssistantDirectActionHandlerTest {
acceptOnboarding(); acceptOnboarding();
} }
@Test
@MediumTest
public void testSwitchedOffInPreferences() throws Exception {
AutofillAssistantPreferencesUtil.setInitialPreferences(false);
assertThat(listActions(), empty());
assertFalse(performAction("onboarding", Bundle.EMPTY));
}
private void acceptOnboarding() throws Exception { private void acceptOnboarding() throws Exception {
WaitingCallback<Boolean> onboardingCallback = WaitingCallback<Boolean> onboardingCallback =
performActionAsync("onboarding", Bundle.EMPTY); performActionAsync("onboarding", Bundle.EMPTY);
...@@ -147,10 +166,10 @@ public class AutofillAssistantDirectActionHandlerTest { ...@@ -147,10 +166,10 @@ public class AutofillAssistantDirectActionHandlerTest {
/** Calls list_assistant_actions and returns the result. */ /** Calls list_assistant_actions and returns the result. */
private List<String> listActions() throws Exception { private List<String> listActions() throws Exception {
WaitingCallback<Bundle> callback = new WaitingCallback<Bundle>(); WaitingCallback<Bundle> callback = new WaitingCallback<Bundle>();
ThreadUtils.runOnUiThreadBlocking( assertTrue(ThreadUtils.runOnUiThreadBlocking(
() ()
-> mHandler.performDirectAction( -> mHandler.performDirectAction(
"list_assistant_actions", Bundle.EMPTY, callback)); "list_assistant_actions", Bundle.EMPTY, callback)));
return Arrays.asList(TextUtils.split( return Arrays.asList(TextUtils.split(
callback.waitForResult("list_assistant_actions").getString("names", ""), ",")); callback.waitForResult("list_assistant_actions").getString("names", ""), ","));
} }
......
...@@ -20,10 +20,13 @@ public interface AutofillAssistantActionHandler { ...@@ -20,10 +20,13 @@ public interface AutofillAssistantActionHandler {
* <p>This method starts AA on the current tab, if necessary, and waits for the first results. * <p>This method starts AA on the current tab, if necessary, and waits for the first results.
* Once AA is started, the results are reported immediately. * Once AA is started, the results are reported immediately.
* *
* @param arguments extra arguments * @param userName name of the user to use when sending RPCs. Might be empty.
* @param experimentIds comma-separated set of experiment ids. Might be empty
* @param arguments extra arguments to include into the RPC. Might be empty.
* @param callback callback to report the result to * @param callback callback to report the result to
*/ */
void listActions(String experimentIds, Bundle arguments, Callback<Set<String>> callback); void listActions(String userName, String experimentIds, Bundle arguments,
Callback<Set<String>> callback);
/** Performs onboarding and returns the result to the callback. */ /** Performs onboarding and returns the result to the callback. */
void performOnboarding(String experimentIds, Callback<Boolean> callback); void performOnboarding(String experimentIds, Callback<Boolean> callback);
...@@ -35,8 +38,8 @@ public interface AutofillAssistantActionHandler { ...@@ -35,8 +38,8 @@ public interface AutofillAssistantActionHandler {
* It can still fail later, and the failure will be reported to the UI. * It can still fail later, and the failure will be reported to the UI.
* *
* @param name action name, might be empty to autostart * @param name action name, might be empty to autostart
* @param experimentIds experiment ids, might be empty * @param experimentIds comma-separated set of experiment ids. Might be empty.
* @param arguments extra arguments * @param arguments extra arguments to pass to the action. Might be empty.
* @param callback to report the result to * @param callback to report the result to
*/ */
void performAction( void performAction(
......
...@@ -32,6 +32,7 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler ...@@ -32,6 +32,7 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler
private static final String ACTION_NAME = "name"; private static final String ACTION_NAME = "name";
private static final String EXPERIMENT_IDS = "experiment_ids"; private static final String EXPERIMENT_IDS = "experiment_ids";
private static final String ONBOARDING_ACTION = "onboarding"; private static final String ONBOARDING_ACTION = "onboarding";
private static final String USER_NAME = "user_name";
/** /**
* Set of actions to report when AA is not available, because of preference or * Set of actions to report when AA is not available, because of preference or
...@@ -60,7 +61,12 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler ...@@ -60,7 +61,12 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler
@Override @Override
public void reportAvailableDirectActions(DirectActionReporter reporter) { public void reportAvailableDirectActions(DirectActionReporter reporter) {
reporter.addDirectAction(LIST_AA_ACTIONS).withResult(LIST_AA_ACTIONS_RESULT, Type.STRING); if (!AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()) return;
reporter.addDirectAction(LIST_AA_ACTIONS)
.withParameter(USER_NAME, Type.STRING, /* required= */ false)
.withParameter(EXPERIMENT_IDS, Type.STRING, /* required= */ false)
.withResult(LIST_AA_ACTIONS_RESULT, Type.STRING);
reporter.addDirectAction(PERFORM_AA_ACTION) reporter.addDirectAction(PERFORM_AA_ACTION)
.withParameter(ACTION_NAME, Type.STRING, /* required= */ false) .withParameter(ACTION_NAME, Type.STRING, /* required= */ false)
...@@ -89,11 +95,19 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler ...@@ -89,11 +95,19 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler
bundleCallback.onResult(bundle); bundleCallback.onResult(bundle);
}; };
if (!AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()) {
namesCallback.onResult(Collections.emptySet());
return;
}
if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) { if (!AutofillAssistantPreferencesUtil.isAutofillOnboardingAccepted()) {
namesCallback.onResult(FALLBACK_ACTION_SET); namesCallback.onResult(FALLBACK_ACTION_SET);
return; return;
} }
String userName = arguments.getString(USER_NAME, "");
arguments.remove(USER_NAME);
String experimentIds = arguments.getString(EXPERIMENT_IDS, ""); String experimentIds = arguments.getString(EXPERIMENT_IDS, "");
arguments.remove(EXPERIMENT_IDS); arguments.remove(EXPERIMENT_IDS);
...@@ -102,7 +116,7 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler ...@@ -102,7 +116,7 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler
namesCallback.onResult(FALLBACK_ACTION_SET); namesCallback.onResult(FALLBACK_ACTION_SET);
return; return;
} }
delegate.listActions(experimentIds, arguments, namesCallback); delegate.listActions(userName, experimentIds, arguments, namesCallback);
}); });
} }
...@@ -112,6 +126,12 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler ...@@ -112,6 +126,12 @@ public class AutofillAssistantDirectActionHandler implements DirectActionHandler
bundle.putBoolean(PERFORM_AA_ACTION_RESULT, result); bundle.putBoolean(PERFORM_AA_ACTION_RESULT, result);
bundleCallback.onResult(bundle); bundleCallback.onResult(bundle);
}; };
if (!AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()) {
booleanCallback.onResult(false);
return;
}
String name = arguments.getString(ACTION_NAME, ""); String name = arguments.getString(ACTION_NAME, "");
arguments.remove(ACTION_NAME); arguments.remove(ACTION_NAME);
......
...@@ -134,7 +134,6 @@ public class AutofillAssistantFacade { ...@@ -134,7 +134,6 @@ public class AutofillAssistantFacade {
public static boolean areDirectActionsAvailable(@ActivityType int activityType) { public static boolean areDirectActionsAvailable(@ActivityType int activityType) {
return BuildInfo.isAtLeastQ() return BuildInfo.isAtLeastQ()
&& (activityType == ActivityType.CUSTOM_TAB || activityType == ActivityType.TABBED) && (activityType == ActivityType.CUSTOM_TAB || activityType == ActivityType.TABBED)
&& AutofillAssistantPreferencesUtil.isAutofillAssistantSwitchOn()
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT_DIRECT_ACTIONS) && ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT_DIRECT_ACTIONS)
&& ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT); && ChromeFeatureList.isEnabled(ChromeFeatureList.AUTOFILL_ASSISTANT);
} }
......
...@@ -15,12 +15,12 @@ class AutofillAssistantPreferencesUtil { ...@@ -15,12 +15,12 @@ class AutofillAssistantPreferencesUtil {
/** Peference keeping track of whether the onboarding has been accepted. */ /** Peference keeping track of whether the onboarding has been accepted. */
@VisibleForTesting @VisibleForTesting
public static final String AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED = static final String AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED =
"AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED"; "AUTOFILL_ASSISTANT_ONBOARDING_ACCEPTED";
/** LEGACY preference for when the `do not show again' checkbox still existed. */ /** LEGACY preference for when the `do not show again' checkbox still existed. */
private static final String AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN = @VisibleForTesting
"AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN"; static final String AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN = "AUTOFILL_ASSISTANT_SKIP_INIT_SCREEN";
/** Checks whether the Autofill Assistant switch preference in settings is on. */ /** Checks whether the Autofill Assistant switch preference in settings is on. */
static boolean isAutofillAssistantSwitchOn() { static boolean isAutofillAssistantSwitchOn() {
......
...@@ -129,7 +129,7 @@ bool ClientAndroid::Start(JNIEnv* env, ...@@ -129,7 +129,7 @@ bool ClientAndroid::Start(JNIEnv* env,
const JavaParamRef<jstring>& jexperiment_ids, const JavaParamRef<jstring>& jexperiment_ids,
const JavaParamRef<jobjectArray>& parameter_names, const JavaParamRef<jobjectArray>& parameter_names,
const JavaParamRef<jobjectArray>& parameter_values, const JavaParamRef<jobjectArray>& parameter_values,
const JavaParamRef<jobject>& joverlay_coordinator, const JavaParamRef<jobject>& jonboarding_coordinator,
jlong jservice) { jlong jservice) {
// When Start() is called, AA_START should have been measured. From now on, // When Start() is called, AA_START should have been measured. From now on,
// the client is responsible for keeping track of dropouts, so that for each // the client is responsible for keeping track of dropouts, so that for each
...@@ -143,8 +143,8 @@ bool ClientAndroid::Start(JNIEnv* env, ...@@ -143,8 +143,8 @@ bool ClientAndroid::Start(JNIEnv* env,
CreateController(std::move(service)); CreateController(std::move(service));
// If an overlay is already shown, then show the rest of the UI. // If an overlay is already shown, then show the rest of the UI.
if (joverlay_coordinator) { if (jonboarding_coordinator) {
AttachUI(joverlay_coordinator); AttachUI(jonboarding_coordinator);
} }
std::unique_ptr<TriggerContextImpl> trigger_context = CreateTriggerContext( std::unique_ptr<TriggerContextImpl> trigger_context = CreateTriggerContext(
...@@ -257,7 +257,7 @@ bool ClientAndroid::PerformDirectAction( ...@@ -257,7 +257,7 @@ bool ClientAndroid::PerformDirectAction(
const base::android::JavaParamRef<jstring>& jexperiment_ids, const base::android::JavaParamRef<jstring>& jexperiment_ids,
const base::android::JavaParamRef<jobjectArray>& jargument_names, const base::android::JavaParamRef<jobjectArray>& jargument_names,
const base::android::JavaParamRef<jobjectArray>& jargument_values, const base::android::JavaParamRef<jobjectArray>& jargument_values,
const base::android::JavaParamRef<jobject>& joverlay_coordinator) { const base::android::JavaParamRef<jobject>& jonboarding_coordinator) {
std::string action_name = std::string action_name =
base::android::ConvertJavaStringToUTF8(env, jaction_name); base::android::ConvertJavaStringToUTF8(env, jaction_name);
...@@ -278,8 +278,8 @@ bool ClientAndroid::PerformDirectAction( ...@@ -278,8 +278,8 @@ bool ClientAndroid::PerformDirectAction(
return false; return false;
// If an overlay is already shown, then show the rest of the UI immediately. // If an overlay is already shown, then show the rest of the UI immediately.
if (joverlay_coordinator) { if (jonboarding_coordinator) {
AttachUI(joverlay_coordinator); AttachUI(jonboarding_coordinator);
} }
return controller_->PerformUserActionWithContext(action_index, return controller_->PerformUserActionWithContext(action_index,
...@@ -313,10 +313,10 @@ void ClientAndroid::AttachUI() { ...@@ -313,10 +313,10 @@ void ClientAndroid::AttachUI() {
} }
void ClientAndroid::AttachUI( void ClientAndroid::AttachUI(
const JavaParamRef<jobject>& joverlay_coordinator) { const JavaParamRef<jobject>& jonboarding_coordinator) {
if (!ui_controller_android_) { if (!ui_controller_android_) {
ui_controller_android_ = UiControllerAndroid::CreateFromWebContents( ui_controller_android_ = UiControllerAndroid::CreateFromWebContents(
web_contents_, joverlay_coordinator); web_contents_, jonboarding_coordinator);
if (!ui_controller_android_) { if (!ui_controller_android_) {
// The activity is not or not yet in a mode where attaching the UI is // The activity is not or not yet in a mode where attaching the UI is
// possible. // possible.
......
...@@ -38,14 +38,15 @@ class ClientAndroid : public Client, ...@@ -38,14 +38,15 @@ class ClientAndroid : public Client,
// Returns the corresponding Java AutofillAssistantClient. // Returns the corresponding Java AutofillAssistantClient.
base::android::ScopedJavaLocalRef<jobject> GetJavaObject(); base::android::ScopedJavaLocalRef<jobject> GetJavaObject();
bool Start(JNIEnv* env, bool Start(
const base::android::JavaParamRef<jobject>& jcaller, JNIEnv* env,
const base::android::JavaParamRef<jstring>& jinitial_url, const base::android::JavaParamRef<jobject>& jcaller,
const base::android::JavaParamRef<jstring>& jexperiment_ids, const base::android::JavaParamRef<jstring>& jinitial_url,
const base::android::JavaParamRef<jobjectArray>& parameter_names, const base::android::JavaParamRef<jstring>& jexperiment_ids,
const base::android::JavaParamRef<jobjectArray>& parameter_values, const base::android::JavaParamRef<jobjectArray>& parameter_names,
const base::android::JavaParamRef<jobject>& joverlay_coordinator, const base::android::JavaParamRef<jobjectArray>& parameter_values,
jlong jservice); const base::android::JavaParamRef<jobject>& jonboarding_coordinator,
jlong jservice);
void DestroyUI(JNIEnv* env, void DestroyUI(JNIEnv* env,
const base::android::JavaParamRef<jobject>& jcaller); const base::android::JavaParamRef<jobject>& jcaller);
void TransferUITo( void TransferUITo(
...@@ -76,7 +77,7 @@ class ClientAndroid : public Client, ...@@ -76,7 +77,7 @@ class ClientAndroid : public Client,
const base::android::JavaParamRef<jstring>& jexperiment_ids, const base::android::JavaParamRef<jstring>& jexperiment_ids,
const base::android::JavaParamRef<jobjectArray>& jargument_names, const base::android::JavaParamRef<jobjectArray>& jargument_names,
const base::android::JavaParamRef<jobjectArray>& jargument_values, const base::android::JavaParamRef<jobjectArray>& jargument_values,
const base::android::JavaParamRef<jobject>& joverlay_coordinator); const base::android::JavaParamRef<jobject>& jonboarding_coordinator);
// Overrides Client // Overrides Client
void AttachUI() override; void AttachUI() override;
...@@ -102,7 +103,7 @@ class ClientAndroid : public Client, ...@@ -102,7 +103,7 @@ class ClientAndroid : public Client,
void CreateController(std::unique_ptr<Service> service); void CreateController(std::unique_ptr<Service> service);
void DestroyController(); void DestroyController();
void AttachUI( void AttachUI(
const base::android::JavaParamRef<jobject>& joverlay_coordinator); const base::android::JavaParamRef<jobject>& jonboarding_coordinator);
bool NeedsUI(); bool NeedsUI();
void OnListDirectActions(const base::android::JavaRef<jobject>& jcallback); void OnListDirectActions(const base::android::JavaRef<jobject>& jcallback);
......
...@@ -41,7 +41,7 @@ class UiControllerAndroid : public ControllerObserver { ...@@ -41,7 +41,7 @@ class UiControllerAndroid : public ControllerObserver {
public: public:
static std::unique_ptr<UiControllerAndroid> CreateFromWebContents( static std::unique_ptr<UiControllerAndroid> CreateFromWebContents(
content::WebContents* web_contents, content::WebContents* web_contents,
const base::android::JavaParamRef<jobject>& joverlay_coordinator); const base::android::JavaParamRef<jobject>& jonboarding_coordinator);
// pointers to |web_contents|, |client| must remain valid for the lifetime of // pointers to |web_contents|, |client| must remain valid for the lifetime of
// this instance. // this instance.
...@@ -51,7 +51,7 @@ class UiControllerAndroid : public ControllerObserver { ...@@ -51,7 +51,7 @@ class UiControllerAndroid : public ControllerObserver {
UiControllerAndroid( UiControllerAndroid(
JNIEnv* env, JNIEnv* env,
const base::android::JavaRef<jobject>& jactivity, const base::android::JavaRef<jobject>& jactivity,
const base::android::JavaParamRef<jobject>& joverlay_coordinator); const base::android::JavaParamRef<jobject>& jonboarding_coordinator);
~UiControllerAndroid() override; ~UiControllerAndroid() override;
// Attaches the UI to the given client, its web contents and delegate. // Attaches the UI to the given client, its web contents and delegate.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment