Skip to content

Commit dc8e3eb

Browse files
Add handlers for gsm, network, power and sms command
1 parent 11aa8f5 commit dc8e3eb

File tree

9 files changed

+320
-0
lines changed

9 files changed

+320
-0
lines changed

src/main/java/io/appium/java_client/MobileCommand.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ public class MobileCommand {
8585
protected static final String GET_SETTINGS;
8686
protected static final String SET_SETTINGS;
8787
protected static final String GET_CURRENT_PACKAGE;
88+
protected static final String SEND_SMS;
89+
protected static final String GSM_CALL;
90+
protected static final String GSM_SIGNAL;
91+
protected static final String GSM_VOICE;
92+
protected static final String NETWORK_SPEED;
93+
protected static final String POWER_CAPACITY;
94+
protected static final String POWER_AC_STATE;
8895

8996
public static final Map<String, CommandInfo> commandRepository;
9097

@@ -137,6 +144,13 @@ public class MobileCommand {
137144
GET_SETTINGS = "getSettings";
138145
SET_SETTINGS = "setSettings";
139146
GET_CURRENT_PACKAGE = "getCurrentPackage";
147+
SEND_SMS = "sendSMS";
148+
GSM_CALL = "gsmCall";
149+
GSM_SIGNAL = "gsmSignal";
150+
GSM_VOICE = "gsmVoice";
151+
NETWORK_SPEED = "networkSpeed";
152+
POWER_CAPACITY = "powerCapacity";
153+
POWER_AC_STATE = "powerAC";
140154

141155
commandRepository = new HashMap<>();
142156
commandRepository.put(RESET, postC("/session/:sessionId/appium/app/reset"));
@@ -198,6 +212,13 @@ public class MobileCommand {
198212
commandRepository.put(UNLOCK, postC("/session/:sessionId/appium/device/unlock"));
199213
commandRepository.put(REPLACE_VALUE, postC("/session/:sessionId/appium/element/:id/replace_value"));
200214
commandRepository.put(GET_CURRENT_PACKAGE, getC("/session/:sessionId/appium/device/current_package"));
215+
commandRepository.put(SEND_SMS, postC("/session/:sessionId/appium/device/send_sms"));
216+
commandRepository.put(GSM_CALL, postC("/session/:sessionId/appium/device/gsm_call"));
217+
commandRepository.put(GSM_SIGNAL, postC("/session/:sessionId/appium/device/gsm_signal"));
218+
commandRepository.put(GSM_VOICE, postC("/session/:sessionId/appium/device/gsm_voice"));
219+
commandRepository.put(NETWORK_SPEED, postC("/session/:sessionId/appium/device/network_speed"));
220+
commandRepository.put(POWER_CAPACITY, postC("/session/:sessionId/appium/device/power_capacity"));
221+
commandRepository.put(POWER_AC_STATE, postC("/session/:sessionId/appium/device/power_ac"));
201222
}
202223

203224
/**

src/main/java/io/appium/java_client/android/AndroidDriver.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@
1717
package io.appium.java_client.android;
1818

1919
import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand;
20+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmCallCommand;
21+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmSignalStrengthCommand;
22+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmVoiceCommand;
23+
import static io.appium.java_client.android.AndroidMobileCommandHelper.networkSpeedCommand;
2024
import static io.appium.java_client.android.AndroidMobileCommandHelper.openNotificationsCommand;
25+
import static io.appium.java_client.android.AndroidMobileCommandHelper.powerACCommand;
26+
import static io.appium.java_client.android.AndroidMobileCommandHelper.powerCapacityCommand;
27+
import static io.appium.java_client.android.AndroidMobileCommandHelper.sendSMSCommand;
2128
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;
2229

2330
import io.appium.java_client.AppiumDriver;
@@ -176,4 +183,68 @@ public void toggleLocationServices() {
176183
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
177184
}
178185

186+
/**
187+
* Emulate send SMS event on the connected emulator.
188+
*
189+
* @param phoneNumber The phone number of message sender.
190+
* @param message The message content.
191+
*/
192+
public void sendSMS(String phoneNumber, String message) {
193+
CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message));
194+
}
195+
196+
/**
197+
* Emulate GSM call event on the connected emulator.
198+
*
199+
* @param phoneNumber The phone number of the caller.
200+
* @param gsmCallActions One of available GSM call actions.
201+
*/
202+
public void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) {
203+
CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions));
204+
}
205+
206+
/**
207+
* Emulate GSM signal strength change event on the connected emulator.
208+
*
209+
* @param gsmSignalStrength One of available GSM signal strength.
210+
*/
211+
public void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) {
212+
CommandExecutionHelper.execute(this, gsmSignalStrengthCommand(gsmSignalStrength));
213+
}
214+
215+
/**
216+
* Emulate GSM voice event on the connected emulator.
217+
*
218+
* @param gsmVoiceState One of available GSM voice state.
219+
*/
220+
public void gsmVoice(GsmVoiceState gsmVoiceState) {
221+
CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState));
222+
}
223+
224+
/**
225+
* Emulate network speed change event on the connected emulator.
226+
*
227+
* @param networkSpeed One of available Network Speed values.
228+
*/
229+
public void networkSpeed(NetworkSpeed networkSpeed) {
230+
CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed));
231+
}
232+
233+
/**
234+
* Emulate power capacity change on the connected emulator.
235+
*
236+
* @param percent Percentage value in range [0, 100].
237+
*/
238+
public void powerCapacity(int percent) {
239+
CommandExecutionHelper.execute(this, powerCapacityCommand(percent));
240+
}
241+
242+
/**
243+
* Emulate power state change on the connected emulator.
244+
*
245+
* @param powerACState One of available Power AC state.
246+
*/
247+
public void powerAC(PowerACState powerACState) {
248+
CommandExecutionHelper.execute(this, powerACCommand(powerACState));
249+
}
179250
}

