in tools/android/emulator/emulated_device.py [0:0]
def _StageDataFiles(self,
system_image_dir,
userdata_tarball,
timer,
enable_guest_gl,
snapshot_file,
system_image_path=None,
data_image_path=None,
vendor_img_path=None,
encryptionkey_img_path=None,
advanced_features_ini=None,
build_prop_path=None,
modified_ramdisk_path=None,
data_files=None):
"""Stages files for the emulator launch."""
self._images_dir = os.path.abspath(self._TempDir('images'))
os.makedirs(self._InitImagesDir())
os.makedirs(self._SessionImagesDir())
# Copy build.prop into the session dir where the emulator will find it.
# TODO(b/67322170): Generally we want build.prop in the session dir where
# the emulator will see it, but swordfish wear_23 breaks when we do that.
# Until we fix that device, we need a special case to avoid breaking it.
if (self.GetApiVersion() > 10 and
not self._IsBuggyWearBuild(build_prop_path)):
shutil.copy(build_prop_path,
os.path.join(self._SessionImagesDir(), 'build.prop'))
# kernel is never compressed (thank god.)
init_kernel = os.path.abspath(
os.path.join(system_image_dir, self._KernelFileName()))
assert os.path.exists(init_kernel)
os.symlink(init_kernel, self._KernelFile())
init_sys = os.path.abspath(system_image_path)
assert os.path.exists(init_sys), '%s: no system.img' % system_image_path
if system_image_path.endswith('.img'):
os.symlink(init_sys, self._InitSystemFile())
if (self._metadata_pb.emulator_type ==
emulator_meta_data_pb2.EmulatorMetaDataPb.QEMU2 and
not self._ShouldModifySystemImage(enable_guest_gl)):
# Qemu2 does not need a writable system.img file, so we symlink to
# ObjFS to avoid a copy.
os.symlink(init_sys, self._SystemFile())
else:
logging.info('Copying system image to %s', self._SystemFile())
timer.start('COPY_SYSTEM_IMAGE')
self._SparseCp(self._InitSystemFile(), self._SystemFile())
timer.stop('COPY_SYSTEM_IMAGE')
os.chmod(self._SystemFile(), stat.S_IRWXU)
else:
assert system_image_path.endswith('.img.tar.gz'), 'Not known format'
logging.info('Extracting system image from tar.gz')
timer.start('EXTRACT_SYSTEM_IMAGE')
self._ExtractTarEntry(
init_sys, 'system.img', os.path.dirname(self._SystemFile()))
shutil.move(os.path.join(os.path.dirname(self._SystemFile()),
'system.img'),
self._SystemFile())
timer.stop('EXTRACT_SYSTEM_IMAGE')
os.chmod(self._SystemFile(), stat.S_IRWXU)
timer.start('MODIFY_SYSTEM_IMAGE')
self._ModifySystemImage(enable_guest_gl)
timer.stop('MODIFY_SYSTEM_IMAGE')
# Folders created are data/misc/*
# Folders created are data/nativetest/**/* and so on.
# If we don't place the files in the right location, we end up
# getting weird exceptions in logcat since emulator requires those files
# to be present.
if data_files:
for each_file in data_files:
fn = each_file.split('data/')[1]
dn = os.path.join(self._SessionImagesDir(), 'data', os.path.dirname(fn))
# Create if this dir does not exist.
if not os.path.exists(dn):
os.makedirs(dn)
bn = os.path.basename(fn)
shutil.copy(each_file, os.path.join(dn, bn))
# Pipe service won't work for user build and api level 23+, since
# pipe_traversal doesn't have a right seclinux policy. In this case, just
# use real adb.
self._use_real_adb = (
self._IsUserBuild(build_prop_path) and self.GetApiVersion() >= 23)
if userdata_tarball:
# userdata tarball should contain:
# self._UserdataQemuFile()
# self._RamdiskFile()
# self._CacheFile()
# self._SdcardFile()
# self._SnapshotFile()
#
# It does not include:
# self._KernelFile() # handled above
# self._SystemFile() # handled above
# self._InitSystemFile() # handled above
tar_opts = '-xzSf'
if (self._metadata_pb.emulator_type ==
emulator_meta_data_pb2.EmulatorMetaDataPb.QEMU2):
# qemu2's userdata.dat is not gzipped because it is a diff of the
# initial userdata partition and thus quite small already. It also
# doesn't compress as well as a raw image does.
tar_opts = '-xSf'
subprocess.check_call(['tar', tar_opts, userdata_tarball, '-C',
self._images_dir])
data_size = FLAGS.data_partition_size
if (self.GetApiVersion() >= 19 and data_size and
data_size > os.path.getsize(self._UserdataQemuFile()) >> 20):
logging.info('Resize data partition to %dM', data_size)
subprocess.check_call(['/sbin/resize2fs', '-f',
self._UserdataQemuFile(), '%dM' % data_size])
# Symlink the snapshot file to the actual location.
if (snapshot_file and self._metadata_pb.emulator_architecture == 'x86' and
os.path.exists(snapshot_file)):
os.symlink(snapshot_file, self._SnapshotRamBinFile())
else:
# self._RamdiskFile() - we modify this abit
# self._SnapshotFile() - always exists
self._InitializeRamdisk(system_image_dir, modified_ramdisk_path)
self._SparseCp(self.android_platform.empty_snapshot_fs,
self._SnapshotFile())
if vendor_img_path and not os.path.exists(self._VendorFile()):
init_data = vendor_img_path
assert os.path.exists(init_data), '%s: no vendor.img' % vendor_img_path
if init_data.endswith('.img.tar.gz'):
self._ExtractTarEntry(
init_data, 'vendor.img', os.path.dirname(self._VendorFile()))
shutil.move(os.path.join(os.path.dirname(self._VendorFile()),
'vendor.img'),
self._VendorFile())
elif init_data.endswith('.img'):
self._SparseCp(init_data, self._VendorFile())
else:
raise Exception('Unknown vendor image type %s', vendor_img_path)
os.chmod(self._VendorFile(), stat.S_IRWXU)
if encryptionkey_img_path and not os.path.exists(
self._EncryptionKeyImageFile()):
init_data = encryptionkey_img_path
assert os.path.exists(init_data), (
'%s: no encryptionkey.img' % encryptionkey_img_path)
assert init_data.endswith('.img'), 'Not known format'
shutil.copy(init_data, self._EncryptionKeyImageFile())
os.chmod(self._EncryptionKeyImageFile(), stat.S_IRWXU)
if advanced_features_ini and not os.path.exists(
self._AdvancedFeaturesFile()):
assert os.path.exists(advanced_features_ini), (
'Advanced Features file %s does not exist' % advanced_features_ini)
shutil.copy(advanced_features_ini, self._AdvancedFeaturesFile())
os.chmod(self._AdvancedFeaturesFile(), stat.S_IRWXU)
if data_image_path and not os.path.exists(self._UserdataQemuFile()):
init_data = data_image_path
assert os.path.exists(init_data), '%s: no userdata.img' % data_image_path
if init_data.endswith('.img'):
self._SparseCp(init_data, self._UserdataQemuFile())
else:
assert init_data.endswith('.img.tar.gz'), 'Not known format'
self._ExtractTarEntry(
init_data,
'userdata.img',
os.path.dirname(self._UserdataQemuFile()))
shutil.move(os.path.join(os.path.dirname(self._UserdataQemuFile()),
'userdata.img'),
self._UserdataQemuFile())
if not os.path.exists(self._CacheFile()):
init_cache = resources.GetResourceFilename(
'android_test_support/'
'tools/android/emulator/support/cache.img.tar.gz')
self._ExtractTarEntry(init_cache, 'cache.img',
os.path.dirname(self._CacheFile()))
if not os.path.exists(self._SdcardFile()):
sdcard_size_mb = self._metadata_pb.sdcard_size_mb
if sdcard_size_mb == 256:
sd_name = 'default_sdcard.256.img'
self._ExtractTarEntry(
resources.GetResourceFilename(
'android_test_support/'
'tools/android/emulator/support/%s.tar.gz' % sd_name),
sd_name, os.path.dirname(self._SdcardFile()))
shutil.move(os.path.join(os.path.dirname(self._SdcardFile()),
sd_name),
self._SdcardFile())
logging.info('Using default sd card.')
else:
logging.info('Making sdcard on the fly due to a nonstandard size')
sdcard_args = [
self.android_platform.mksdcard,
'%sM' % sdcard_size_mb,
self._SdcardFile()]
timer.start(_SDCARD_CREATE)
common.SpawnAndWaitWithRetry(sdcard_args)
# 1AEF-1A1E is hard coded in AdbController.java
self._SetUUID(self._SdcardFile(), 0x1AEF1A1E)
timer.stop(_SDCARD_CREATE)
os.chmod(self._SdcardFile(), stat.S_IRWXU)
if os.path.exists(self._UserdataQemuFile()):
os.chmod(self._UserdataQemuFile(), stat.S_IRWXU)
os.chmod(self._CacheFile(), stat.S_IRWXU)
os.chmod(self._SnapshotFile(), stat.S_IRWXU)