Class: DeviceAPI::Android::Plugin::Audio

Inherits:
Object
  • Object
show all
Defined in:
lib/device_api/android/plugins/audio.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Audio

Returns a new instance of Audio.



8
9
10
# File 'lib/device_api/android/plugins/audio.rb', line 8

def initialize(options)
  @qualifier = options #[:serial]
end

Instance Attribute Details

#qualifierObject (readonly)

Returns the value of attribute qualifier.



6
7
8
# File 'lib/device_api/android/plugins/audio.rb', line 6

def qualifier
  @qualifier
end

Instance Method Details

#get_current_volumeObject



20
21
22
23
24
25
# File 'lib/device_api/android/plugins/audio.rb', line 20

def get_current_volume
  system = get_system_volume
  volume = system.select { |a| a.include?('Current') }.first
  volume.scan(/Current: 2:\s(.*?),(:?.*)/).flatten.first.to_i

end

#get_volume_stepsObject



12
13
14
15
16
17
18
# File 'lib/device_api/android/plugins/audio.rb', line 12

def get_volume_steps
  audio = ADB.dumpsys( @qualifier, 'audio' )
  vol_steps = audio.detect { |a| a.include?('volume steps:') }
  return nil if vol_steps.nil?

  vol_steps.scan(/volume steps: (.*)/).flatten.first.to_i
end

#is_muted?Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/device_api/android/plugins/audio.rb', line 27

def is_muted?
  system = get_system_volume
  mute = system.select { |a| a.include?('Mute') }.first
  mute.scan(/Mute count: (.*)/).flatten.first.to_i > 0
end

#max_volumeObject



40
41
42
43
44
45
46
47
# File 'lib/device_api/android/plugins/audio.rb', line 40

def max_volume
  vol = get_current_volume
  steps = get_volume_steps

  change_volume(steps - vol, 24)

  get_current_volume == steps
end

#min_volumeObject



49
50
51
52
53
54
55
# File 'lib/device_api/android/plugins/audio.rb', line 49

def min_volume
  vol = get_current_volume
  change_volume(vol, 25)

  get_current_volume == 0
  # adb shell service call audio 4 i32 1 i32 0 i32 1
end

#volumeObject



33
34
35
36
37
38
# File 'lib/device_api/android/plugins/audio.rb', line 33

def volume
  return 0 if is_muted?
  steps = get_volume_steps
  vol = get_current_volume
  ((vol.to_f / steps.to_f) * 100).to_i
end