Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/java/io/appium/java_client/MobileCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class MobileCommand {
protected static final String TOUCH_ID_ENROLLMENT;
//Android
@Deprecated
protected static final String CURRENT_ACTIVITY;
public static final String CURRENT_ACTIVITY;
@Deprecated
protected static final String END_TEST_COVERAGE;
@Deprecated
Expand Down Expand Up @@ -149,21 +149,21 @@ public class MobileCommand {
@Deprecated
protected static final String SET_SETTINGS;
@Deprecated
protected static final String GET_CURRENT_PACKAGE;
public static final String GET_CURRENT_PACKAGE;
@Deprecated
protected static final String SEND_SMS;
public static final String SEND_SMS;
@Deprecated
protected static final String GSM_CALL;
public static final String GSM_CALL;
@Deprecated
protected static final String GSM_SIGNAL;
public static final String GSM_SIGNAL;
@Deprecated
protected static final String GSM_VOICE;
public static final String GSM_VOICE;
@Deprecated
protected static final String NETWORK_SPEED;
public static final String NETWORK_SPEED;
@Deprecated
protected static final String POWER_CAPACITY;
public static final String POWER_CAPACITY;
@Deprecated
protected static final String POWER_AC_STATE;
public static final String POWER_AC_STATE;
@Deprecated
protected static final String TOGGLE_WIFI;
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public AndroidDriver(URL remoteSessionAddress, String automationName) {
*
* @param intent intent to broadcast.
* @param path path to .ec file.
* @deprecated This API will be removed
*/
@Deprecated
public void endTestCoverage(String intent, String path) {
CommandExecutionHelper.execute(this, endTestCoverageCommand(intent, path));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> currentActivityCommand() {
return new AbstractMap.SimpleEntry<>(CURRENT_ACTIVITY, ImmutableMap.of());
}
Expand All @@ -46,6 +47,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> currentPackageCommand() {
return new AbstractMap.SimpleEntry<>(GET_CURRENT_PACKAGE, ImmutableMap.of());
}
Expand All @@ -57,6 +59,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* @param path path to .ec file.
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> endTestCoverageCommand(String intent,
String path) {
String[] parameters = new String[] {"intent", "path"};
Expand Down Expand Up @@ -117,6 +120,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> getDisplayDensityCommand() {
return new AbstractMap.SimpleEntry<>(GET_DISPLAY_DENSITY, ImmutableMap.of());
}
Expand All @@ -126,6 +130,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> getNetworkConnectionCommand() {
return new AbstractMap.SimpleEntry<>(GET_NETWORK_CONNECTION, ImmutableMap.of());
}
Expand All @@ -136,6 +141,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> getSystemBarsCommand() {
return new AbstractMap.SimpleEntry<>(GET_SYSTEM_BARS, ImmutableMap.of());
}
Expand All @@ -145,6 +151,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> isLockedCommand() {
return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.of());
}
Expand All @@ -155,6 +162,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10)
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> fingerPrintCommand(int fingerPrintId) {
return new AbstractMap.SimpleEntry<>(FINGER_PRINT,
prepareArguments("fingerprintId", fingerPrintId));
Expand All @@ -165,6 +173,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> openNotificationsCommand() {
return new AbstractMap.SimpleEntry<>(OPEN_NOTIFICATIONS, ImmutableMap.of());
}
Expand All @@ -175,6 +184,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* @param bitMask The bitmask of the desired connection
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> setConnectionCommand(long bitMask) {
String[] parameters = new String[] {"name", "parameters"};
Object[] values = new Object[] {"network_connection", ImmutableMap.of("type", bitMask)};
Expand All @@ -198,6 +208,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
* @throws IllegalArgumentException when any required argument is empty
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> startActivityCommand(String appPackage,
String appActivity, String appWaitPackage, String appWaitActivity,
String intentAction, String intentCategory, String intentFlags,
Expand Down Expand Up @@ -234,6 +245,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> toggleLocationServicesCommand() {
return new AbstractMap.SimpleEntry<>(TOGGLE_LOCATION_SERVICES, ImmutableMap.of());
}
Expand All @@ -243,6 +255,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> unlockCommand() {
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.of());
}
Expand All @@ -256,6 +269,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
* @param value a new value
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> replaceElementValueCommand(
RemoteWebElement remoteWebElement, String value) {
String[] parameters = new String[] {"id", "value"};
Expand All @@ -275,6 +289,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> sendSMSCommand(
String phoneNumber, String message) {
ImmutableMap<String, ?> parameters = ImmutableMap
Expand All @@ -294,6 +309,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> gsmCallCommand(
String phoneNumber, GsmCallActions gsmCallActions) {
String[] parameters = new String[] {"phoneNumber", "action"};
Expand All @@ -309,6 +325,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> gsmSignalStrengthCommand(
GsmSignalStrength gsmSignalStrength) {
return new AbstractMap.SimpleEntry<>(GSM_SIGNAL,
Expand All @@ -327,6 +344,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> gsmVoiceCommand(
GsmVoiceState gsmVoiceState) {
return new AbstractMap.SimpleEntry<>(GSM_VOICE,
Expand All @@ -341,6 +359,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> networkSpeedCommand(
NetworkSpeed networkSpeed) {
return new AbstractMap.SimpleEntry<>(NETWORK_SPEED,
Expand All @@ -355,6 +374,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> powerCapacityCommand(
int percent) {
return new AbstractMap.SimpleEntry<>(POWER_CAPACITY,
Expand All @@ -369,6 +389,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> powerACCommand(
PowerACState powerACState) {
return new AbstractMap.SimpleEntry<>(POWER_AC_STATE,
Expand All @@ -380,6 +401,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> toggleWifiCommand() {
return new AbstractMap.SimpleEntry<>(TOGGLE_WIFI, ImmutableMap.of());
}
Expand All @@ -389,6 +411,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> toggleAirplaneCommand() {
return new AbstractMap.SimpleEntry<>(TOGGLE_AIRPLANE_MODE, ImmutableMap.of());
}
Expand All @@ -398,6 +421,7 @@ public class AndroidMobileCommandHelper extends MobileCommand {
*
* @return a key-value pair. The key is the command name. The value is a {@link Map} command arguments.
*/
@Deprecated
public static Map.Entry<String, Map<String, ?>> toggleDataCommand() {
return new AbstractMap.SimpleEntry<>(TOGGLE_DATA, ImmutableMap.of());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.appium.java_client.android;

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import org.openqa.selenium.UnsupportedCommandException;

import static io.appium.java_client.android.AndroidMobileCommandHelper.fingerPrintCommand;

Expand All @@ -13,6 +15,13 @@ public interface AuthenticatesByFinger extends ExecutesMethod {
* @param fingerPrintId finger prints stored in Android Keystore system (from 1 to 10)
*/
default void fingerPrint(int fingerPrintId) {
CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId));
try {
CommandExecutionHelper.executeScript(this, "mobile: fingerprint", ImmutableMap.of(
"fingerprintId", fingerPrintId
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(this, fingerPrintCommand(fingerPrintId));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,35 @@
package io.appium.java_client.android;

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import io.appium.java_client.MobileCommand;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.remote.RemoteWebElement;

public interface CanReplaceElementValue extends ExecutesMethod {
/**
* Replaces element value with the given one.
* Sends a text to the given element by replacing its previous content.
*
* @param element The destination element.
* @param value The value to set.
* @param value The text to enter. It could also contain Unicode characters.
* If the text ends with `\\n` (the backslash must be escaped, so the
* char is NOT translated into `0x0A`) then the Enter key press is going to
* be emulated after it is entered (the `\\n` substring itself will be cut
* off from the typed text).
*/
default void replaceElementValue(RemoteWebElement element, String value) {
this.execute(MobileCommand.REPLACE_VALUE, ImmutableMap.of(
"id", element.getId(),
"value", value
));
try {
CommandExecutionHelper.executeScript(this, "mobile: replaceValue", ImmutableMap.of(
"elementId", element.getId(),
"text", value
));
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
this.execute(MobileCommand.REPLACE_VALUE, ImmutableMap.of(
"id", element.getId(),
"value", value
));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import org.openqa.selenium.UnsupportedCommandException;

import java.util.Map;

Expand All @@ -16,7 +17,12 @@ public interface HasAndroidDeviceDetails extends ExecutesMethod {
@return The density value in dpi
*/
default Long getDisplayDensity() {
return CommandExecutionHelper.execute(this, getDisplayDensityCommand());
try {
return CommandExecutionHelper.executeScript(this, "mobile: getDisplayDensity");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(this, getDisplayDensityCommand());
}
}

/**
Expand All @@ -25,7 +31,12 @@ default Long getDisplayDensity() {
@return The map where keys are bar types and values are mappings of bar properties.
*/
default Map<String, Map<String, Object>> getSystemBars() {
return CommandExecutionHelper.execute(this, getSystemBarsCommand());
try {
return CommandExecutionHelper.executeScript(this, "mobile: getSystemBars");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(this, getSystemBarsCommand());
}
}

}
30 changes: 26 additions & 4 deletions src/main/java/io/appium/java_client/android/StartsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@

package io.appium.java_client.android;

import com.google.common.collect.ImmutableMap;
import io.appium.java_client.CommandExecutionHelper;
import io.appium.java_client.ExecutesMethod;
import org.openqa.selenium.UnsupportedCommandException;

import static io.appium.java_client.android.AndroidMobileCommandHelper.currentActivityCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.currentPackageCommand;
import javax.annotation.Nullable;

import java.util.AbstractMap;

import static io.appium.java_client.MobileCommand.CURRENT_ACTIVITY;
import static io.appium.java_client.MobileCommand.GET_CURRENT_PACKAGE;
import static io.appium.java_client.android.AndroidMobileCommandHelper.startActivityCommand;

public interface StartsActivity extends ExecutesMethod {
Expand Down Expand Up @@ -57,16 +63,32 @@ default void startActivity(Activity activity) {
*
* @return a current activity being run on the mobile device.
*/
@Nullable
default String currentActivity() {
return CommandExecutionHelper.execute(this, currentActivityCommand());
try {
return CommandExecutionHelper.executeScript(this, "mobile: getCurrentActivity");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(
this, new AbstractMap.SimpleEntry<>(CURRENT_ACTIVITY, ImmutableMap.of())
);
}
}

/**
* Get the current package being run on the mobile device.
*
* @return a current package being run on the mobile device.
*/
@Nullable
default String getCurrentPackage() {
return CommandExecutionHelper.execute(this, currentPackageCommand());
try {
return CommandExecutionHelper.executeScript(this, "mobile: getCurrentPackage");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
return CommandExecutionHelper.execute(
this, new AbstractMap.SimpleEntry<>(GET_CURRENT_PACKAGE, ImmutableMap.of())
);
}
}
}
Loading