Sha256: 6a72e32e77d5e0f29dbca29fde8bbdd370f3efbcf7f9055afec4e5d84a028e35

Contents?: true

Size: 1.36 KB

Versions: 69

Compression:

Stored size: 1.36 KB

Contents

module Fastlane
  module Helper
    class AdbDevice
      attr_accessor :serial

      def initialize(serial: nil)
        self.serial = serial
      end
    end

    class AdbHelper
      # Path to the adb binary
      attr_accessor :adb_path

      # All available devices
      attr_accessor :devices

      def initialize(adb_path: nil)
        android_home = ENV['ANDROID_HOME'] || ENV['ANDROID_SDK_ROOT'] || ENV['ANDROID_SDK']
        if (adb_path.nil? || adb_path == "adb") && android_home
          adb_path = Pathname.new(android_home).join("platform-tools/adb").to_s
        end
        self.adb_path = adb_path
      end

      # Run a certain action
      def trigger(command: nil, serial: nil)
        android_serial = serial != "" ? "ANDROID_SERIAL=#{serial}" : nil
        command = [android_serial, adb_path, command].join(" ")
        Action.sh(command)
      end

      def device_avalaible?(serial)
        load_all_devices
        return devices.map(&:serial).include?(serial)
      end

      def load_all_devices
        self.devices = []

        command = [adb_path, "devices"].join(" ")
        output = Actions.sh(command, log: false)
        output.split("\n").each do |line|
          if (result = line.match(/(.*)\tdevice$/))
            self.devices << AdbDevice.new(serial: result[1])
          end
        end
        self.devices
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
fastlane-2.108.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.107.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.106.2 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.106.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.106.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.105.2 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.105.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.104.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.103.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.103.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.102.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.101.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.101.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.100.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.100.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.99.1 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.99.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.98.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.97.0 fastlane/lib/fastlane/helper/adb_helper.rb
fastlane-2.96.1 fastlane/lib/fastlane/helper/adb_helper.rb