class AdbSdkLib::Device
One of android device attached to host through ADB.
This is a wrapper of com.android.ddmlib.Device object in Java.
Public Class Methods
@param [Rjb::Rjb_JavaProxy] device Rjb proxy object of com.android.ddmlib.Device
# 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.message, 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
Public Instance Methods
the API level of the android on the device. (same as output of ‘getprop ro.build.version.sdk’) @!attribute [r] api_level
@return [String] the API level.
# File lib/adb_sdklib/device.rb, line 97 def api_level; property(@device.PROP_BUILD_API_LEVEL) end
Returns the battery level. @param [Integer] freshness_ms freshness time (milliseconds). @return [Integer] the battery level.
# 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
@!attribute [r] bootloader? @return [Boolean] true if the device is in bootloader mode.
# File lib/adb_sdklib/device.rb, line 58 def bootloader?; @device.isBootloader end
the build code name of the android on the device. @!attribute [r] build_codename
(same as output of ‘getprop ro.build.version.codename’) @return [String] the build code name.
# File lib/adb_sdklib/device.rb, line 103 def build_codename; property(@device.PROP_BUILD_CODENAME) end
the build version of the android on the device. (same as output of ‘getprop ro.build.version.release’) @!attribute [r] build_version
@return [String] the build version of the android.
# File lib/adb_sdklib/device.rb, line 91 def build_version; property(@device.PROP_BUILD_VERSION) end
the device debuggable. (same as output of ‘getprop ro.debuggable’) @!attribute [r] debuggable @return [String] the device debuggable.
# File lib/adb_sdklib/device.rb, line 121 def debuggable; property(@device.PROP_DEBUGGABLE) end
the product manufacturer of the device. (same as output of ‘getprop ro.product.manufacturer’) @!attribute [r] device_manufacturer
@return [String] the product manufacturer.
# File lib/adb_sdklib/device.rb, line 115 def device_manufacturer; property(@device.PROP_DEVICE_MANUFACTURER) end
the product model of the device. (same as output of ‘getprop ro.product.model’) @!attribute [r] device_model
@return [String] the device model.
# File lib/adb_sdklib/device.rb, line 109 def device_model; property(@device.PROP_DEVICE_MODEL) end
@!attribute [r] emulator? @return [Boolean] true if the device is an emulator.
# File lib/adb_sdklib/device.rb, line 50 def emulator?; @device.isEmulator end
Returns the human-readable formatted information. @return [String] the human-readable formatted information
# File lib/adb_sdklib/device.rb, line 216 def inspect; "#<AdbSdkLib::Device:#{self.serial}>" end
@!attribute [r] jobject @return [Rjb::Rjb_JavaProxy] Wrapper of com.android.ddmlib.Device object.
# File lib/adb_sdklib/device.rb, line 33 def jobject; @device end
Calls wrapping java object’s same name method with arguments. @param [String] method_name method name to call @param [Array] args arguments @return [Object] result of the method call
# File lib/adb_sdklib/device.rb, line 206 def method_missing(method_name, *args) return @device.__send__(method_name, *args) end
@!attribute [r] offline? @return [Boolean] true if the device is offline.
# File lib/adb_sdklib/device.rb, line 54 def offline?; @device.isOffline end
@!attribute [r] online? @return [Boolean] true if the device is ready.
# File lib/adb_sdklib/device.rb, line 46 def online?; @device.isOnline end
Returns the device properties. It contains the whole output of ‘getprop’ @return [Hash<String, String>] the device properties
# 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
Returns a property value. @param [String] name the name of the value to return. @return [String, nil] the value or nil if the property does not exist.
# File lib/adb_sdklib/device.rb, line 77 def property(name); @device.getProperty(name) end
Returns the property count. @return [Integer] the number of property for this device.
# File lib/adb_sdklib/device.rb, line 72 def property_count; @device.getPropertyCount end
Pulls a file from the device.
If localfile path ends with ‘/’, complements by the basename of remotefile. @example
device = AdbSdkLib::Adb.new.devices.first device.pull('/data/local/tmp/remote.txt', 'path/to/local.txt') device.pull('/data/local/tmp/file.txt', 'path/to/dir/') # uses file.txt
@param [String] remotefile the name of the remote file on the device to get @param [String] localfile the name of the local file or directory @return [self] self
# 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
Pushes a file to the device.
If remotefile path ends with ‘/’, complements by the basename of localfile. @example
device = AdbSdkLib::Adb.new.devices.first device.push('path/to/local.txt', '/data/local/tmp/remote.txt') device.push('path/to/file.txt', '/data/local/tmp/') # uses file.txt
@param [String] localfile the name of the local file to send @param [String] remotefile the name of the remote file or directory
on the device
@return [self] self @raise [ArgumentError] If localfile is not found
# 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 the device @param [String, nil] into the bootloader name to reboot into,
or nil to just reboot the device
@return [self]
# File lib/adb_sdklib/device.rb, line 68 def reboot(into=nil) @device.reboot(into); self end
Get a screenshot from the device @return [AdbSdkLib::RawImage] Wrapper of com.android.ddmlib.RawImage object.
# File lib/adb_sdklib/device.rb, line 62 def screenshot(); RawImage.new(@device.getScreenshot()) end
@!attribute [r] serial @return [String] the serial number of the device.
# File lib/adb_sdklib/device.rb, line 37 def serial; @device.getSerialNumber end
Executes a shell command on the device, and receives the result. @!method shell(command) @return [String, self] @overload shell(command)
@param [String] command the command to execute @return [String] all results of the command.
@overload shell(command)
@param [String] command the command to execute @return [self] self @yield [line] @yieldparam [String] line each line of results of the command.
# 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
@!attribute [r] state @return [Symbol] the state of the device.
(:BOOTLOADER, :OFFLINE, :ONLINE, :RECOVERY)
# File lib/adb_sdklib/device.rb, line 42 def state; @device.getState.toString.to_sym end
Converts self to string. @return [String] convert to string
# File lib/adb_sdklib/device.rb, line 212 def to_s; "Android:#{self.serial}" end
Private Instance Methods
@private
# File lib/adb_sdklib/device.rb, line 220 def to_ary; nil end