Skip to content

Commit 0fdc028

Browse files
fixed review comments
1 parent dc8e3eb commit 0fdc028

File tree

9 files changed

+103
-165
lines changed

9 files changed

+103
-165
lines changed

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

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,7 @@
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;
2420
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;
2821
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;
2922

3023
import io.appium.java_client.AppiumDriver;
@@ -58,7 +51,8 @@ public class AndroidDriver<T extends WebElement>
5851
extends AppiumDriver<T>
5952
implements PressesKeyCode, HasNetworkConnection, PushesFiles, StartsActivity,
6053
FindsByAndroidUIAutomator<T>, LocksDevice, HasAndroidSettings, HasDeviceDetails,
61-
HasSupportedPerformanceDataType, AuthenticatesByFinger, CanRecordScreen {
54+
HasSupportedPerformanceDataType, AuthenticatesByFinger,
55+
CanRecordScreen, SupportsSpecialEmulatorCommands {
6256

6357
private static final String ANDROID_PLATFORM = MobilePlatform.ANDROID;
6458

@@ -182,69 +176,4 @@ public void openNotifications() {
182176
public void toggleLocationServices() {
183177
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
184178
}
185-
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-
}
250179
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
301301
*
302302
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
303303
*/
304-
public static Map.Entry<String, Map<String, ?>> sendSMSCommand(
304+
public static Map.Entry<String, Map<String, ?>> sendSMSCommand(
305305
String phoneNumber, String message) {
306306
ImmutableMap<String, ?> parameters = ImmutableMap
307307
.<String, Object>builder().put("phoneNumber", phoneNumber)
@@ -320,10 +320,10 @@ public class AndroidMobileCommandHelper extends MobileCommand {
320320
*
321321
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
322322
*/
323-
public static Map.Entry<String, Map<String, ?>> gsmCallCommand(
323+
public static Map.Entry<String, Map<String, ?>> gsmCallCommand(
324324
String phoneNumber, GsmCallActions gsmCallActions) {
325325
String[] parameters = new String[] {"phoneNumber", "action"};
326-
Object[] values = new Object[]{phoneNumber, gsmCallActions.toString()};
326+
Object[] values = new Object[]{phoneNumber, gsmCallActions.name().toLowerCase()};
327327
return new AbstractMap.SimpleEntry<>(GSM_CALL, prepareArguments(parameters, values));
328328
}
329329

@@ -335,10 +335,10 @@ public class AndroidMobileCommandHelper extends MobileCommand {
335335
*
336336
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
337337
*/
338-
public static Map.Entry<String, Map<String, ?>> gsmSignalStrengthCommand(
338+
public static Map.Entry<String, Map<String, ?>> gsmSignalStrengthCommand(
339339
GsmSignalStrength gsmSignalStrength) {
340340
return new AbstractMap.SimpleEntry<>(GSM_SIGNAL,
341-
prepareArguments("signalStrengh", gsmSignalStrength.getValue()));
341+
prepareArguments("signalStrengh", gsmSignalStrength.ordinal()));
342342
}
343343

344344
/**
@@ -349,10 +349,10 @@ public class AndroidMobileCommandHelper extends MobileCommand {
349349
*
350350
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
351351
*/
352-
public static Map.Entry<String, Map<String, ?>> gsmVoiceCommand(
352+
public static Map.Entry<String, Map<String, ?>> gsmVoiceCommand(
353353
GsmVoiceState gsmVoiceState) {
354354
return new AbstractMap.SimpleEntry<>(GSM_VOICE,
355-
prepareArguments("state", gsmVoiceState.toString()));
355+
prepareArguments("state", gsmVoiceState.name().toLowerCase()));
356356
}
357357

358358
/**
@@ -363,10 +363,10 @@ public class AndroidMobileCommandHelper extends MobileCommand {
363363
*
364364
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
365365
*/
366-
public static Map.Entry<String, Map<String, ?>> networkSpeedCommand(
366+
public static Map.Entry<String, Map<String, ?>> networkSpeedCommand(
367367
NetworkSpeed networkSpeed) {
368368
return new AbstractMap.SimpleEntry<>(NETWORK_SPEED,
369-
prepareArguments("netspeed", networkSpeed.toString()));
369+
prepareArguments("netspeed", networkSpeed.name().toLowerCase()));
370370
}
371371

372372
/**
@@ -377,7 +377,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
377377
*
378378
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
379379
*/
380-
public static Map.Entry<String, Map<String, ?>> powerCapacityCommand(
380+
public static Map.Entry<String, Map<String, ?>> powerCapacityCommand(
381381
int percent) {
382382
return new AbstractMap.SimpleEntry<>(POWER_CAPACITY,
383383
prepareArguments("percent", percent));
@@ -391,9 +391,9 @@ public class AndroidMobileCommandHelper extends MobileCommand {
391391
*
392392
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
393393
*/
394-
public static Map.Entry<String, Map<String, ?>> powerACCommand(
394+
public static Map.Entry<String, Map<String, ?>> powerACCommand(
395395
PowerACState powerACState) {
396396
return new AbstractMap.SimpleEntry<>(POWER_AC_STATE,
397-
prepareArguments("state", powerACState.toString()));
397+
prepareArguments("state", powerACState.name().toLowerCase()));
398398
}
399399
}
Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,5 @@
11
package io.appium.java_client.android;
22

33
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-
}
4+
CALL, ACCEPT, CANCEL, HOLD
185
}
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
package io.appium.java_client.android;
22

33
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; }
4+
NONE_OR_UNKNOWN, POOR, MODERATE, GOOD, GREAT
175
}
Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,5 @@
11
package io.appium.java_client.android;
22

33
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-
}
4+
ON, OFF, DENIED, SEARCHING, ROAMING, HOME, UNREGISTERED
215
}
Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
package io.appium.java_client.android;
22

33
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-
}
4+
GSM, SCSD, GPRS, EDGE, UMTS, HSDPA, LTE, EVDO, FULL
235
}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
package io.appium.java_client.android;
22

33
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-
}
4+
ON, OFF
165
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package io.appium.java_client.android;
2+
3+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmCallCommand;
4+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmSignalStrengthCommand;
5+
import static io.appium.java_client.android.AndroidMobileCommandHelper.gsmVoiceCommand;
6+
import static io.appium.java_client.android.AndroidMobileCommandHelper.networkSpeedCommand;
7+
import static io.appium.java_client.android.AndroidMobileCommandHelper.powerACCommand;
8+
import static io.appium.java_client.android.AndroidMobileCommandHelper.powerCapacityCommand;
9+
import static io.appium.java_client.android.AndroidMobileCommandHelper.sendSMSCommand;
10+
11+
import io.appium.java_client.CommandExecutionHelper;
12+
import io.appium.java_client.ExecutesMethod;
13+
14+
public interface SupportsSpecialEmulatorCommands extends ExecutesMethod {
15+
16+
/**
17+
* Emulate send SMS event on the connected emulator.
18+
*
19+
* @param phoneNumber The phone number of message sender.
20+
* @param message The message content.
21+
*/
22+
default void sendSMS(String phoneNumber, String message) {
23+
CommandExecutionHelper.execute(this, sendSMSCommand(phoneNumber, message));
24+
}
25+
26+
/**
27+
* Emulate GSM call event on the connected emulator.
28+
*
29+
* @param phoneNumber The phone number of the caller.
30+
* @param gsmCallActions One of available GSM call actions {@link GsmCallActions}.
31+
*/
32+
default void gsmCall(String phoneNumber, GsmCallActions gsmCallActions) {
33+
CommandExecutionHelper.execute(this, gsmCallCommand(phoneNumber, gsmCallActions));
34+
}
35+
36+
/**
37+
* Emulate GSM signal strength change event on the connected emulator.
38+
*
39+
* @param gsmSignalStrength One of available GSM signal strength {@link GsmSignalStrength}.
40+
*/
41+
default void gsmSignalStrength(GsmSignalStrength gsmSignalStrength) {
42+
CommandExecutionHelper.execute( this, gsmSignalStrengthCommand(gsmSignalStrength));
43+
}
44+
45+
/**
46+
* Emulate GSM voice event on the connected emulator.
47+
*
48+
* @param gsmVoiceState One of available GSM voice state {@link GsmVoiceState}.
49+
*/
50+
default void gsmVoice(GsmVoiceState gsmVoiceState) {
51+
CommandExecutionHelper.execute(this, gsmVoiceCommand(gsmVoiceState));
52+
}
53+
54+
/**
55+
* Emulate network speed change event on the connected emulator.
56+
*
57+
* @param networkSpeed One of available Network Speed values {@link NetworkSpeed}.
58+
*/
59+
default void networkSpeed(NetworkSpeed networkSpeed) {
60+
CommandExecutionHelper.execute(this, networkSpeedCommand(networkSpeed));
61+
}
62+
63+
/**
64+
* Emulate power capacity change on the connected emulator.
65+
*
66+
* @param percent Percentage value in range [0, 100].
67+
*/
68+
default void powerCapacity(int percent) {
69+
CommandExecutionHelper.execute(this, powerCapacityCommand(percent));
70+
}
71+
72+
/**
73+
* Emulate power state change on the connected emulator.
74+
*
75+
* @param powerACState One of available Power AC state {@link PowerACState}.
76+
*/
77+
default void powerAC(PowerACState powerACState) {
78+
CommandExecutionHelper.execute(this, powerACCommand(powerACState));
79+
}
80+
81+
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,12 @@ public class AndroidDriverTest extends BaseAndroidTest {
5555
}
5656

5757
@Test public void networkSpeedTest() {
58-
driver.networkSpeed(NetworkSpeed.LTE);
59-
driver.powerCapacity(50);
60-
driver.powerAC(PowerACState.ON);
58+
driver.networkSpeed(NetworkSpeed.EDGE);
6159
}
6260

6361
@Test public void powerTest() {
64-
driver.powerCapacity(50);
65-
driver.powerAC(PowerACState.ON);
62+
driver.powerCapacity(100);
63+
driver.powerAC(PowerACState.OFF);
6664
}
6765

6866
@Test public void getDeviceTimeTest() {

0 commit comments

Comments
 (0)