Skip to content
Permalink
Browse files

Add adb root command for backup/restore.

  • Loading branch information...
askeing committed Jun 30, 2015
1 parent fe9fbfc commit de53af86530ce189657a77f6f49cc534525ddb0d
Showing with 31 additions and 8 deletions.
  1. +14 −8 backup_restore_profile.py
  2. +17 −0 utilities/adb_helper.py
@@ -189,15 +189,21 @@ def run(self):
elif 'ANDROID_SERIAL' in os.environ and os.environ['ANDROID_SERIAL'] in devices:
self.logger.debug('Setup serial to [{0}] by ANDROID_SERIAL'.format(os.environ['ANDROID_SERIAL']))
device_serial = os.environ['ANDROID_SERIAL']
elif self.args.serial is None and not 'ANDROID_SERIAL' in os.environ:
if len(devices) == 1:
self.logger.debug('No serial, and only one device')
device_serial = None
else:
self.logger.debug('No serial, but there are more than one device')
self.logger.warning('Please specify the device by --serial option.')
exit(1)
else:
if self.args.serial is None and not 'ANDROID_SERIAL' in os.environ:
if len(devices) == 1:
self.logger.debug('No serial, and only one device')
device_serial = None
else:
self.logger.debug('No serial, but there are more than one device')
self.logger.warning('Please specify the device by --serial option.')
exit(1)
device_serial = None

# checking the adb root for backup/restore
if not AdbHelper.adb_root(serial=device_serial):
exit(2)

# Backup
if self.args.backup:
try:
@@ -79,3 +79,20 @@ def adb_shell(command, serial=None):
AdbHelper.logger.debug('cmd: {0}'.format(cmd))
AdbHelper.logger.debug('output: {0}'.format(output))
return output

@staticmethod
def adb_root(serial=None):
if serial is None:
cmd = 'adb root'
else:
cmd = 'adb -s %s root' % (serial,)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.communicate()[0]
AdbHelper.logger.debug('cmd: {0}'.format(cmd))
AdbHelper.logger.debug('output: {0}'.format(output))
if p.returncode is 0 and (not 'cannot' in output):
AdbHelper.logger.info(output)
return True
else:
AdbHelper.logger.warning(output)
return False

0 comments on commit de53af8

Please sign in to comment.
You can’t perform that action at this time.