def METHOD_NAME(emulator):
    try:
        match = None
        result = subprocess.check_output('"%s" devices' % ADB, shell=True)
        lines = result.splitlines()
        for line in lines[1:]:
            line = str(line, 'utf-8')
            if line:
                if emulator:
                    match = re.search(r'^(emulator-\d+)\s+device$', line)
                else:
                    if re.search(r'^(emulator-\d+)\s+device$', line): # We are emulator
                        continue                                      # Skip it
                    match = re.search(r'^([\w\d]+)\s+device$', line)
                if match:
                    break
        if match:
            return match.group(1)
        return False
    except subprocess.CalledProcessError as e:
        print('Problem checking for devices : status', e.returncode)
        return False