Class: AdbSdkLib::Device
- Inherits:
-
Object
- Object
- AdbSdkLib::Device
- Defined in:
- lib/adb_sdklib/device.rb
Overview
One of android device attached to host through ADB.
This is a wrapper of com.android.ddmlib.Device object in Java.
Instance Attribute Summary collapse
-
#api_level ⇒ String
readonly
the API level of the android on the device.
-
#bootloader? ⇒ Boolean
readonly
True if the device is in bootloader mode.
-
#build_codename ⇒ String
readonly
the build code name of the android on the device.
-
#build_version ⇒ String
readonly
the build version of the android on the device.
-
#debuggable ⇒ String
readonly
the device debuggable.
-
#device_manufacturer ⇒ String
readonly
the product manufacturer of the device.
-
#device_model ⇒ String
readonly
the product model of the device.
-
#emulator? ⇒ Boolean
readonly
True if the device is an emulator.
-
#jobject ⇒ Rjb::Rjb_JavaProxy
readonly
Wrapper of com.android.ddmlib.Device object.
-
#offline? ⇒ Boolean
readonly
True if the device is offline.
-
#online? ⇒ Boolean
readonly
True if the device is ready.
-
#serial ⇒ String
readonly
The serial number of the device.
-
#state ⇒ Symbol
readonly
The state of the device.
Instance Method Summary collapse
-
#battery_level(freshness_ms = nil) ⇒ Integer
Returns the battery level.
-
#initialize(device) ⇒ Device
constructor
A new instance of Device.
-
#inspect ⇒ String
Returns the human-readable formatted information.
-
#method_missing(method_name, *args) ⇒ Object
Calls wrapping java object’s same name method with arguments.
-
#properties ⇒ Hash<String, String>
Returns the device properties.
-
#property(name) ⇒ String?
Returns a property value.
-
#property_count ⇒ Integer
Returns the property count.
-
#pull(remotefile, localfile) ⇒ self
Pulls a file from the device.
-
#push(localfile, remotefile) ⇒ self
Pushes a file to the device.
-
#reboot(into = nil) ⇒ self
Reboot the device.
-
#screenshot ⇒ AdbSdkLib::RawImage
Get a screenshot from the device.
-
#shell(command) ⇒ String, self
Executes a shell command on the device, and receives the result.
-
#to_s ⇒ String
Converts self to string.
Constructor Details
#initialize(device) ⇒ Device
Returns a new instance of Device.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/adb_sdklib/device.rb', line 14 def initialize(device) unless device.instance_of?(Rjb::Rjb_JavaProxy) && device._classname == 'com.android.ddmlib.Device' raise TypeError, "Parameter is not com.android.ddmlib.Device class" end class << device def call_java_method(method_name, *args) rjb_method_missing(method_name, *args) rescue => e raise SdkLibError.new(e., e.class.to_s, self._classname, method_name) end alias_method :rjb_method_missing, :method_missing alias_method :method_missing, :call_java_method end @device = device end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
Calls wrapping java object’s same name method with arguments.
206 207 208 |
# File 'lib/adb_sdklib/device.rb', line 206 def method_missing(method_name, *args) return @device.__send__(method_name, *args) end |
Instance Attribute Details
#api_level ⇒ String (readonly)
the API level of the android on the device. (same as output of ‘getprop ro.build.version.sdk’)
97 |
# File 'lib/adb_sdklib/device.rb', line 97 def api_level; property(@device.PROP_BUILD_API_LEVEL) end |
#bootloader? ⇒ Boolean (readonly)
Returns true if the device is in bootloader mode.
58 |
# File 'lib/adb_sdklib/device.rb', line 58 def bootloader?; @device.isBootloader end |
#build_codename ⇒ String (readonly)
the build code name of the android on the device. (same as output of ‘getprop ro.build.version.codename’)
103 |
# File 'lib/adb_sdklib/device.rb', line 103 def build_codename; property(@device.PROP_BUILD_CODENAME) end |
#build_version ⇒ String (readonly)
the build version of the android on the device. (same as output of ‘getprop ro.build.version.release’)
91 |
# File 'lib/adb_sdklib/device.rb', line 91 def build_version; property(@device.PROP_BUILD_VERSION) end |
#debuggable ⇒ String (readonly)
the device debuggable. (same as output of ‘getprop ro.debuggable’)
121 |
# File 'lib/adb_sdklib/device.rb', line 121 def debuggable; property(@device.PROP_DEBUGGABLE) end |
#device_manufacturer ⇒ String (readonly)
the product manufacturer of the device. (same as output of ‘getprop ro.product.manufacturer’)
115 |
# File 'lib/adb_sdklib/device.rb', line 115 def device_manufacturer; property(@device.PROP_DEVICE_MANUFACTURER) end |
#device_model ⇒ String (readonly)
the product model of the device. (same as output of ‘getprop ro.product.model’)
109 |
# File 'lib/adb_sdklib/device.rb', line 109 def device_model; property(@device.PROP_DEVICE_MODEL) end |
#emulator? ⇒ Boolean (readonly)
Returns true if the device is an emulator.
50 |
# File 'lib/adb_sdklib/device.rb', line 50 def emulator?; @device.isEmulator end |
#jobject ⇒ Rjb::Rjb_JavaProxy (readonly)
Returns Wrapper of com.android.ddmlib.Device object.
33 |
# File 'lib/adb_sdklib/device.rb', line 33 def jobject; @device end |
#offline? ⇒ Boolean (readonly)
Returns true if the device is offline.
54 |
# File 'lib/adb_sdklib/device.rb', line 54 def offline?; @device.isOffline end |
#online? ⇒ Boolean (readonly)
Returns true if the device is ready.
46 |
# File 'lib/adb_sdklib/device.rb', line 46 def online?; @device.isOnline end |
#serial ⇒ String (readonly)
Returns the serial number of the device.
37 |
# File 'lib/adb_sdklib/device.rb', line 37 def serial; @device.getSerialNumber end |
#state ⇒ Symbol (readonly)
Returns the state of the device. (:BOOTLOADER, :OFFLINE, :ONLINE, :RECOVERY).
42 |
# File 'lib/adb_sdklib/device.rb', line 42 def state; @device.getState.toString.to_sym end |
Instance Method Details
#battery_level(freshness_ms = nil) ⇒ Integer
Returns the battery level.
126 127 128 129 130 131 132 |
# File 'lib/adb_sdklib/device.rb', line 126 def battery_level(freshness_ms = nil) if freshness_ms.nil? @device.getBatteryLevel.intValue else @device.getBatteryLevel(freshness_ms).intValue end end |
#inspect ⇒ String
Returns the human-readable formatted information.
216 |
# File 'lib/adb_sdklib/device.rb', line 216 def inspect; "#<AdbSdkLib::Device:#{self.serial}>" end |
#properties ⇒ Hash<String, String>
Returns the device properties. It contains the whole output of ‘getprop’
81 82 83 84 85 |
# File 'lib/adb_sdklib/device.rb', line 81 def properties convert_map_to_hash(@device.getProperties) do |hash, key, value| hash[key.toString] = value.toString end end |
#property(name) ⇒ String?
Returns a property value.
77 |
# File 'lib/adb_sdklib/device.rb', line 77 def property(name); @device.getProperty(name) end |
#property_count ⇒ Integer
Returns the property count.
72 |
# File 'lib/adb_sdklib/device.rb', line 72 def property_count; @device.getPropertyCount end |
#pull(remotefile, localfile) ⇒ self
Pulls a file from the device.
If localfile path ends with ‘/’, complements by the basename of remotefile.
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/adb_sdklib/device.rb', line 185 def pull(remotefile, localfile) if localfile.end_with?('/') || File.directory?(localfile) localdir = localfile.chomp('/') localfilename = nil else localdir = File.dirname(localfile) localfilename = File.basename(localfile) end unless File.exist?(localdir) FileUtils.mkdir_p(localdir) end localfilename = File.basename(remotefile) if localfilename.nil? @device.pullFile(remotefile, "#{localdir}/#{localfilename}") self end |
#push(localfile, remotefile) ⇒ self
Pushes a file to the device.
If remotefile path ends with ‘/’, complements by the basename of localfile.
165 166 167 168 169 170 171 172 |
# File 'lib/adb_sdklib/device.rb', line 165 def push(localfile, remotefile) raise ArgumentError, "Not found #{localfile}" unless File.exist?(localfile) if remotefile.end_with?('/') remotefile = "#{remotefile}#{File.basename(localfile)}" end @device.pushFile(localfile, remotefile) self end |
#reboot(into = nil) ⇒ self
Reboot the device
68 |
# File 'lib/adb_sdklib/device.rb', line 68 def reboot(into=nil) @device.reboot(into); self end |
#screenshot ⇒ AdbSdkLib::RawImage
Get a screenshot from the device
62 |
# File 'lib/adb_sdklib/device.rb', line 62 def screenshot(); RawImage.new(@device.getScreenshot()) end |
#shell(command) ⇒ String #shell(command) {|line| ... } ⇒ self
Executes a shell command on the device, and receives the result.
145 146 147 148 149 150 |
# File 'lib/adb_sdklib/device.rb', line 145 def shell(command, &block) capture = CommandCapture.new(block_given? ? block : nil) receiver = Rjb::bind(capture, 'com.android.ddmlib.IShellOutputReceiver') @device.executeShellCommand(command.to_s, receiver) block_given? ? self : capture.to_s end |
#to_s ⇒ String
Converts self to string.
212 |
# File 'lib/adb_sdklib/device.rb', line 212 def to_s; "Android:#{self.serial}" end |