def set_certapps(self, enable=True, serial=None): AdbWrapper.adb_root(serial=serial) logger.info('{} Full Privilege for WebIDE...'.format('Enabling' if enable else 'Disabling')) need_restart = True try: tmp_dir = tempfile.mkdtemp(prefix='enablecertapps_') # get profile folder name xxx.default under /data/b2g/mozilla/ profile_dir_name, retcode = AdbWrapper.adb_shell('ls /data/b2g/mozilla/ | grep default', serial=serial) device_src_file = os.path.join('/data/b2g/mozilla/', profile_dir_name, 'prefs.js') dest_temp_file = os.path.join(tmp_dir, 'prefs.js.origin') try: logger.info('Pulling prefs.js file...') AdbWrapper.adb_pull(device_src_file, dest_temp_file, serial=serial) except: raise Exception('Error pulling prefs.js file.') dest_file = os.path.join(tmp_dir, 'prefs.js') with open(dest_temp_file, 'r') as fr: with open(dest_file, 'w') as fw: match = False is_forbid = 'false' if enable else 'true' logger.debug('is_forbid: [{}]'.format(is_forbid)) for line in fr: if 'devtools.debugger.forbid-certified-apps' in line: logger.debug('line: [{}] to [{}]'.format(line, is_forbid)) if is_forbid in line: # do not need to restart if the setting isn't changed logger.info('The full privilege is already {}.'.format('enabled' if enable else 'disabled')) need_restart = False break else: logger.info('Changing setting of pref.js file...') fw.write('user_pref("devtools.debugger.forbid-certified-apps", {});\n'.format(is_forbid)) match = True else: fw.write(line) if not match: if not enable: # the forbid is true when there is no setting logger.info('The full privilege is already disabled.') need_restart = False else: if need_restart: # adding setting when there is no setting and need to enable certapps logger.info('Adding setting of pref.js file...') fw.write('user_pref("devtools.debugger.forbid-certified-apps", {});\n'.format(is_forbid)) if need_restart: B2GHelper.stop_b2g(serial=serial) try: logger.info('Pushing prefs.js file...') AdbWrapper.adb_push(dest_file, device_src_file, serial=serial) except: raise Exception('Error pushing prefs.js file.') finally: if need_restart: B2GHelper.start_b2g(serial=serial) shutil.rmtree(tmp_dir)
def prepare_step(self): # checking the adb root if not AdbWrapper.adb_root(serial=self.serial): raise Exception('No root permission for shallow flashing.') # checking the adb remount if not AdbWrapper.adb_remount(serial=self.serial): raise Exception('No permission to remount for shallow flashing.') # Stop B2G B2GHelper.stop_b2g(serial=self.serial)
def run(self): """ Entry point. """ self.devices = AdbWrapper.adb_devices() logger.debug("Devices: {}".format(self.devices)) if len(self.devices) < 1: raise Exception("Can not find device, please connect your device.") elif len(self.devices) > 1: raise Exception("Find more than one device, please only connect one device.") # get device name device_name = AdbWrapper.adb_shell("getprop ro.product.device")[0] logger.info("Device found: {}".format(device_name)) if device_name not in self.SUPPORT_DEVICES.keys(): raise Exception("The {} device is not supported.".format(device_name)) # select branch branch = self.select_branch() # select build type postfix = self.select_build() # get namespace and image artifact device_info = self.SUPPORT_DEVICES.get(device_name) namespace = self.NAMESPACE_FORMAT(branch=branch, device=device_info.get("name"), postfix=postfix) artifact = self.ARTIFACT_FORMAT(build_path=self.BUILD_PATH, image=device_info.get("image")) logger.info("Device: {}".format(device_name)) logger.info("Namespace: {}".format(namespace)) logger.info("Artifact: {}".format(artifact)) ret = raw_input( '\nDownload "{artifact}" from "{namespace}".\nRight? [Y/n]'.format(artifact=artifact, namespace=namespace) ) if len(ret) > 0 and ret.lower()[0] == "n": logger.info("Stop.") exit(0) # downloading image logger.info("Downloading image...") local_image = self.download(namespace, artifact) logger.debug("Image file: {}".format(local_image)) # checking file logger.info("Checking file...") if not B2GHelper.check_b2g_image(local_image): raise Exception("This is not B2G image file: {}".format(local_image)) # flashing image logger.info("Flashing image...") self.flash_image(local_image)
def run(self): # get the device's serial number devices = AdbWrapper.adb_devices() if len(devices) == 0: raise Exception('No device.') else: device_serial = AdbHelper.get_serial(self.args.serial) if device_serial is None: if len(devices) == 1: logger.debug('No serial, and only one device') else: logger.debug('No serial, but there are more than one device') raise Exception('Please specify the device by --serial option.') else: logger.debug('Setup serial to [{0}]'.format(device_serial)) # checking the adb root for backup/restore if not AdbWrapper.adb_root(serial=device_serial): raise Exception('No root permission for backup and resotre.') # Backup if self.args.backup: try: logger.info('Target device [{0}]'.format(device_serial)) # Create temp folder tmp_dir = tempfile.mkdtemp(prefix='backup_restore_') logger.debug('TEMP Foler: {}'.format(tmp_dir)) # Stop B2G B2GHelper.stop_b2g(serial=device_serial) # Backup User Profile self.backup_profile(local_dir=tmp_dir, serial=device_serial) # Backup SDCard if self.args.sdcard: self.backup_sdcard(local_dir=tmp_dir, serial=device_serial) # Copy backup files from temp folder to target folder if os.path.isdir(self.args.profile_dir): logger.warning('Removing [{0}] folder...'.format(self.args.profile_dir)) shutil.rmtree(self.args.profile_dir) logger.info('Copy profile from [{0}] to [{1}].'.format(tmp_dir, self.args.profile_dir)) shutil.copytree(tmp_dir, self.args.profile_dir) # Start B2G if not self.args.no_reboot: B2GHelper.start_b2g(serial=device_serial) finally: logger.debug('Removing [{0}] folder...'.format(tmp_dir)) shutil.rmtree(tmp_dir) # Restore elif self.args.restore: logger.info('Target device [{0}]'.format(device_serial)) # Checking the Version of Profile if self.check_profile_version(local_dir=self.args.profile_dir, serial=device_serial): # Stop B2G B2GHelper.stop_b2g(serial=device_serial) # Restore User Profile self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial) # Restore SDCard if self.args.sdcard: self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial) # Start B2G if not self.args.no_reboot: B2GHelper.start_b2g(serial=device_serial) else: logger.warning('The version on device is smaller than backup\'s version.')
def set_certapps(self, enable=True, serial=None): ''' Set the devtools permission for certapps. @param enable: True will turn on the permission. False will turn off the permission. @param serial: device serial number. (optional) @raise exception: When it cannot pulling/pushing the pref.js file of device. ''' AdbWrapper.adb_root(serial=serial) logger.info('{} Full Privilege for WebIDE...'.format( 'Enabling' if enable else 'Disabling')) need_restart = True try: tmp_dir = tempfile.mkdtemp(prefix='enablecertapps_') # get profile folder name xxx.default under /data/b2g/mozilla/ profile_dir_name, retcode = AdbWrapper.adb_shell( 'ls /data/b2g/mozilla/ | grep default', serial=serial) device_src_file = os.path.join('/data/b2g/mozilla/', profile_dir_name, 'prefs.js') dest_temp_file = os.path.join(tmp_dir, 'prefs.js.origin') try: logger.info('Pulling prefs.js file...') AdbWrapper.adb_pull(device_src_file, dest_temp_file, serial=serial) except: raise Exception('Error pulling prefs.js file.') dest_file = os.path.join(tmp_dir, 'prefs.js') with open(dest_temp_file, 'r') as fr: with open(dest_file, 'w') as fw: match = False is_forbid = 'false' if enable else 'true' logger.debug('is_forbid: [{}]'.format(is_forbid)) for line in fr: if 'devtools.debugger.forbid-certified-apps' in line: logger.debug('line: [{}] to [{}]'.format( line, is_forbid)) if is_forbid in line: # do not need to restart if the setting isn't changed logger.info( 'The full privilege is already {}.'.format( 'enabled' if enable else 'disabled')) need_restart = False break else: logger.info( 'Changing setting of pref.js file...') fw.write( 'user_pref("devtools.debugger.forbid-certified-apps", {});\n' .format(is_forbid)) match = True else: fw.write(line) if not match: if not enable: # the forbid is true when there is no setting logger.info( 'The full privilege is already disabled.') need_restart = False else: if need_restart: # adding setting when there is no setting and need to enable certapps logger.info( 'Adding setting of pref.js file...') fw.write( 'user_pref("devtools.debugger.forbid-certified-apps", {});\n' .format(is_forbid)) if need_restart: B2GHelper.stop_b2g(serial=serial) try: logger.info('Pushing prefs.js file...') AdbWrapper.adb_push(dest_file, device_src_file, serial=serial) except: raise Exception('Error pushing prefs.js file.') finally: if need_restart: B2GHelper.start_b2g(serial=serial) shutil.rmtree(tmp_dir)
def run(self): # get the device's serial number devices = AdbWrapper.adb_devices() if len(devices) == 0: raise Exception('No device.') else: device_serial = AdbHelper.get_serial(self.args.serial) if device_serial is None: if len(devices) == 1: logger.debug('No serial, and only one device') else: logger.debug( 'No serial, but there are more than one device') raise Exception( 'Please specify the device by --serial option.') else: logger.debug('Setup serial to [{0}]'.format(device_serial)) # checking the adb root for backup/restore if not AdbWrapper.adb_root(serial=device_serial): raise Exception('No root permission for backup and resotre.') # Backup if self.args.backup: try: logger.info('Target device [{0}]'.format(device_serial)) # Create temp folder tmp_dir = tempfile.mkdtemp(prefix='backup_restore_') logger.debug('TEMP Foler: {}'.format(tmp_dir)) # Stop B2G B2GHelper.stop_b2g(serial=device_serial) # Backup User Profile self.backup_profile(local_dir=tmp_dir, serial=device_serial) # Backup SDCard if self.args.sdcard: self.backup_sdcard(local_dir=tmp_dir, serial=device_serial) # Copy backup files from temp folder to target folder if os.path.isdir(self.args.profile_dir): logger.warning('Removing [{0}] folder...'.format( self.args.profile_dir)) shutil.rmtree(self.args.profile_dir) logger.info('Copy profile from [{0}] to [{1}].'.format( tmp_dir, self.args.profile_dir)) shutil.copytree(tmp_dir, self.args.profile_dir) # Start B2G if not self.args.no_reboot: B2GHelper.start_b2g(serial=device_serial) finally: logger.debug('Removing [{0}] folder...'.format(tmp_dir)) shutil.rmtree(tmp_dir) # Restore elif self.args.restore: logger.info('Target device [{0}]'.format(device_serial)) # Checking the Version of Profile if self.check_profile_version(local_dir=self.args.profile_dir, serial=device_serial): # Stop B2G B2GHelper.stop_b2g(serial=device_serial) # Restore User Profile self.restore_profile(local_dir=self.args.profile_dir, serial=device_serial) # Restore SDCard if self.args.sdcard: self.restore_sdcard(local_dir=self.args.profile_dir, serial=device_serial) # Start B2G if not self.args.no_reboot: B2GHelper.start_b2g(serial=device_serial) else: logger.warning( 'The version on device is smaller than backup\'s version.')