device_api-android 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/device_api/android.rb +1 -0
- data/lib/device_api/android/adb.rb +35 -31
- data/lib/device_api/android/device.rb +2 -2
- data/lib/device_api/android/plugins/audio.rb +76 -0
- metadata +12 -17
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 696b2120302134357a63763b3bded0f733d9e3a4
         | 
| 4 | 
            +
              data.tar.gz: 50845791f6c53132d0718d5648c1960c44e78c67
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4454f5cf73cba899c4f4b7a63054712cbd39b1594a9c86c67d53038e011106735b7561fada022599fbb2342b67ad5721ec08e4d95d19413fba76db18f160d943
         | 
| 7 | 
            +
              data.tar.gz: a0a41ab17b179a5339ee522b1bc45760e0510e88d33b4c871899e156814305ad453a5ea4b2217601c0f410aefbf03d3ce4188f2cfa9031b8c707ea0396fe1dca
         | 
    
        data/lib/device_api/android.rb
    CHANGED
    
    | @@ -4,6 +4,7 @@ require 'device_api/android/device' | |
| 4 4 | 
             
            require 'device_api/android/signing'
         | 
| 5 5 |  | 
| 6 6 | 
             
            # Load plugins
         | 
| 7 | 
            +
            require 'device_api/android/plugins/audio'
         | 
| 7 8 | 
             
            require 'device_api/android/plugins/memory'
         | 
| 8 9 | 
             
            require 'device_api/android/plugins/battery'
         | 
| 9 10 | 
             
            require 'device_api/android/plugins/disk'
         | 
| @@ -38,9 +38,7 @@ module DeviceAPI | |
| 38 38 | 
             
                  # @param serial serial number of device
         | 
| 39 39 | 
             
                  # @return (Hash) hash containing device properties
         | 
| 40 40 | 
             
                  def self.getprop(serial)
         | 
| 41 | 
            -
                    result =  | 
| 42 | 
            -
             | 
| 43 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 41 | 
            +
                    result = shell(serial, 'getprop')
         | 
| 44 42 |  | 
| 45 43 | 
             
                    lines = result.stdout.encode('UTF-16', 'UTF-8', invalid: :replace, replace: '').encode('UTF-8', 'UTF-16').split("\n")
         | 
| 46 44 |  | 
| @@ -73,7 +71,7 @@ module DeviceAPI | |
| 73 71 |  | 
| 74 72 | 
             
                  # Get the network information
         | 
| 75 73 | 
             
                  def self.get_network_info(serial)
         | 
| 76 | 
            -
                    lines =  | 
| 74 | 
            +
                    lines = shell(serial, 'netcfg')
         | 
| 77 75 | 
             
                    lines.stdout.split("\n").map do |a|
         | 
| 78 76 | 
             
                      b = a.split(" ")
         | 
| 79 77 | 
             
                      { name: b[0], ip: b[2].split('/')[0], mac: b[4] }
         | 
| @@ -119,8 +117,7 @@ module DeviceAPI | |
| 119 117 | 
             
                  # @param serial serial number of device
         | 
| 120 118 | 
             
                  # @return (Array) array of results from adb shell dumpsys
         | 
| 121 119 | 
             
                  def self.dumpsys(serial, command)
         | 
| 122 | 
            -
                    result =  | 
| 123 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 120 | 
            +
                    result = shell(serial, "dumpsys #{command}")
         | 
| 124 121 | 
             
                    result.stdout.split("\n").map { |line| line.strip }
         | 
| 125 122 | 
             
                  end
         | 
| 126 123 |  | 
| @@ -172,9 +169,7 @@ module DeviceAPI | |
| 172 169 | 
             
                  # @param serial serial number of device
         | 
| 173 170 | 
             
                  # @return (Float) uptime in seconds
         | 
| 174 171 | 
             
                  def self.get_uptime(serial)
         | 
| 175 | 
            -
                    result =  | 
| 176 | 
            -
             | 
| 177 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 172 | 
            +
                    result = shell(serial, 'cat /proc/uptime')
         | 
