Git Product home page Git Product logo

python-adb's Introduction

python-adb

Coverage Status Build Status

Note: This is not an official Google project. It is maintained by ex-Google engineers. For a better maintained option, look at adb_shell.

This repository contains a pure-python implementation of the ADB and Fastboot protocols, using libusb1 for USB communications.

This is a complete replacement and rearchitecture of the Android project's ADB and fastboot code

This code is mainly targeted to users that need to communicate with Android devices in an automated fashion, such as in automated testing. It does not have a daemon between the client and the device, and therefore does not support multiple simultaneous commands to the same device. It does support any number of devices and never communicates with a device that it wasn't intended to, unlike the Android project's ADB.

Using as standalone tool

Install using pip:

pip install adb

Once installed, two new binaries should be available: pyadb and pyfastboot.

pyadb devices
pyadb shell ls /sdcard

Running ./make_tools.py creates two files: adb.zip and fastboot.zip. They can be run similar to native adb and fastboot via the python interpreter:

python adb.zip devices
python adb.zip shell ls /sdcard

Using as a Python Library

A presentation was made at PyCon 2016, and here's some demo code:

import os.path as op

from adb import adb_commands
from adb import sign_cryptography


# KitKat+ devices require authentication
signer = sign_cryptography.CryptographySigner(
    op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands()
device.ConnectDevice(
    rsa_keys=[signer])
# Now we can use Shell, Pull, Push, etc!
for i in xrange(10):
  print device.Shell('echo %d' % i)

Pros

  • Simpler code due to use of libusb1 and Python.
  • API can be used by other Python code easily.
  • Errors are propagated with tracebacks, helping debug connectivity issues.
  • No daemon outliving the command.
  • Can be packaged as standalone zips that can be run independent of the CPU architecture (e.g. x86 vs ARM).

Cons

  • Technically slower due to Python, mitigated by no daemon.
  • Only one command per device at a time.
  • More dependencies than Android's ADB.

Dependencies

  • libusb1 (1.0.16+)
  • python-libusb1 (1.2.0+)
  • adb.zip: one of:
    • py-cryptography
    • python-rsa (3.2+)
  • fastboot.zip (optional):
    • python-progressbar (2.3+)

History

1.0.0

  • Initial version

1.1.0

  • Added TcpHandle (jameyhicks)
  • Various timing and other changes (alusco)

1.2.0

  • Update to libusb1 1.6+ (bytearray output)
  • Add support for Python 3.6
  • Create adb.zip and fastboot.zip as executable tools.
  • Add Travis CI integration
  • Support multiple crypto libraries (M2Crypto + python-rsa)
  • Push directories

1.3.0

Backwards Incompatible changes

adb_commands.AdbCommands() is now a normal class rather than a collection of staticmethods. Using the following example code to get started:

device = adb_commands.AdbCommands()
device.ConnectDevice(rsa_keys=[signer])
Other changes/fixes

Many changes since 1.2.0!

  • New entrypoints exposed by pip: pyadb and pyfastboot
  • Lots of Python 2/3 compatibility fixes
  • Windows compatibility fixes
  • Transfer progress available (Push, Pull, Install)
  • Handle some misbehaving devices (double CLSE bug)
  • New options for Push and Install (st_mode and grant_permissions)

python-adb's People

Contributors

alusco avatar bif-g avatar delijati avatar fahhem avatar farthornas avatar fgervais avatar fmborghino avatar greateggsgreg avatar halastra avatar jameyhicks avatar jefflirion avatar llliuyx avatar maruel avatar mohammadag avatar sytone avatar tgalal avatar tormath1 avatar tuxuser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-adb's Issues

Protocol: AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

Hi,

I will get an error, when I run two error command:

Like this:

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto


# KitKat+ devices require authentication
signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands.ConnectDevice(
    rsa_keys=[signer])
# Now we can use Shell, Pull, Push, etc!
# for i in xrange(10):
#   print device.Shell('echo %d' % i)

print device.Shell('ls 333')
print device.Shell('ls 222')
print device.Shell('ls 111')
device.Close()

result:

/usr/bin/python2.7 /home/ligf/PycharmProjects/test-adb/tmp.py
ls: 333: No such file or directory
Traceback (most recent call last):

  File "/home/ligf/PycharmProjects/test-adb/tmp.py", line 18, in <module>
    print device.Shell('ls 222')
  File "build/bdist.linux-x86_64/egg/adb/adb_commands.py", line 227, in Shell
  File "build/bdist.linux-x86_64/egg/adb/adb_protocol.py", line 377, in Command
  File "build/bdist.linux-x86_64/egg/adb/adb_protocol.py", line 405, in StreamingCommand
AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

Process finished with exit code 1

It may be a bug at here:
adb_protocol.py

    if cmd == b'CLSE':
      # Device doesn't support this service.
      return None
    if cmd != b'OKAY':
      raise InvalidCommandError('Expected a ready response, got %s' % cmd,
                                cmd, (remote_id, their_local_id))
    return _AdbConnection(usb, local_id, remote_id, timeout_ms)

BRs
/Eismog

USB1 USBErrorNotSupported: LIBUSB_ERROR_NOT_SUPPORTED [-12]

Running the following code on Win10, using pypi 1.2 package (I had to install manually LibUsb1 and copied the LibUSB1-0.dll to local directory):

    import os.path as op
    from adb import adb_commands
    from adb import sign_m2crypto

    #KitKat+ devices require authentication
    signer = sign_m2crypto.M2CryptoSigner(op.expanduser("~/.android/adbkey"))
    # Connect to the device
    device = adb_commands.AdbCommands(None, None)
    # device.ConnectDevice()
    device.ConnectDevice(rsa_keys=[signer])

Gives me the following error:
Traceback (most recent call last):
File "C:\Users\baruchl\AppData\Local\JetBrains\Toolbox\apps\PyCharm-C\ch-0\173.4301.16\helpers\pydev\pydev_run_in_console.py", line 53, in run_file
pydev_imports.execfile(file, globals, locals) # execute the script
File "C:/Users/baruchl/Documents/_GIT/VAL_LAB/VAL_LAB/adb_helper.py", line 184, in
main()
File "C:/Users/baruchl/Documents/GIT/VAL_LAB/VAL_LAB/adb_helper.py", line 156, in main
try_adb_python() #do not use till ADB python issue resolved
File "C:/Users/baruchl/Documents/GIT/VAL_LAB/VAL_LAB/adb_helper.py", line 29, in try_adb_python
device.ConnectDevice(rsa_keys=[signer])
File "C:\Users\baruchl\PycharmProjects\VAL_LAB\venv\lib\site-packages\adb\adb_commands.py", line 75, in ConnectDevice
timeout_ms=default_timeout_ms)
File "C:\Users\baruchl\PycharmProjects\VAL_LAB\venv\lib\site-packages\adb\common.py", line 211, in FindAndOpen
dev.Open()
File "C:\Users\baruchl\PycharmProjects\VAL_LAB\venv\lib\site-packages\adb\common.py", line 115, in Open
if handle.kernelDriverActive(iface_number):
File "C:\Users\baruchl\PycharmProjects\VAL_LAB\venv\lib\site-packages\usb1_init
.py", line 1321, in kernelDriverActive
raiseUSBError(result)
File "C:\Users\baruchl\PycharmProjects\TM2_VAL_LAB\venv\lib\site-packages\usb1_init
.py", line 125, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
USBErrorNotSupported: LIBUSB_ERROR_NOT_SUPPORTED [-12]

