#NEWLINE# def setup( self , context ) : #NEWLINE# #INDENT# self . bbench_on_device = '/' . join ( [ self . device . working_directory , 'bbench' ] ) #NEWLINE# self . bbench_server_on_device = os . path . join ( self . device . working_directory , BBENCH_SERVER_NAME ) #NEWLINE# self . audio_on_device = os . path . join ( self . device . working_directory , DEFAULT_AUDIO_FILE_NAME ) #NEWLINE# self . index_noinput = ( 'file:///{}' . format ( self . bbench_on_device ) + '/index_noinput.html' ) #NEWLINE# if ( not os . path . isdir ( os . path . join ( self . dependencies_directory , 'sites' ) ) ) : #NEWLINE# #INDENT# self . _download_bbench_file ( ) #NEWLINE# #UNINDENT# if ( self . with_audio and ( not os . path . isfile ( self . audio_file ) ) ) : #NEWLINE# #INDENT# self . _download_audio_file ( ) #NEWLINE# #UNINDENT# if ( not os . path . isdir ( self . dependencies_directory ) ) : #NEWLINE# #INDENT# raise ConfigError ( 'Bbench directory does not exist: {}' . format ( self . dependencies_directory ) ) #NEWLINE# #UNINDENT# self . _apply_patches ( ) #NEWLINE# if self . with_audio : #NEWLINE# #INDENT# if ( self . force_dependency_push or ( not self . device . file_exists ( self . audio_on_device ) ) ) : #NEWLINE# #INDENT# self . device . push_file ( self . audio_file , self . audio_on_device , timeout = 120 ) #NEWLINE# #UNINDENT# #UNINDENT# if ( self . force_dependency_push or ( not self . device . file_exists ( self . bbench_on_device ) ) ) : #NEWLINE# #INDENT# self . logger . debug ( 'Copying bbench sites to device.' ) #NEWLINE# self . device . push_file ( self . dependencies_directory , self . bbench_on_device , timeout = 300 ) #NEWLINE# #UNINDENT# host_binary = context . resolver . get ( Executable ( self , self . device . abi , 'bbench_server' ) ) #NEWLINE# device_binary = self . device . install ( self ) #NEWLINE# self . luanch_server_command = '{} {}' . format ( device_binary , self . server_timeout ) #NEWLINE# self . device . execute ( 'am start -n  {}/{} about:blank' . format ( self . browser_package , self . browser_activity ) ) #NEWLINE# time . sleep ( 5 ) #NEWLINE# self . device . execute ( 'am force-stop {}' . format ( self . browser_package ) ) #NEWLINE# time . sleep ( 5 ) #NEWLINE# self . device . clear_logcat ( ) #NEWLINE# self . device . execute ( 'pm clear {}' . format ( self . browser_package ) ) #NEWLINE# if self . clear_file_cache : #NEWLINE# #INDENT# self . device . execute ( 'sync' ) #NEWLINE# self . device . set_sysfile_value ( '/proc/sys/vm/drop_caches' , 3 ) #NEWLINE# #UNINDENT# if ( self . device . get_sdk_version ( ) >= 23 ) : #NEWLINE# #INDENT# self . device . execute ( 'pm grant com.android.browser android.permission.READ_EXTERNAL_STORAGE' ) #NEWLINE# self . device . execute ( 'pm grant com.android.browser android.permission.WRITE_EXTERNAL_STORAGE' ) #NEWLINE# #UNINDENT# if self . with_audio : #NEWLINE# #INDENT# self . device . execute ( 'am start -W -S -n com.android.music/.MediaPlaybackActivity -d {}' . format ( self . audio_on_device ) )