| 178 173 |  | 
| 179 174 | 
             
                    lines = result.stdout.split("\n")
         | 
| 180 175 | 
             
                    uptime = 0
         | 
| @@ -210,11 +205,11 @@ module DeviceAPI | |
| 210 205 | 
             
                    seed = args[:seed]
         | 
| 211 206 | 
             
                    throttle = args[:throttle]
         | 
| 212 207 |  | 
| 213 | 
            -
                    cmd = " | 
| 208 | 
            +
                    cmd = "monkey -p #{package} -v #{events}"
         | 
| 214 209 | 
             
                    cmd = cmd + " -s #{seed}" if seed
         | 
| 215 210 | 
             
                    cmd = cmd + " -t #{throttle}" if throttle
         | 
| 216 211 |  | 
| 217 | 
            -
                     | 
| 212 | 
            +
                    shell(serial, cmd)
         | 
| 218 213 | 
             
                  end
         | 
| 219 214 |  | 
| 220 215 | 
             
                  # Take a screenshot from the device
         | 
| @@ -228,9 +223,9 @@ module DeviceAPI | |
| 228 223 | 
             
                    filename = args[:filename] or raise "filename not provided (:filename => '/tmp/myfile.png')"
         | 
| 229 224 |  | 
| 230 225 | 
             
                    convert_carriage_returns = %q{perl -pe 's/\x0D\x0A/\x0A/g'}
         | 
| 231 | 
            -
                    cmd = " | 
| 226 | 
            +
                    cmd = "screencap -p | #{convert_carriage_returns} > #{filename}"
         | 
| 232 227 |  | 
| 233 | 
            -
                     | 
| 228 | 
            +
                    shell(serial, cmd)
         | 
| 234 229 | 
             
                  end
         | 
| 235 230 |  | 
| 236 231 | 
             
                  # Returns wifi status and access point name
         | 
| @@ -238,21 +233,34 @@ module DeviceAPI | |
| 238 233 | 
             
                  # @example
         | 
| 239 234 | 
             
                  #   DeviceAPI::ADB.wifi(serial)
         | 
| 240 235 | 
             
                  def self.wifi(serial)
         | 
| 241 | 
            -
                    result =  | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
                    else
         | 
