• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2019 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4import logging
5
6from autotest_lib.client.common_lib.cros import assistant_util
7# TODO (crbug.com/949874): Remove this when we make sure assistant_util_private
8# is available.
9try:
10    from autotest_lib.client.common_lib.cros import assistant_util_private
11except ImportError:
12    logging.error("Failed to import assistant_util_private")
13
14class AssistantNativeError(Exception):
15    """Error in AssistantFacadeNative."""
16    pass
17
18class AssistantFacadeNative(object):
19    """Facade to access the assistant-related functionality.
20
21    The methods inside this class only accept Python native types.
22
23    """
24    def __init__(self, resource):
25        self._resource = resource
26
27
28    def restart_chrome_for_assistant(self, enable_dsp_hotword=True):
29        """Restarts Chrome with Google assistant enabled.
30
31        @param enable_dsp_hotword: A bool to control the usage of dsp for
32                hotword.
33        """
34        # TODO (paulhsia): Remove this when voice command is ready for non
35        # gaia_login environment.
36        cred = assistant_util_private.get_login_credential()
37        custom_chrome_setup = {
38                "autotest_ext": True,
39                "gaia_login": True,
40                "enable_assistant": True,
41                "username": cred.username,
42                "password": cred.password,
43        }
44
45        if enable_dsp_hotword:
46            custom_chrome_setup["extra_browser_args"] = (
47                ["--enable-features=EnableDspHotword"])
48        self._resource.start_custom_chrome(custom_chrome_setup)
49
50
51    def send_text_query(self, text):
52        """Sends text query to Google assistant and gets response.
53
54        @param text: A str object for text qeury.
55
56        @returns: A str object for query response.
57        """
58        ext = self._resource.get_extension()
59        return assistant_util.send_text_query(ext, text)
60
61
62    def enable_hotword(self):
63        """Enables hotword in Google assistant."""
64        ext = self._resource.get_extension()
65        assistant_util.enable_hotword(ext)
66