assets/rakelib/ruboto.device.rb in ruboto-1.4.1 vs assets/rakelib/ruboto.device.rb in ruboto-1.5.0

- old
+ new

@@ -27,12 +27,23 @@ installed_timestamp = Time.parse($2) !File.exists?(apk_file) || (installed_apk_size == File.size(apk_file) && installed_timestamp >= File.mtime(apk_file)) end +# the scripts path is different on different Android versions and devices... def scripts_path(package) - @sdcard_path ||= "/mnt/sdcard/Android/data/#{package}/files/scripts" + external_storage = `adb shell 'echo $EXTERNAL_STORAGE'`.chomp + app_data_path = "#{external_storage}/Android/data/#{package}" + if external_storage.empty? + puts "external storage not found: #{app_data_path.inspect}" + app_data_path = `adb shell run-as #{package} pwd` + if app_data_path =~ /Permission denied/ + puts "internal storage not found: #{app_data_path.inspect}" + app_data_path = "/mnt/sdcard/Android/data/#{package}" + end + end + "#{app_data_path}/files/scripts" end def mark_update(time = Time.now) FileUtils.mkdir_p File.dirname(UPDATE_MARKER_FILE) File.open(UPDATE_MARKER_FILE, 'w') { |f| f << time.iso8601 } @@ -73,11 +84,11 @@ puts "Package #{package} already installed, but of different size or timestamp. Replacing package." sh "adb shell date -s #{Time.now.strftime '%Y%m%d.%H%M%S'}" output = nil install_retry_count = 0 begin - timeout install_timeout do + Timeout.timeout install_timeout do output = `adb install -r "#{apk_file}" 2>&1` end rescue Timeout::Error puts "Installing package #{package} timed out after #{install_timeout}s." install_retry_count += 1 @@ -106,11 +117,11 @@ end puts "Installing package #{package}" output = nil install_retry_count = 0 begin - timeout install_timeout do + Timeout.timeout install_timeout do output = `adb install "#{apk_file}" 2>&1` end rescue Timeout::Error puts "Installing package #{package} timed out after #{install_timeout}s." install_retry_count += 1 @@ -136,33 +147,29 @@ puts "Uninstall failed exit code #{$?}" exit $? end end +def make_device_path(package, path) + puts `adb shell #{"run-as #{package}" if sdk_level >= 23} mkdir -p #{path}` + device_path_exists?(path) +end + def update_scripts(package) - # FIXME(uwe): Simplify when we stop supporting Android 2.3 - if sdk_level < 15 - scripts_path(package).split('/').tap do |parts| - parts.size.times do |i| - path = parts[0..i].join('/') - puts(`adb shell mkdir #{path}`) unless device_path_exists?(path) - end - end - else - puts(`adb shell mkdir -p #{scripts_path(package)}`) unless device_path_exists?(scripts_path(package)) + scripts_path = scripts_path(package) + if !device_path_exists?(scripts_path) && !make_device_path(package, scripts_path) + raise "Unable to create device scripts dir: #{scripts_path}" end - # EMXIF - - raise "Unable to create device scripts dir: #{scripts_path(package)}" unless device_path_exists?(scripts_path(package)) - last_update = File.exists?(UPDATE_MARKER_FILE) ? Time.parse(File.read(UPDATE_MARKER_FILE)) : Time.parse('1970-01-01T00:00:00') + mark_time = File.exists?(UPDATE_MARKER_FILE) ? File.read(UPDATE_MARKER_FILE) : '1970-01-01T00:00:00' + last_update = Time.parse(mark_time) Dir.chdir('src') do source_files = Dir['**/*.rb'] changed_files = source_files.select { |f| !File.directory?(f) && File.mtime(f) >= last_update && f !~ /~$/ } unless changed_files.empty? puts 'Pushing files to apk public file area:' changed_files.each do |script_file| print "#{script_file}: "; $stdout.flush - system "adb push #{script_file} #{scripts_path(package)}/#{script_file}" + system "adb push #{script_file} #{scripts_path}/#{script_file}" end mark_update return changed_files end end