| 245 | 
            -
                      result = {:status => result.stdout.match("state:(.*?),")[1].strip, :access_point => result.stdout.match("extra:(.*?),")[1].strip.gsub(/"/,'')}
         | 
| 246 | 
            -
                    end
         | 
| 247 | 
            -
                    result
         | 
| 236 | 
            +
                    result = shell(serial, 'dumpsys wifi | grep mNetworkInfo')
         | 
| 237 | 
            +
             | 
| 238 | 
            +
                    {:status => result.stdout.match("state:(.*?),")[1].strip, :access_point => result.stdout.match("extra:(.*?),")[1].strip.gsub(/"/,'')}
         | 
| 248 239 | 
             
                  end
         | 
| 249 240 |  | 
| 250 241 | 
             
                  # Sends a key event to the specified device
         | 
| 251 242 | 
             
                  # @param [String] serial serial number of device
         | 
| 252 243 | 
             
                  # @param [String] keyevent keyevent to send to the device
         | 
| 253 244 | 
             
                  def self.keyevent(serial, keyevent)
         | 
| 254 | 
            -
                     | 
| 255 | 
            -
             | 
| 245 | 
            +
                    shell(serial, "input keyevent #{keyevent}").stdout
         | 
| 246 | 
            +
                  end
         | 
| 247 | 
            +
             | 
| 248 | 
            +
                  # ADB Shell command
         | 
| 249 | 
            +
                  # @param [String] serial serial number of device
         | 
| 250 | 
            +
                  # @param [String] command command to execute
         | 
| 251 | 
            +
                  def self.shell(serial, command)
         | 
| 252 | 
            +
                    result = execute("adb -s #{serial} shell #{command}")
         | 
| 253 | 
            +
             | 
| 254 | 
            +
                    case result.stderr
         | 
| 255 | 
            +
                    when /^error: device unauthorized./
         | 
| 256 | 
            +
                      raise DeviceAPI::UnauthorizedDevice, result.stderr
         | 
| 257 | 
            +
                    when /^error: device not found/
         | 
| 258 | 
            +
                      raise DeviceAPI::DeviceNotFound, result.stderr
         | 
| 259 | 
            +
                    else
         | 
| 260 | 
            +
                      raise ADBCommandError.new(result.stderr)
         | 
| 261 | 
            +
                    end if result.exit != 0
         | 
| 262 | 
            +
             | 
| 263 | 
            +
                    result
         | 
| 256 264 | 
             
                  end
         | 
| 257 265 |  | 
| 258 266 | 
             
                  # Sends a swipe command to the specified device
         | 
| @@ -263,8 +271,7 @@ module DeviceAPI | |
| 263 271 | 
             
                  # @option coords [String] :y_from (0) Coordinate to start from on the Y axis
         | 
| 264 272 | 
             
                  # @option coords [String] :y_to (0) Coordinate to end on on the Y axis
         | 
| 265 273 | 
             
                  def self.swipe(serial, coords = {x_from: 0, x_to: 0, y_from: 0, y_to: 0 })
         | 
| 266 | 
            -
                     | 
| 267 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 274 | 
            +
                    shell(serial, "input swipe #{coords[:x_from]} #{coords[:x_to]} #{coords[:y_from]} #{coords[:y_to]}").stdout
         | 
| 268 275 | 
             
                  end
         | 
| 269 276 |  | 
| 270 277 | 
             
                  # Starts intent using adb 
         | 
| @@ -274,9 +281,7 @@ module DeviceAPI | |
| 274 281 | 
             
                  # @example
         | 
| 275 282 | 
             
                  # DeviceAPI::ADB.am(serial, "start -a android.intent.action.MAIN -n com.android.settings/.wifi.WifiSettings")
         | 
| 276 283 | 
             
                  def self.am(serial, command)
         | 
| 277 | 
            -
                     | 
| 278 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 279 | 
            -
                    return result.stdout
         | 
| 284 | 
            +
                    shell(serial, "am #{command}").stdout
         | 
| 280 285 | 
             
                  end
         | 
| 281 286 |  | 
| 282 287 | 
             
                  # Package manager commands
         | 
| @@ -284,9 +289,7 @@ module DeviceAPI | |
| 284 289 | 
             
                  # @param command command to issue to the package manager
         | 
| 285 290 | 
             
                  # @example DeviceAPI::ADB.pm(serial, 'list packages')
         | 
| 286 291 | 
             
                  def self.pm(serial, command)
         | 
| 287 | 
            -
                     | 
| 288 | 
            -
                    raise ADBCommandError.new(result.stderr) if result.exit != 0
         | 
| 289 | 
            -
                    return result.stdout
         | 
| 292 | 
            +
                    shell(serial, "pm #{command}").stdout
         | 
| 290 293 | 
             
                  end
         | 
| 291 294 |  | 
| 292 295 | 
             
                  # Blocks a package, used on Android versions less than KitKat
         | 
| @@ -306,6 +309,8 @@ module DeviceAPI | |
| 306 309 | 
             
                    result = pm(serial, "hide #{package}")
         | 
| 307 310 | 
             
                    result.include?('true')
         | 
| 308 311 | 
             
                  end
         | 
| 312 | 
            +
             | 
| 313 | 
            +
             | 
| 309 314 | 
             
                end
         | 
| 310 315 |  | 
| 311 316 | 
             
                # ADB Error class
         | 
| @@ -315,6 +320,5 @@ module DeviceAPI | |
| 315 320 | 
             
                  end
         | 
| 316 321 | 
             
                end
         | 
| 317 322 |  | 
| 318 | 
            -
             | 
| 319 323 | 
             
              end
         | 
| 320 324 | 
             
            end
         | 
| @@ -258,14 +258,14 @@ module DeviceAPI | |
| 258 258 | 
             
                  def ip_address
         | 
| 259 259 | 
             
                    network = get_network_info
         | 
| 260 260 | 
             
                    wlan0 = network.detect { |a| a[:name] == 'wlan0' }
         | 
| 261 | 
            -
                    wlan0[:ip]
         | 
| 261 | 
            +
                    wlan0[:ip] unless wlan0.nil?
         | 
| 262 262 | 
             
                  end
         | 
| 263 263 |  | 
| 264 264 | 
             
                  # Returns the Wifi mac address
         | 
| 265 265 | 
             
                  def wifi_mac_address
         | 
| 266 266 | 
             
                    network = get_network_info
         | 
| 267 267 | 
             
                    wifi = network.detect { |a| a[:name] == 'wlan0' }
         | 
| 268 | 
            -
                    wifi[:mac]
         | 
| 268 | 
            +
                    wifi[:mac] unless wifi.nil?
         | 
| 269 269 | 
             
                  end
         | 
| 270 270 |  | 
| 271 271 | 
             
                  private
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            module DeviceAPI
         | 
| 2 | 
            +
              module Android
         | 
| 3 | 
            +
                module Plugin
         | 
| 4 | 
            +
                  class Audio
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                    attr_reader :serial
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    def initialize(options)
         | 
| 9 | 
            +
                      @serial = options #[:serial]
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                    def get_volume_steps
         | 
| 13 | 
            +
                      audio = ADB.dumpsys( @serial, 'audio' )
         | 
| 14 | 
            +
                      vol_steps = audio.detect { |a| a.include?('volume steps:') }
         | 
| 15 | 
            +
                      return nil if vol_steps.nil?
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                      vol_steps.scan(/volume steps: (.*)/).flatten.first.to_i
         | 
| 18 | 
            +
                    end
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                    def get_current_volume
         | 
| 21 | 
            +
                      system = get_system_volume
         | 
| 22 | 
            +
                      volume = system.select { |a| a.include?('Current') }.first
         | 
| 23 | 
            +
                      volume.scan(/Current: 2:\s(.*?),(:?.*)/).flatten.first.to_i
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                    end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                    def is_muted?
         | 
| 28 | 
            +
                      system = get_system_volume
         | 
| 29 | 
            +
                      mute = system.select { |a| a.include?('Mute') }.first
         | 
| 30 | 
            +
                      mute.scan(/Mute count: (.*)/).flatten.first.to_i > 0
         | 
| 31 | 
            +
                    end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                    def volume
         | 
| 34 | 
            +
                      return 0 if is_muted?
         | 
| 35 | 
            +
                      steps = get_volume_steps
         | 
| 36 | 
            +
                      vol = get_current_volume
         | 
| 37 | 
            +
                      ((vol.to_f / steps.to_f) * 100).to_i
         | 
| 38 | 
            +
                    end
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                    def max_volume
         | 
| 41 | 
            +
                      vol = get_current_volume
         | 
| 42 | 
            +
                      steps = get_volume_steps
         | 
| 43 | 
            +
             | 
| 44 | 
            +
                      change_volume(steps - vol, 24)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                      get_current_volume == steps
         | 
| 47 | 
            +
                    end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                    def min_volume
         | 
| 50 | 
            +
                      vol = get_current_volume
         | 
| 51 | 
            +
                      change_volume(vol, 25)
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                      get_current_volume == 0
         | 
| 54 | 
            +
                      # adb shell service call audio 4 i32 1 i32 0 i32 1
         | 
| 55 | 
            +
                    end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                    private
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                    def change_volume(op, key)
         | 
| 60 | 
            +
                      op.times do
         | 
| 61 | 
            +
                        ADB.keyevent(@serial, key )
         | 
| 62 | 
            +
                      end
         | 
| 63 | 
            +
                    end
         | 
| 64 | 
            +
             | 
| 65 | 
            +
                    def get_system_volume
         | 
| 66 | 
            +
                      audio = ADB.dumpsys( @serial, 'audio' )
         | 
| 67 | 
            +
                      index = audio.index('- STREAM_SYSTEM:')
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                      return nil if index.nil?
         | 
| 70 | 
            +
             | 
| 71 | 
            +
                      audio[index+1..index+2]
         | 
| 72 | 
            +
                    end
         | 
| 73 | 
            +
                  end
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: device_api-android
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.2. | 
| 4 | 
            +
              version: 1.2.2
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - David Buckhurst
         | 
| @@ -11,42 +11,36 @@ authors: | |
| 11 11 | 
             
            autorequire: 
         | 
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 | 
            -
            date:  | 
| 14 | 
            +
            date: 2016-02-09 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: device_api
         | 
| 18 18 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 19 19 | 
             
                requirements:
         | 
| 20 | 
            -
                - - " | 
| 20 | 
            +
                - - "~>"
         | 
| 21 21 | 
             
                  - !ruby/object:Gem::Version
         | 
| 22 | 
            -
                    version:  | 
| 23 | 
            -
                - - "<"
         | 
| 24 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 25 | 
            -
                    version: '2.0'
         | 
| 22 | 
            +
                    version: 1.0.2
         | 
| 26 23 | 
             
              type: :runtime
         | 
| 27 24 | 
             
              prerelease: false
         | 
| 28 25 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 29 26 | 
             
                requirements:
         | 
| 30 | 
            -
                - - " | 
| 31 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 32 | 
            -
                    version: '1.0'
         | 
| 33 | 
            -
                - - "<"
         | 
| 27 | 
            +
                - - "~>"
         | 
| 34 28 | 
             
                  - !ruby/object:Gem::Version
         | 
| 35 | 
            -
                    version:  | 
| 29 | 
            +
                    version: 1.0.2
         | 
| 36 30 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 37 31 | 
             
              name: rspec
         | 
| 38 32 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| 39 33 | 
             
                requirements:
         | 
| 40 | 
            -
                - - " | 
| 34 | 
            +
                - - "~>"
         | 
| 41 35 | 
             
                  - !ruby/object:Gem::Version
         | 
| 42 | 
            -
                    version: ' | 
| 36 | 
            +
                    version: '3'
         | 
| 43 37 | 
             
              type: :development
         | 
| 44 38 | 
             
              prerelease: false
         | 
| 45 39 | 
             
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 46 40 | 
             
                requirements:
         | 
| 47 | 
            -
                - - " | 
| 41 | 
            +
                - - "~>"
         | 
| 48 42 | 
             
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            -
                    version: ' | 
| 43 | 
            +
                    version: '3'
         | 
| 50 44 | 
             
            description: Android implementation of DeviceAPI
         | 
| 51 45 | 
             
            email: david.buckhurst@bbc.co.uk
         | 
| 52 46 | 
             
            executables: []
         | 
| @@ -60,6 +54,7 @@ files: | |
| 60 54 | 
             
            - lib/device_api/android/device.rb
         | 
| 61 55 | 
             
            - lib/device_api/android/device/kindle.rb
         | 
| 62 56 | 
             
            - lib/device_api/android/device/samsung.rb
         | 
| 57 | 
            +
            - lib/device_api/android/plugins/audio.rb
         | 
| 63 58 | 
             
            - lib/device_api/android/plugins/battery.rb
         | 
| 64 59 | 
             
            - lib/device_api/android/plugins/disk.rb
         | 
| 65 60 | 
             
            - lib/device_api/android/plugins/memory.rb
         | 
| @@ -84,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 84 79 | 
             
                  version: '0'
         | 
| 85 80 | 
             
            requirements: []
         | 
| 86 81 | 
             
            rubyforge_project: 
         | 
| 87 | 
            -
            rubygems_version: 2. | 
| 82 | 
            +
            rubygems_version: 2.5.0
         | 
| 88 83 | 
             
            signing_key: 
         | 
| 89 84 | 
             
            specification_version: 4
         | 
| 90 85 | 
             
            summary: Android Device Management API
         |