def test_regular_file(self): """Test that checksum is properly calculated for regular files.""" adb.write_data_to_file('abcd', '/sdcard/file1') self.assertTrue(adb.file_exists('/sdcard/file1')) self.assertEqual( adb.get_file_checksum('/sdcard/file1'), 'e2fc714c4727ee9395f324cd2e7f331f')
def test_nonexistent_file(self): """Tests that checksum is None for a non-existent file.""" self.assertFalse(adb.file_exists('/sdcard/non-existent')) self.assertIsNone(adb.get_file_checksum('/sdcard/non-existent'))
def configure_build_properties_if_needed(): """Edits /system/build.prop for better boot speed and power use.""" # Check md5 checksum of build.prop to see if already updated, # in which case exit. If build.prop does not exist, something # is very wrong with the device, so bail. old_md5 = persistent_cache.get_value(BUILD_PROP_MD5_KEY) current_md5 = adb.get_file_checksum(BUILD_PROP_PATH) if current_md5 is None: logs.log_error('Unable to find %s on device.' % BUILD_PROP_PATH) return if old_md5 == current_md5: return # Pull to tmp file. bot_tmp_directory = environment.get_value('BOT_TMPDIR') old_build_prop_path = os.path.join(bot_tmp_directory, 'old.prop') adb.run_adb_command(['pull', BUILD_PROP_PATH, old_build_prop_path]) if not os.path.exists(old_build_prop_path): logs.log_error('Unable to fetch %s from device.' % BUILD_PROP_PATH) return # Write new build.prop. new_build_prop_path = os.path.join(bot_tmp_directory, 'new.prop') old_build_prop_file_content = open(old_build_prop_path, 'r') new_build_prop_file_content = open(new_build_prop_path, 'w') new_content_notification = '### CHANGED OR ADDED PROPERTIES ###' for line in old_build_prop_file_content: property_name = line.split('=')[0].strip() if property_name in BUILD_PROPERTIES: continue if new_content_notification in line: continue new_build_prop_file_content.write(line) new_build_prop_file_content.write(new_content_notification + '\n') for flag, value in BUILD_PROPERTIES.iteritems(): new_build_prop_file_content.write('%s=%s\n' % (flag, value)) old_build_prop_file_content.close() new_build_prop_file_content.close() # Keep verified boot disabled for M and higher releases. This makes it easy # to modify system's app_process to load asan libraries. build_version = get_build_version() if is_build_at_least(build_version, 'M'): adb.run_as_root() adb.run_adb_command('disable-verity') reboot() # Make /system writable. adb.run_as_root() adb.remount() # Remove seccomp policies (on N and higher) as ASan requires extra syscalls. if is_build_at_least(build_version, 'N'): policy_files = adb.run_adb_shell_command( ['find', '/system/etc/seccomp_policy/', '-type', 'f']) for policy_file in policy_files.splitlines(): adb.run_adb_shell_command(['rm', policy_file.strip()]) # Remove Google Plus app from non-Google devices. Makes it easy to install # older Gallery app on these devices. Otherwise, we run into duplicate # permission errors. if not google_device(): adb.run_adb_shell_command(['rm', '/system/app/PlusOne.apk']) adb.run_adb_shell_command(['rm', '/system/app/PlusOne/PlusOne.apk']) # Push new build.prop and backup to device. logs.log('Pushing new build properties file on device.') adb.run_adb_command( ['push', '-p', old_build_prop_path, BUILD_PROP_BACKUP_PATH]) adb.run_adb_command(['push', '-p', new_build_prop_path, BUILD_PROP_PATH]) adb.run_adb_shell_command(['chmod', '644', BUILD_PROP_PATH]) # Set persistent cache key containing and md5sum. current_md5 = adb.get_file_checksum(BUILD_PROP_PATH) persistent_cache.set_value(BUILD_PROP_MD5_KEY, current_md5)