Another strange issue is that if I run adb_commands.AdbCommands(None, None) with no arguments as described in the readme file, I get a the following error:
'init() takes exactly 3 arguments (1 given)'

undefined symbol: sslv3_method

After tweaking this library to get past the non-existant python3 class of basestring, i've run into another issue.

In [6]: from adb import sign_m2crypto
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-6-f9a280645ee6> in <module>()
----> 1 from adb import sign_m2crypto

~/.virtualenvs/frida/lib/python3.5/site-packages/adb/sign_m2crypto.py in <module>()
     13 # limitations under the License.
     14
---> 15 from M2Crypto import RSA
     16
     17 from adb import adb_protocol

~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/__init__.py in <module>()
     24 version_info = StrictVersion(__version__).version
     25
---> 26 from M2Crypto import (ASN1, AuthCookie, BIO, BN, DH, DSA, EVP, Engine, Err,
     27                       PGP, RSA, Rand, SMIME, SSL, X509, m2crypto,
     28                       ftpslib, httpslib, m2, m2urllib, m2xmlrpclib,
~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/ASN1.py in <module>()
     13 import time
     14
---> 15 from M2Crypto import BIO, m2, util
     16 if util.py27plus:
     17     from typing import Any, Callable, Optional, Tuple  # noqa

~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/BIO.py in <module>()
      8 import io  # noqa
      9
---> 10 from M2Crypto import m2, six, util
     11 if util.py27plus:
     12     from typing import AnyStr, Callable, Iterable, Optional, Union  # noqa

~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/m2.py in <module>()
     28 """
     29
---> 30 from M2Crypto.m2crypto import *
     31 lib_init()

~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/m2crypto.py in <module>()
     24                 fp.close()
     25             return _mod
---> 26     _m2crypto = swig_import_helper()
     27     del swig_import_helper
     28 else:

~/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/m2crypto.py in swig_import_helper()
     20         if fp is not None:
     21             try:
---> 22                 _mod = imp.load_module('_m2crypto', fp, pathname, description)
     23             finally:
     24                 fp.close()

~/.virtualenvs/frida/lib/python3.5/imp.py in load_module(name, file, filename, details)
    240                 return load_dynamic(name, filename, opened_file)
    241         else:
--> 242             return load_dynamic(name, filename, file)
    243     elif type_ == PKG_DIRECTORY:
    244         return load_package(name, filename)

~/.virtualenvs/frida/lib/python3.5/imp.py in load_dynamic(name, path, file)
    340         spec = importlib.machinery.ModuleSpec(
    341             name=name, loader=loader, origin=path)
--> 342         return _load(spec)
    343
    344 else:

ImportError: /home/user/.virtualenvs/frida/lib/python3.5/site-packages/M2Crypto/_m2crypto.cpython-35m-x86_64-linux-gnu.so: undefined symbol: sslv3_method

TCP Only Version

Is it possible to make a version that only has adb over network support without libusb and all the other libs? I was also wondering if it's possible for a pycrypto or pycryptodome port of the signer.

usb1.USBErrorNoDevice: LIBUSB_ERROR_NO_DEVICE [-4]

branch:master(bed1a53)
libusb1:1.6.4
os:centos7

When I run the command adb devices, it is no problem:

$ adb devices
List of devices attached
00d7d4dc428cab55        device

But When I run command sudo python adb.zip devices,it throw the error:

# python adb.zip devices
00d7d4dc428cab55        device
Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "adb.zip/__main__.py", line 178, in <module>
  File "adb.zip/__main__.py", line 161, in main
  File "adb.zip/__main__.py", line 52, in Devices
  File "adb.zip/adb/common.py", line 133, in serial_number
  File "/usr/lib/python2.7/site-packages/usb1/__init__.py", line 2040, in getSerialNumber
    self.device_descriptor.iSerialNumber)
  File "/usr/lib/python2.7/site-packages/usb1/__init__.py", line 2017, in _getASCIIStringDescriptor
    return self.open().getASCIIStringDescriptor(descriptor)
  File "/usr/lib/python2.7/site-packages/usb1/__init__.py", line 2067, in open
    mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
  File "/usr/lib/python2.7/site-packages/usb1/__init__.py", line 133, in mayRaiseUSBError
    __raiseUSBError(value)
  File "/usr/lib/python2.7/site-packages/usb1/__init__.py", line 125, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorNoDevice: LIBUSB_ERROR_NO_DEVICE [-4]

Migrate from 2.7 to 3.6

import cStringsIO fails with Python3
According to "What's new in Python 3"

The StringIO and cStringIO modules are gone. Instead, import the io module and use io.StringIO or io.BytesIO for text and data respectively.

Also there are problems with bytes and str conversions.

Shell/StreamingShell and asynchronous replies

So, from what I can tell, you can pretty much only issue one command in shell (i.e. you don't get a pipe to a shell). And as soon as that command finishes, you only get back what was immediately printed out from it. Any async stuff that prints after that gets dumped. This makes it tough to actually start something running in the background and make sure it worked without having to send another shell command to check it some other way.

TypeError: can't concat bytes to str

I get the following error when connecting to a device:

$ python3.5 bluegiga_trigger_enum_bug.py
Traceback (most recent call last):
File "bluegiga_trigger_enum_bug.py", line 16, in
rsa_keys=[signer])
File "/home/fgervais/.local/lib/python3.5/site-packages/adb/adb_commands.py", line 76, in ConnectDevice
return cls.Connect(handle, **kwargs)
File "/home/fgervais/.local/lib/python3.5/site-packages/adb/adb_commands.py", line 99, in Connect
device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
File "/home/fgervais/.local/lib/python3.5/site-packages/adb/adb_protocol.py", line 295, in Connect
signed_token = rsa_key.Sign(str(banner))
File "/home/fgervais/.local/lib/python3.5/site-packages/adb/sign_pythonrsa.py", line 69, in Sign
return rsa.sign(data, self.priv_key, 'SHA-1-PREHASHED')
File "/home/fgervais/.local/lib/python3.5/site-packages/rsa/pkcs1.py", line 275, in sign
cleartext = asn1code + hash
TypeError: can't concat bytes to str

I'm not sure if this is related to my setup or not but I had to do the following to make is work:
fgervais@03fb73e

I'd like to have some feedback on this before I pull-request it.

.android/adbkey missing

"pkg_resources.DistributionNotFound: The 'python-rsa' distribution was not found and is required by adb"

op.expanduser('~/.android/adbkey'))

File "/home/vxerlee/python-adb/adb/sign_m2crypto.py", line 24, in init
with open(rsa_key_path + '.pub') as rsa_pub_file:
IOError: [Errno 2] No such file or directory: '/home/vxerlee/.android/adbkey.pub'

python adb.zip shell fails on macOS Sierra 10.12.1

I'm using Python 2.7.12 on macOS Sierra 10.12.1.

$  python adb.zip shell
Traceback (most recent call last):
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "adb.zip/__main__.py", line 178, in <module>
  File "adb.zip/__main__.py", line 174, in main
  File "adb.zip/adb/common_cli.py", line 150, in StartCli
  File "adb.zip/adb/adb_commands.py", line 75, in ConnectDevice
  File "adb.zip/adb/common.py", line 208, in FindAndOpen
  File "adb.zip/adb/common.py", line 122, in Open
  File "/usr/local/lib/python2.7/site-packages/usb1.py", line 1183, in claimInterface
    libusb1.libusb_claim_interface(self.__handle, interface),
  File "/usr/local/lib/python2.7/site-packages/usb1.py", line 133, in mayRaiseUSBError
    __raiseUSBError(value)
  File "/usr/local/lib/python2.7/site-packages/usb1.py", line 125, in raiseUSBError
    raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

can i call device.shell() and device.logcat() same time?

i found can not call shell() and logcat() same time, like this case:

'''
import os.path as op
from mainfuzzer.adb import adb_commands
from mainfuzzer.adb import sign_m2crypto
signer = sign_m2crypto.M2CryptoSigner(
op.expanduser('~/.android/adbkey'))
device = adb_commands.AdbCommands.ConnectDevice( rsa_keys=[signer])
class LogcatTask:
def __init__(self):
self._running = True
self.output = ''

def terminate(self):
    self._running = False

def run(self, options, timeout_ms):
    logcat = device.Logcat(' '.join(options), timeout_ms=timeout_ms)
    while self._running and timeout_ms > 0:
        self.output += logcat.next().strip()

from threading import Thread
c = LogcatTask()
t = Thread(target=c.run, args=([' ', ], 10000,))
t.start()
cmd = "ls -al /data/local/tmp"
print '=============>' + device.Shell(cmd)
import time
time.sleep(5)
c.terminate()
t.join()
print c.output
'''

i got this error:

usb_exceptions.ReadFailedError: Could not receive data from first SP9832A311063170368 (timeout 10000ms): LIBUSB_ERROR_TIMEOUT [-7]

Running on top of Android emulator

Is it possible to run the lib on top of an Android emulator?
I'm using Memu and I'm able to run adb commands on it from command line.
Thanks.

TcpHandle: TCP connection port parse error

In common.py, you split (in init of TcpHandle) the given serial (which in effect is host:port). port results as a string, but socket expects port to be numeric in socket.create_connection

Python 2.7

Wait-for-device command

Hi all,
I'm trying to use this Python implementation of ADB to issue reboot commands to my device.
The problem is that I cannot find a function that can be invoked to let me know when the device reboot has been completed.
In the Android ADB implementation I just use adb wait-for-device and wait until it returns.
Is the function available or am I missing something?

Thank you

[Query] Remember device is not working.

Hello, I am trying to use python-adb via Termux to be able to run adb commands via local device using the tcp mode.

However the remember device is not working. I forked the code, removed all code containing libusb1 and usb1 and tried to run the example code.

It works, however it is always prompting for the debugging checkbox in my phone even after checking remember this device.

May I know how to correctly remember the device in the code?

Add entry_points

Adding entry_points to setup.py to get console scripts

diff --git a/setup.py b/setup.py
index 7fb1172..ec02932 100644
--- a/setup.py
+++ b/setup.py
@@ -57,5 +57,12 @@ Android project's ADB.
         'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 3',
         'Topic :: Software Development :: Testing'
-        ]
+        ],
+    entry_points={
+        "console_scripts": [
+            "adb = adb.adb_debug:main",
+            "fastboot = adb.fastboot_debug:main",
+        ],
+    }
+
 )

TypeError while using Python3.6 with python-rsa

I tried to use python-adb with Python3.6 and python-rsa, then I got the TypeError while connecting to the device:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "D:\DevTools\python-adb-master\adb\adb_commands.py", line 76, in ConnectDevice
    return cls.Connect(handle, **kwargs)
  File "D:\DevTools\python-adb-master\adb\adb_commands.py", line 99, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
  File "D:\DevTools\python-adb-master\adb\adb_protocol.py", line 299, in Connect
    signed_token = rsa_key.Sign(str(banner))
  File "D:\DevTools\python-adb-master\adb\sign_pythonrsa.py", line 69, in Sign
    return rsa.sign(data, self.priv_key, 'SHA-1-PREHASHED')
  File "D:\ProgramFiles\Python\Python36\lib\site-packages\rsa\pkcs1.py", line 275, in sign
    cleartext = asn1code + hash
TypeError: can't concat str to bytes

Unable to connect to device

I copied the piece of demo code. But when I run, it gives OPENSSL_Uplink(000007FECFBD2000,08): no OPENSSL_Applink

my code:

`
signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey'))

device = AdbCommands.ConnectDevice(rsa_keys=[signer])
`
I have installed openssl binaries and it is present in the PATH variable. Is there any other setup that I need to do?

usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Hello,the problem happened when I run the demo code.
OS:macOS Sierra 10.12
Android Phone: Huawei Mate8, Android 7.0
python dependencies:
adb (1.2.0)
libusb1 (1.6.4)
M2Crypto (0.29.0)
rsa (3.4.2)

The code about
device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)

Traceback (most recent call last):
File "/.../PycharmProjects/AndroidPerformanceTest/adb_exp.py", line 13, in
rsa_keys=[signer])
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/adb/adb_commands.py", line 75, in ConnectDevice
timeout_ms=default_timeout_ms)
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/adb/common.py", line 211, in FindAndOpen
dev.Open()
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/adb/common.py", line 122, in Open
handle.claimInterface(iface_number)
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/usb1/init.py", line 1276, in claimInterface
libusb1.libusb_claim_interface(self.__handle, interface),
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/usb1/init.py", line 133, in mayRaiseUSBError
__raiseUSBError(value)
File "/.../PycharmProjects/AndroidPerformanceTest/virtual_env/AndroidPerformanceTest/lib/python2.7/site-packages/usb1/init.py", line 125, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorAccess: LIBUSB_ERROR_ACCESS [-3]

Issue: module' object has no attribute 'libusb_get_port_numbers'

when exec below command on MAC (high Sierra), it always report no attribute libusb_get_port_numbers issue.

$ python adb.zip list /sdcard/
Traceback (most recent call last):
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/local/Cellar/python/2.7.12_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "adb.zip/main.py", line 178, in
File "adb.zip/main.py", line 174, in main
File "adb.zip/adb/common_cli.py", line 150, in StartCli
File "adb.zip/adb/adb_commands.py", line 75, in ConnectDevice
File "adb.zip/adb/common.py", line 212, in FindAndOpen
File "adb.zip/adb/common.py", line 93, in Open
File "adb.zip/adb/common.py", line 138, in port_path
File "/usr/local/lib/python2.7/site-packages/usb1.py", line 1510, in getPortNumberList
result = libusb1.libusb_get_port_numbers(self.device_p, port_list,
AttributeError: 'module' object has no attribute 'libusb_get_port_numbers'

basestring not defined in python3

So I haven't been able to connect using this library with python3. I get the following error:

In [8]: d2 = adb_commands.AdbCommands.ConnectDevice(d.port_path)
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-de9165e2e205> in <module>()
----> 1 d2 = adb_commands.AdbCommands.ConnectDevice(d.port_path)

~/.virtualenvs/frida/lib/python3.5/site-packages/adb/adb_commands.py in ConnectDevice(cls, port_path, serial, default_timeout_ms, **kwargs)
     73         handle = common.UsbHandle.FindAndOpen(
     74             DeviceIsAvailable, port_path=port_path, serial=serial,
---> 75             timeout_ms=default_timeout_ms)
     76     return cls.Connect(handle, **kwargs)
     77 

~/.virtualenvs/frida/lib/python3.5/site-packages/adb/common.py in FindAndOpen(cls, setting_matcher, port_path, serial, timeout_ms)
    209     dev = cls.Find(
    210         setting_matcher, port_path=port_path, serial=serial,
--> 211         timeout_ms=timeout_ms)
    212     dev.Open()
    213     dev.FlushBuffers()

~/.virtualenvs/frida/lib/python3.5/site-packages/adb/common.py in Find(cls, setting_matcher, port_path, serial, timeout_ms)
    218     """Gets the first device that matches according to the keyword args."""
    219     if port_path:
--> 220       device_matcher = cls.PortPathMatcher(port_path)
    221       usb_info = port_path
    222     elif serial:

~/.virtualenvs/frida/lib/python3.5/site-packages/adb/common.py in PortPathMatcher(cls, port_path)
    194   def PortPathMatcher(cls, port_path):
    195     """Returns a device matcher for the given port path."""
--> 196     if isinstance(port_path, basestring):
    197       # Convert from sysfs path to port_path.
    198       port_path = [int(part) for part in SYSFS_PORT_SPLIT_RE.split(port_path)]

NameError: name 'basestring' is not defined

Turns out basestring as an object was removed in python3. Confused how people are successfully using this.

https://docs.python.org/3.0/whatsnew/3.0.html

The builtin basestring abstract type was removed. Use str instead. The str and bytes types don’t have functionality enough in common to warrant a shared base class. The 2to3 tool (see below) replaces every occurrence of basestring with str.

It seems replacing it with str gets past that. Not sure if that has other negative impacts in the code. Also, i still can't get python3 to successfully load given M2Crypto errors that follow. Guessing this library isn't ready for python3 use...

Demo code does not work

Seems like adb connection is closed after each Shell comand:

95:automation direvius$ python ./cmd.py
0

Traceback (most recent call last):
  File "./cmd.py", line 16, in <module>
    print device.Shell('echo %d' % i)
  File "/usr/local/lib/python2.7/site-packages/adb/adb_commands.py", line 227, in Shell
    timeout_ms=timeout_ms)
  File "/usr/local/lib/python2.7/site-packages/adb/adb_protocol.py", line 369, in Command
    return ''.join(cls.StreamingCommand(usb, service, command, timeout_ms))
  File "/usr/local/lib/python2.7/site-packages/adb/adb_protocol.py", line 394, in StreamingCommand
    for data in connection.ReadUntilClose():
AttributeError: 'NoneType' object has no attribute 'ReadUntilClose'

It works when there are ConnectDevice calls before every Shell

I cannot run python2.7 adb.zip shell on my Ubuntu 14.04

$ python2.7 adb.zip shell ls
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"main", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "adb.zip/main.py", line 178, in
File "adb.zip/main.py", line 174, in main
File "adb.zip/adb/common_cli.py", line 150, in StartCli
File "adb.zip/adb/adb_commands.py", line 75, in ConnectDevice
File "adb.zip/adb/common.py", line 208, in FindAndOpen
File "adb.zip/adb/common.py", line 122, in Open
File "build/bdist.linux-x86_64/egg/usb1.py", line 1162, in claimInterface
File "build/bdist.linux-x86_64/egg/usb1.py", line 121, in mayRaiseUSBError
File "build/bdist.linux-x86_64/egg/usb1.py", line 117, in raiseUSBError
usb1.USBErrorBusy: LIBUSB_ERROR_BUSY [-6

ADB forward implementation

i will use adb forward for code autmation that i have made, how to use adb forward on this module, or any tweak for using adb forward?
thanks

python 3.5: TypeError: a bytes-like object is required, not 'str' in TcpHandle.

On this commit: bed1a53 the following fails in python 3.5:
I do the following in a python 3.5 virtualenv:

In [4]: device = adb_commands.AdbCommands.ConnectDevice(serial=b'10.47.112.55:5555')

TypeError Traceback (most recent call last)
in ()
----> 1 device = adb_commands.AdbCommands.ConnectDevice(serial=b'10.47.112.55:5555')

python-adb/adb/adb_commands.py in ConnectDevice(cls, port_path, serial, default_timeout_ms, **kwargs)
69 """
70 if serial and b':' in serial:
---> 71 handle = common.TcpHandle(serial)
72 else:
73 handle = common.UsbHandle.FindAndOpen(

python-adb/adb/common.py in init(self, serial)
288 Host may be an IP address or a host name.
289 """
--> 290 if ':' in serial:
291 (host, port) = serial.split(':')
292 else:

TypeError: a bytes-like object is required, not 'str'

Can be fixed by the following patch:
diff --git a/adb/common.py b/adb/common.py
index a5d8928..b8980b6 100644
--- a/adb/common.py
+++ b/adb/common.py
@@ -287,12 +287,12 @@ class TcpHandle(object):

 Host may be an IP address or a host name.
 """
  • if ':' in serial:
  •  (host, port) = serial.split(':')
    
  • if b':' in serial:
  •  (host, port) = serial.split(b':')
    
    else:
    host = serial
    port = 5555
  • self._serial_number = '%s:%s' % (host, port)
  • self._serial_number = b'%s:%s' % (host, port)

    self._connection = socket.create_connection((host, port))

Should this be working in python 3.5? The current implementation does not.

I also bump into:
device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs) <-- banner
making problems. The following would fix it for python 3.5, but would break it for 2.7 I assume:

diff --git a/adb/adb_commands.py b/adb/adb_commands.py
index 966dc50..64b071d 100644
--- a/adb/adb_commands.py
+++ b/adb/adb_commands.py
@@ -95,7 +95,7 @@ class AdbCommands(object):
An instance of this class if the device connected successfully.
"""
if not banner:

  •  banner = socket.gethostname()
    
  •  banner = bytes(socket.gethostname(), 'ascii')
    
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)

    Remove banner and colons after device state (state::banner)

    device_state = device_state.split(b':')[0]

Should this be working in python 3.5?

No timeout on TCP connection to adb device

common.py, class TcpHandle does not support a time out for a TCP connection.

Since the class method ConnectDevice of class AdbCommands uses common.TcpHandle
"adb_unit = adb_commands.AdbCommands.ConnectDevice(serial='XX.XX.XX.XX:PORT')" hangs indefinitely if there is trouble connecting to 'XX.XX.XX.XX:PORT'.

Python 2.7

Unable to identify devices

Hi,
I am trying to issue python adb.zip devices to find the devices and get the following error. I have installed the dependencies(libusb1, python-libusb1, python-rsa). I also had issues with installing M2Crypto. I am working on Windows10.
Error:
Traceback (most recent call last):
File "C:\Python27\lib\runpy.py", line 174, in run_module_as_main
"main", fname, loader, pkg_name)
File "C:\Python27\lib\runpy.py", line 72, in run_code
exec code in run_globals
File "adb.zip_main
.py", line 178, in
File "adb.zip_main
.py", line 161, in main
File "adb.zip_main_.py", line 52, in Devices
File "adb.zip\adb\common.py", line 133, in serial_number
File "C:\Python27\lib\site-packages\usb1_init_.py", line 2040, in getSerialNumber
self.device_descriptor.iSerialNumber)
File "C:\Python27\lib\site-packages\usb1_init_.py", line 2017, in getASCIIStringDescriptor
return self.open().getASCIIStringDescriptor(descriptor)
File "C:\Python27\lib\site-packages\usb1_init
.py", line 2067, in open
mayRaiseUSBError(libusb1.libusb_open(self.device_p, byref(handle)))
File "C:\Python27\lib\site-packages\usb1_init_.py", line 133, in mayRaiseUSBError
_raiseUSBError(value)
File "C:\Python27\lib\site-packages\usb1_init
.py", line 125, in raiseUSBError
raise __STATUS_TO_EXCEPTION_DICT.get(value, __USBError)(value)
usb1.USBErrorNotSupported: LIBUSB_ERROR_NOT_SUPPORTED [-12]

I also installed winusb driver. Does this application work on windows?

"Allow USB debugging?" dialog show every time after calling adb_commands.AdbCommands.ConnectDevice

OS: Windows 7 x64
Branch: Master
Phone: Redmi Note 2
Android version: 5.0.2

I forked and use cryptography.io instead of M2Crypto to do the RSA thing in sign_m2crypto, because installing M2Crypto on Windows is painful and I can't manage it :(
Everything works fine, except the "Allow USB debugging?" dialog pops up every time I call adb_commands.AdbCommands.ConnectDevice, even after I check the "Always allow from this computer" checkbox.
Is this an issue or a designed behavior?

Here's my cryptography signer

class CryptographySigner(adb_protocol.AuthSigner):

  def __init__(self, rsa_key_path):
    with open(rsa_key_path + '.pub') as rsa_pub_file:
      self.public_key = rsa_pub_file.read()

    with open(rsa_key_path, 'rb') as key_file:
      self.rsa_key = serialization.load_pem_private_key(
        key_file.read(),
        password=None,
        backend=default_backend()
      )
  
  def Sign(self, data):
    return self.rsa_key.sign(
      data,
      padding.PKCS1v15(),
      hashes.SHA1()
    )

  def GetPublicKey(self):
    return self.public_key

Here is my test script

from os import path

from adb import adb_commands
from adb import sign_m2crypto
from adb import sign_pythonrsa

signer = sign_m2crypto.CryptographySigner(
  path.expanduser('~/.android/adbkey')
)

device = adb_commands.AdbCommands.ConnectDevice(
  auth_timeout_ms=3000,   # confirm manually on device
  rsa_keys=[signer]
)

for i in xrange(10):
  print device.Shell('echo %d' % i)

print device.Shell('ls')

Allow parallel commands over ADB

Currently, one can only issue one command at a time. Issuing two or more will cause issues with the data being intermixed because the ADB client assumes a local-id of 1.

My current proposal is to alter the internal use of the AdbMessage class so that an instance is used, which holds the handle (also renamed to transport instead of usb to match android-adb). In the various Connect classmethods in AdbCommands, it will create a new instance of that class, but there will be a new method that accepts an existing instance. This will allow a new parallel version to be used, but only by folks interested in that, so we don't affect or slow existing users.

An entirely new class will be created for parallel connections, likely a thin wrapper around a dict of the AdbMessage replacement.

This will result in two things:

  • Everything inside of AdbCommands will change rather drastically, so anyone using internal functions will get bit. We'll have to do a major revision change.
  • Users who didn't reach past AdbCommands and want parallel commands will have to make code changes to specify that, so they get the 'optimized' version that only allows a single stream.

The reason for allowing, and defaulting to, a single stream implementation is not as much for performance, as it is to reduce complexity in the normal case. The multi-stream version will have dispatching and lookups interleaved with everything a single-stream version has to do, making debugging more confusing. Users should be able to avoid multi-stream support when they don't need it, and be able to switch to single-stream when they're debugging something that may falsely show up as an adb issue.

Documentation or examples

Hello,

Can you provide more documentation about usage , also that link for Pycon 2016 is not working (asking permission), maybe you might at least fix that

Use libsparse in fastboot

Here is the error code:

fastboot.FastbootRemoteFailure: ('FAIL: data too large', 'data too large')

I noticed that the adb in platform-tools is working by sending sparse data.

Request: Make use of USB optional

Hi,
it would be great, if usage of USB would be conditional (common.py and file_sync.py)

try:
import libusb1
import usb1
except:
pass

Please implement port forwarding

Could you please implement support for port forwarding?

Right now if I want to use port forwarding, I have to call adb with subprocess. This is a problem, because I can't use adb, python-adb and usb tethering at the same time.

SYSFS_PORT_SPLIT_RE is not defined

SYSFS_PORT_SPLIT_RE, which I assume is supposed to be a compiled regex; is not defined.

`
#adb/common.py
#ln 194

@classmethod
def PortPathMatcher(cls, port_path):
    """Returns a device matcher for the given port path."""
    if isinstance(port_path, basestring):
      # Convert from sysfs path to port_path.
      port_path = [int(part) for part in SYSFS_PORT_SPLIT_RE.split(port_path)]
         return lambda device: device.port_path == port_path

`

Attached device not found

Device running on Android Emulator on Debian 9 with Python 3.5.

$ adb devices -l
List of devices attached
emulator-5554          device product:sdk_gphone_x86 model:Android_SDK_built_for_x86 device:generic_x86 transport_id:11

$ python3 adb.zip devices

Same with the Python library:

In [1]: from adb import adb_commands

In [2]: list(adb_commands.AdbCommands.Devices())
Out[2]: []

In [3]: adb_commands.AdbCommands.ConnectDevice(serial='emulator-5554')
---------------------------------------------------------------------------
StopIteration                             Traceback (most recent call last)
/usr/local/lib/python3.5/dist-packages/adb/common.py in FindFirst(cls, setting_matcher, device_matcher, **kwargs)
    255             return next(cls.FindDevices(
--> 256                 setting_matcher, device_matcher=device_matcher, **kwargs))
    257         except StopIteration:

StopIteration: 

During handling of the above exception, another exception occurred:

DeviceNotFoundError                       Traceback (most recent call last)
<ipython-input-3-ef65bdc4c112> in <module>()
----> 1 adb_commands.AdbCommands.ConnectDevice(serial='emulator-5554')

/usr/local/lib/python3.5/dist-packages/adb/adb_commands.py in ConnectDevice(cls, port_path, serial, default_timeout_ms, **kwargs)
     75             handle = common.UsbHandle.FindAndOpen(
     76                 DeviceIsAvailable, port_path=port_path, serial=serial,
---> 77                 timeout_ms=default_timeout_ms)
     78         return cls.Connect(handle, **kwargs)
     79 

/usr/local/lib/python3.5/dist-packages/adb/common.py in FindAndOpen(cls, setting_matcher, port_path, serial, timeout_ms)
    215         dev = cls.Find(
    216             setting_matcher, port_path=port_path, serial=serial,
--> 217             timeout_ms=timeout_ms)
    218         dev.Open()
    219         dev.FlushBuffers()

/usr/local/lib/python3.5/dist-packages/adb/common.py in Find(cls, setting_matcher, port_path, serial, timeout_ms)
    235             usb_info = 'first'
    236         return cls.FindFirst(setting_matcher, device_matcher,
--> 237                              usb_info=usb_info, timeout_ms=timeout_ms)
    238 
    239     @classmethod

/usr/local/lib/python3.5/dist-packages/adb/common.py in FindFirst(cls, setting_matcher, device_matcher, **kwargs)
    257         except StopIteration:
    258             raise usb_exceptions.DeviceNotFoundError(
--> 259                 'No device available, or it is in the wrong configuration.')
    260 
    261     @classmethod

DeviceNotFoundError: No device available, or it is in the wrong configuration.

Pull: Command Failed

From the excerpt below, Im gathering an apk location and then passing the location to the Pull command. However, when executing, this result returns 'Command failed'.

def adb_package(apk):
    print("[*]Searching for app relative to: " + apk + "\n")
    try:
        # os.system("adb kill-server")
        signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey'))
        # Connect to the device
        device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])
        # Now we can use Shell, Pull, Push, etc!
        packages = device.Shell('pm list packages | grep ' + apk)

        print ("Packages found! \n\n" + packages)

        print ("Enter package name to extract: ")

        base = raw_input()
        extract(base)

    except CalledProcessError as e:
        print(e)


def extract(base):
    try:
        signer = sign_m2crypto.M2CryptoSigner(op.expanduser('~/.android/adbkey'))
        # Connect to the device
        device = adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])
        # Now we can use Shell, Pull, Push, etc!
        apk_path = device.Shell('pm path ' + base)

        new_path = apk_path[apk_path.startswith("package:") and len("package:"):]

        # a = unicode(new_path, "utf-8")
        device.Pull(new_path)


    except CalledProcessError as e:
        print(e)`

UnicodeDecodeError when running demo code

Trying to run the demo code:

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto

# KitKat+ devices require authentication
signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands.ConnectDevice(
    rsa_keys=[signer])
# Now we can use Shell, Pull, Push, etc!
for i in xrange(10):
  print device.Shell('echo %d' % i)

Fails as follows:

$ env PYTHONPATH=/space/pub-repos/python-adb:$PYTHONPATH python adb-demo.py
Traceback (most recent call last):
File "adb-demo.py", line 11, in
rsa_keys=[signer])
File "/space/pub-repos/python-adb/adb/adb_commands.py", line 76, in ConnectDevice
return cls.Connect(handle, **kwargs)
File "/space/pub-repos/python-adb/adb/adb_commands.py", line 99, in Connect
device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
File "/space/pub-repos/python-adb/adb/adb_protocol.py", line 298, in Connect
msg.Send(usb)
File "/space/pub-repos/python-adb/adb/adb_protocol.py", line 211, in Send
usb.BulkWrite(self.Pack(), timeout_ms)
File "/space/pub-repos/python-adb/adb/adb_protocol.py", line 198, in Pack
len(self.data), self.checksum, self.magic)
File "/space/pub-repos/python-adb/adb/adb_protocol.py", line 182, in checksum
return self.CalculateChecksum(self.data)
File "/space/pub-repos/python-adb/adb/adb_protocol.py", line 190, in CalculateChecksum
total = sum(map(ord, data.decode('ascii')))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8d in position 1: ordinal not in range(128)

I'm using the latest git commit.

$ git log --oneline -1
bed1a53 Bump to 1.2.0 and add a History section (#46)

Mobile phone is google pixel running Android 7.1.2 .

TypeError: ord() expected string of length 1

Hi,
I try to use it both with adb.zip and from python and I get this error:

Traceback (most recent call last):
  File "/home/elichai2/PycharmProjects/Test/python_adb.py", line 10, in <module>
    rsa_keys=[signer])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 76, in ConnectDevice
    return cls.Connect(handle, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_commands.py", line 99, in Connect
    device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 277, in Connect
    cmd, arg0, arg1, banner = cls.Read(usb, ['CNXN', 'AUTH'])
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 235, in Read
    actual_checksum = cls.CalculateChecksum(data)
  File "/usr/local/lib/python2.7/dist-packages/adb/adb_protocol.py", line 187, in CalculateChecksum
    return sum(map(ord, data)) & 0xFFFFFFFF
TypeError: ord() expected string of length 1, but int found

Error when running demo code

python-adb/adb/adb_protocol.py", line 187, in CalculateChecksum return sum(map(ord, data)) & 0xFFFFFFFF TypeError: ord() expected string of length 1, but int found

Disable 10 sec USB timeout if no data arrives

When running python adb.zip logcat and there is no activity for 10 secs I receive an exception "Exception: Could not receive data from first 0123456789 (timeout 10000ms): LIBUSB_ERROR_TIMEOUT [-7]". It would be nice if there is a way to disable this timeout somehow. For some commands like "logcat" this seem to make sense.
I think this is loosely related to #24 (allow parallel commands). Using an infinite timeout is no optimal solution, as there is no alive checking at all then. If we could run a dummy command on a parallel channel, that could provide a robust way to detect dead devices. That would also catch cases where the ADB daemon on the device dies (manually or by the out-of-memory killer), but the device itself is still fine.

adb doen't work with Windows Cygwin env

I have installed adb in python27 virtualenv under windows cygwin and installed libusb drivers.

I am trying to run the example code given with collected android device using usb

import os.path as op

from adb import adb_commands
from adb import sign_m2crypto

# KitKat+ devices require authentication
signer = sign_m2crypto.M2CryptoSigner(
    op.expanduser('~/.android/adbkey'))
# Connect to the device
device = adb_commands.AdbCommands.ConnectDevice(
    rsa_keys=[signer])
print (device)

from adb import adb_commands
File "build\bdist.win-amd64\egg\adb\adb_commands.py", line 30, in
File "build\bdist.win-amd64\egg\adb\common.py", line 23, in
File "C:\WS\uppf\venv\lib\site-packages\libusb1.py", line 8, in
from usb1.libusb1 import *
File "C:\WS\uppf\venv\lib\site-packages\usb1_init_.py", line 61, in
from . import libusb1
File "C:\WS\uppf\venv\lib\site-packages\usb1\libusb1.py", line 199, in
libusb = _loadLibrary()
File "C:\WS\uppf\venv\lib\site-packages\usb1\libusb1.py", line 173, in loadLibrary
**return dll_loader('libusb-1.0' + suffix, loader_kw)
File "c:\python27\Lib\ctypes_init
.py", line 366, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found
(venv)

adb_commands.AdbCommands.ConnectDevice(rsa_keys=[signer])

the problem happened when running the example program in readme.

OS: MacOS 10.13
Phone: Huawei Mate 10.

the exception stack:
File "PATH_TO_PROJECT/main.py", line 11, in
device = adb_commands.AdbCommands.ConnectDevice(banner='ok',rsa_keys=[signer])
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_commands.py", line 76, in ConnectDevice
return cls.Connect(handle, **kwargs)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_commands.py", line 99, in Connect
device_state = cls.protocol_handler.Connect(usb, banner=banner, **kwargs)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_protocol.py", line 298, in Connect
msg.Send(usb)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_protocol.py", line 211, in Send
usb.BulkWrite(self.Pack(), timeout_ms)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_protocol.py", line 198, in Pack
len(self.data), self.checksum, self.magic)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_protocol.py", line 182, in checksum
return self.CalculateChecksum(self.data)
File "PATH_TO_PROJECT/env/lib/python2.7/site-packages/adb/adb_protocol.py", line 190, in CalculateChecksum
total = sum(map(ord, data.decode('ascii')))
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8e in position 0: ordinal not in range(128)

./abootool 运行时候报错

错误提示:
return adb_commands.AdbCommands.ConnectDevice(self.usbdev,rsa_keys=[signer])
TypeError: unbound method ConnectDevice() must be called with AdbCommands instance as first argument (got UsbHandle instance instead)

How to write a SQL update command with root privilege

1. adb shell

2. su -c 'sqlite3 /data/data/com.android.providers.settings/databases/settings.db "update system set value=5000 where name='screen_off_timeout'"'

But I am getting the following error:

Error: no such column: screen_off_timeout

how to fix it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.