src/main/java/io/appium/java_client/android/AndroidMobileCommandHelper.java

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,109 @@ public class AndroidMobileCommandHelper extends MobileCommand {
291291
return new AbstractMap.SimpleEntry<>(
292292
REPLACE_VALUE, prepareArguments(parameters, values));
293293
}
294+
295+
/**
296+
* This method forms a {@link Map} of parameters for the element
297+
* value replacement. It is used against input elements
298+
*
299+
* @param phoneNumber The phone number of message sender
300+
* @param message The message content
301+
*
302+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
303+
*/
304+
public static Map.Entry<String, Map<String, ?>> sendSMSCommand(
305+
String phoneNumber, String message) {
306+
ImmutableMap<String, ?> parameters = ImmutableMap
307+
.<String, Object>builder().put("phoneNumber", phoneNumber)
308+
.put("message", message)
309+
.build();
310+
311+
return new AbstractMap.SimpleEntry<>(SEND_SMS, parameters);
312+
}
313+
314+
/**
315+
* This method forms a {@link Map} of parameters for the element
316+
* value replacement. It is used against input elements
317+
*
318+
* @param phoneNumber The phone number of message sender
319+
* @param gsmCallActions One of available GSM call actions
320+
*
321+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
322+
*/
323+
public static Map.Entry<String, Map<String, ?>> gsmCallCommand(
324+
String phoneNumber, GsmCallActions gsmCallActions) {
325+
String[] parameters = new String[] {"phoneNumber", "action"};
326+
Object[] values = new Object[]{phoneNumber, gsmCallActions.toString()};
327+
return new AbstractMap.SimpleEntry<>(GSM_CALL, prepareArguments(parameters, values));
328+
}
329+
330+
/**
331+
* This method forms a {@link Map} of parameters for the element
332+
* value replacement. It is used against input elements
333+
*
334+
* @param gsmSignalStrength One of available GSM signal strength
335+
*
336+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
337+
*/
338+
public static Map.Entry<String, Map<String, ?>> gsmSignalStrengthCommand(
339+
GsmSignalStrength gsmSignalStrength) {
340+
return new AbstractMap.SimpleEntry<>(GSM_SIGNAL,
341+
prepareArguments("signalStrengh", gsmSignalStrength.getValue()));
342+
}
343+
344+
/**
345+
* This method forms a {@link Map} of parameters for the element
346+
* value replacement. It is used against input elements
347+
*
348+
* @param gsmVoiceState One of available GSM voice state
349+
*
350+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
351+
*/
352+
public static Map.Entry<String, Map<String, ?>> gsmVoiceCommand(
353+
GsmVoiceState gsmVoiceState) {
354+
return new AbstractMap.SimpleEntry<>(GSM_VOICE,
355+
prepareArguments("state", gsmVoiceState.toString()));
356+
}
357+
358+
/**
359+
* This method forms a {@link Map} of parameters for the element
360+
* value replacement. It is used against input elements
361+
*
362+
* @param networkSpeed One of possible NETWORK_SPEED values
363+
*
364+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
365+
*/
366+
public static Map.Entry<String, Map<String, ?>> networkSpeedCommand(
367+
NetworkSpeed networkSpeed) {
368+
return new AbstractMap.SimpleEntry<>(NETWORK_SPEED,
369+
prepareArguments("netspeed", networkSpeed.toString()));
370+
}
371+
372+
/**
373+
* This method forms a {@link Map} of parameters for the element
374+
* value replacement. It is used against input elements
375+
*
376+
* @param percent A number in range [0, 4]
377+
*
378+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
379+
*/
380+
public static Map.Entry<String, Map<String, ?>> powerCapacityCommand(
381+
int percent) {
382+
return new AbstractMap.SimpleEntry<>(POWER_CAPACITY,
383+
prepareArguments("percent", percent));
384+
}
385+
386+
/**
387+
* This method forms a {@link Map} of parameters for the element
388+
* value replacement. It is used against input elements
389+
*
390+
* @param powerACState One of available power AC state
391+
*
392+
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
393+
*/
394+
public static Map.Entry<String, Map<String, ?>> powerACCommand(
395+
PowerACState powerACState) {
396+
return new AbstractMap.SimpleEntry<>(POWER_AC_STATE,
397+
prepareArguments("state", powerACState.toString()));
398+
}
294399
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package io.appium.java_client.android;
2+
3+
public enum GsmCallActions {
4+
CALL("call"),
5+
ACCEPT("accept"),
6+
CANCEL("cancel"),
7+
HOLD("hold");
8+
9+
private final String gsmcall;
10+
11+
GsmCallActions(String gsmcall) {
12+
this.gsmcall = gsmcall;
13+
}
14+
15+
@Override public String toString() {
16+
return this.gsmcall;
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.appium.java_client.android;
2+
3+
public enum GsmSignalStrength {
4+
NONE_OR_UNKNOWN(0),
5+
POOR(1),
6+
MODERATE(2),
7+
GOOD(3),
8+
GREAT(4);
9+
10+
private final int gsmSignalStrength;
11+
12+
GsmSignalStrength(int gsmSignalStrength) {
13+
this.gsmSignalStrength = gsmSignalStrength;
14+
}
15+
16+
public int getValue() { return gsmSignalStrength; }
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.appium.java_client.android;
2+
3+
public enum GsmVoiceState {
4+
ON("on"),
5+
OFF("off"),
6+
DENIED("denied"),
7+
SEARCHING("searching"),
8+
ROAMING("roaming"),
9+
HOME("home"),
10+
UNREGISTERED("unregistered");
11+
12+
private final String gsmVoiceState;
13+
14+
GsmVoiceState(String gsmVoiceState) {
15+
this.gsmVoiceState = gsmVoiceState;
16+
}
17+
18+
@Override public String toString() {
19+
return this.gsmVoiceState;
20+
}
21+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.appium.java_client.android;
2+
3+
public enum NetworkSpeed {
4+
GSM("gsm"),
5+
SCSD("scsd"),
6+
GPRS("gprs"),
7+
EDGE("edge"),
8+
UMTS("umts"),
9+
HSDPA("hsdpa"),
10+
LTE("lte"),
11+
EVDO("evdo"),
12+
FULL("full");
13+
14+
private final String networkSpeed;
15+
16+
NetworkSpeed(String networkSpeed) {
17+
this.networkSpeed = networkSpeed;
18+
}
19+
20+
@Override public String toString() {
21+
return this.networkSpeed;
22+
}
23+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.appium.java_client.android;
2+
3+
public enum PowerACState {
4+
ON("on"),
5+
OFF("off");
6+
7+
private final String powerACState;
8+
9+
PowerACState(String powerACState) {
10+
this.powerACState = powerACState;
11+
}
12+
13+
@Override public String toString() {
14+
return this.powerACState;
15+
}
16+
}

src/test/java/io/appium/java_client/android/AndroidDriverTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,34 @@
3737

3838
public class AndroidDriverTest extends BaseAndroidTest {
3939

40+
@Test public void sendSMSTest() {
41+
driver.sendSMS("11111111", "call");
42+
}
43+
44+
@Test public void gsmCallTest() {
45+
driver.gsmCall("11111111", GsmCallActions.CALL);
46+
driver.gsmCall("11111111", GsmCallActions.ACCEPT);
47+
}
48+
49+
@Test public void gsmSignalStrengthTest() {
50+
driver.gsmSignalStrength(GsmSignalStrength.GREAT);
51+
}
52+
53+
@Test public void gsmVoiceTest() {
54+
driver.gsmVoice(GsmVoiceState.OFF);
55+
}
56+
57+
@Test public void networkSpeedTest() {
58+
driver.networkSpeed(NetworkSpeed.LTE);
59+
driver.powerCapacity(50);
60+
driver.powerAC(PowerACState.ON);
61+
}
62+
63+
@Test public void powerTest() {
64+
driver.powerCapacity(50);
65+
driver.powerAC(PowerACState.ON);
66+
}
67+
4068
@Test public void getDeviceTimeTest() {
4169
String time = driver.getDeviceTime();
4270
assertTrue(time.length() == 28);

0 commit comments

Comments
 (0)