-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathairplane_mode.rb
41 lines (34 loc) · 929 Bytes
/
airplane_mode.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true
require_relative 'packages'
require_relative 'check_rooted'
require 'open3'
class AirplaneMode
def self.name
'airplane_mode'
end
def self.perform(*args)
input = args[0]
return unless validate_input(input)
case input
when 'on'
Open3.capture2('adb shell settings put global airplane_mode_on 1')
when 'off'
Open3.capture2('adb shell settings put global airplane_mode_on 0')
end
if check_rooted
Open3.capture2('adb shell am broadcast -a android.intent.action.AIRPLANE_MODE')
else
puts('Unrooted device requires restart before airplane mode takes effect. Run $ ax reboot.')
end
end
def self.validate_input(input)
if input.nil? || (input != 'off' && input != 'on')
puts 'Invalid input. Options are: on off'
return false
end
true
end
def self.similar_sounding_commands
%w[cell wifi]
end
end