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
15 changes: 2 additions & 13 deletions src/main/java/io/appium/java_client/android/AndroidDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@
import java.net.URL;

import static io.appium.java_client.android.AndroidMobileCommandHelper.endTestCoverageCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.openNotificationsCommand;
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;

/**
* Android driver implementation.
Expand Down Expand Up @@ -86,6 +84,8 @@ public class AndroidDriver extends AppiumDriver implements
HasBattery<AndroidBatteryInfo>,
ExecuteCDPCommand,
CanReplaceElementValue,
SupportsGpsStateManagement,
HasNotifications,
SupportsExtendedGeolocationCommands {
private static final String ANDROID_PLATFORM = Platform.ANDROID.name();

Expand Down Expand Up @@ -262,17 +262,6 @@ public void endTestCoverage(String intent, String path) {
CommandExecutionHelper.execute(this, endTestCoverageCommand(intent, path));
}

/**
* Open the notification shade, on Android devices.
*/
public void openNotifications() {
CommandExecutionHelper.execute(this, openNotificationsCommand());
}

public void toggleLocationServices() {
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
}

@Override
public AndroidBatteryInfo getBatteryInfo() {
return new AndroidBatteryInfo(CommandExecutionHelper.executeScript(this, "mobile: batteryInfo"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default void replaceElementValue(RemoteWebElement element, String value) {
// TODO: Remove the fallback
this.execute(MobileCommand.REPLACE_VALUE, ImmutableMap.of(
"id", element.getId(),
"text", value,
"value", value
));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.appium.java_client.android;

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.openNotificationsCommand;

public interface HasNotifications extends ExecutesMethod {

/**
* Opens notification drawer on the device under test.
*/
default void openNotifications() {
try {
CommandExecutionHelper.executeScript(this, "mobile: openNotifications");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(this, openNotificationsCommand());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.appium.java_client.android;

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

import static com.google.common.base.Preconditions.checkNotNull;
import static io.appium.java_client.android.AndroidMobileCommandHelper.toggleLocationServicesCommand;

public interface SupportsGpsStateManagement extends ExecutesMethod {

/**
* Toggles GPS service state.
* This method only works reliably since API 31 (Android 12).
*/
default void toggleLocationServices() {
try {
CommandExecutionHelper.executeScript(this, "mobile: toggleGps");
} catch (UnsupportedCommandException e) {
// TODO: Remove the fallback
CommandExecutionHelper.execute(this, toggleLocationServicesCommand());
}
}

/**
* Check GPS service state.
*
* @return true if GPS service is enabled.
*/
default boolean isLocationServicesEnabled() {
return checkNotNull(
CommandExecutionHelper.executeScript(this, "mobile: isGpsEnabled")
);
}
}