# Copyright 2015 The Swarming Authors. All rights reserved.
# Use of this source code is governed by the Apache v2.0 license that can be
# found in the LICENSE file.

"""Android specific utility functions.

This file serves as an API to bot_config.py. bot_config.py can be replaced on
the server to allow additional server-specific functionality.
"""

import collections
import logging
import os


from adb import adb_commands_safe
from adb import high


def initialize(pub_key, priv_key):
  return high.Initialize(pub_key, priv_key)


def get_devices(bot):
  return high.GetDevices(
      'swarming', 10000, 10000, on_error=bot.post_error if bot else None,
      as_root=True)


def close_devices(devices):
  return high.CloseDevices(devices)

# Copyright 2015 The Swarming Authors. All rights reserved.
# Use of this source code is governed by the Apache v2.0 license that can be
# found in the LICENSE file.

"""Android specific utility functions.

This file serves as an API to bot_config.py. bot_config.py can be replaced on
the server to allow additional server-specific functionality.
"""

import collections
import logging
import os


from adb import adb_commands_safe
from adb import adb_protocol
from adb import common
from adb import high


# Master switch that can easily be temporarily increased to INFO or even DEBUG
# when needed by simply pushing a new tainted swarming server version. This
# helps quickly debugging issues. On the other hand, even INFO level is quite
# verbose so keep it at WARNING by default.
LEVEL = logging.WARNING
adb_commands_safe._LOG.setLevel(LEVEL)
adb_protocol._LOG.setLevel(LEVEL)
common._LOG.setLevel(LEVEL)
high._LOG.setLevel(LEVEL)


def initialize(pub_key, priv_key):
  return high.Initialize(pub_key, priv_key)


def get_devices(bot):
  return high.GetDevices(
      'swarming', 10000, 10000, on_error=bot.post_error if bot else None,
      as_root=True)


def close_devices(devices):
  return high.CloseDevices(devices)


def kill_adb():
  return adb_commands_safe.KillADB()

Add kill_adb() and increase python-adb logging to WARNING.
Add kill_adb() and increase python-adb logging to WARNING.

It gives a master switch that can easily be temporarily increased to INFO or
even DEBUG when needed by simply pushing a new tainted swarming server version.
This helps quickly debugging issues. On the other hand, even INFO level is quite
verbose so keep it at WARNING by default.

Adding kill_adb() is useful, since it's better to forcibly kill adb upfront in
on_after_task() than try to kill it after trying USB enumeration then killing
adb then enumerating again.

R=stip@chromium.org
BUG=chromium:525873

Review URL: https://codereview.chromium.org/1430073003
