1"""Utilities used by ui_pages module."""
2from typing import Any, Callable, Dict
3
4
5def dr_wakeup_before_op(op: Callable[..., Any]) -> Callable[..., Any]:
6  """Sends keycode 'KEYCODE_WAKEUP' before conducting UI function.
7
8  Args:
9    op: UI function (click, swipe etc.)
10
11  Returns:
12    Wrapped UI function.
13  """
14  def _wrapper(*args: Any, **kargs: Dict[str, Any]) -> Callable[..., Any]:
15    """Wrapper of UI function.
16
17    Args:
18      *args: Argument list passed into UI function.
19      **kargs: key/value argument passed into UI function.
20
21    Returns:
22      The returned result by calling the wrapped UI operation method.
23    """
24
25    ui_page_self = args[0]
26    ui_page_self.ctx.ad.adb.shell(
27        'input keyevent KEYCODE_WAKEUP')
28    return op(*args, **kargs)
29
30  return _wrapper
31