Add Apps.AppListSearchQueryLength UMA histogram.
[chromium-blink-merge.git] / build / android / pylib / device / device_blacklist.py
bloba141d62b81b828f17a243dbb70adbe8772ddba30
1 # Copyright 2014 The Chromium 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.
5 import json
6 import os
7 import threading
9 from pylib import constants
10 _BLACKLIST_JSON = os.path.join(
11 constants.DIR_SOURCE_ROOT,
12 os.environ.get('CHROMIUM_OUT_DIR', 'out'),
13 'bad_devices.json')
15 # Note that this only protects against concurrent accesses to the blacklist
16 # within a process.
17 _blacklist_lock = threading.RLock()
19 def ReadBlacklist():
20 """Reads the blacklist from the _BLACKLIST_JSON file.
22 Returns:
23 A list containing bad devices.
24 """
25 with _blacklist_lock:
26 if not os.path.exists(_BLACKLIST_JSON):
27 return []
29 with open(_BLACKLIST_JSON, 'r') as f:
30 return json.load(f)
33 def WriteBlacklist(blacklist):
34 """Writes the provided blacklist to the _BLACKLIST_JSON file.
36 Args:
37 blacklist: list of bad devices to write to the _BLACKLIST_JSON file.
38 """
39 with _blacklist_lock:
40 with open(_BLACKLIST_JSON, 'w') as f:
41 json.dump(list(set(blacklist)), f)
44 def ExtendBlacklist(devices):
45 """Adds devices to _BLACKLIST_JSON file.
47 Args:
48 devices: list of bad devices to be added to the _BLACKLIST_JSON file.
49 """
50 with _blacklist_lock:
51 blacklist = ReadBlacklist()
52 blacklist.extend(devices)
53 WriteBlacklist(blacklist)
56 def ResetBlacklist():
57 """Erases the _BLACKLIST_JSON file if it exists."""
58 with _blacklist_lock:
59 if os.path.exists(_BLACKLIST_JSON):
60 os.remove(_BLACKLIST_JSON)