Skip to content

Commit 0777907

Browse files
author
Mykola Mokhnach
committed
Add handlers for lock/unlock in iOS
1 parent b04386d commit 0777907

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,28 @@ public static ImmutableMap<String, Object> prepareArguments(String[] params,
352352
LOCK, prepareArguments("seconds", duration.getSeconds()));
353353
}
354354

355+
/**
356+
* This method forms a {@link java.util.Map} of parameters for the
357+
* device unlocking.
358+
*
359+
* @return a key-value pair. The key is the command name. The value is a
360+
* {@link java.util.Map} command arguments.
361+
*/
362+
public static Map.Entry<String, Map<String, ?>> unlockDeviceCommand() {
363+
return new AbstractMap.SimpleEntry<>(UNLOCK, ImmutableMap.<String, Object>of());
364+
}
365+
366+
/**
367+
* This method forms a {@link java.util.Map} of parameters for the
368+
* device locked query.
369+
*
370+
* @return a key-value pair. The key is the command name. The value is a
371+
* {@link java.util.Map} command arguments.
372+
*/
373+
public static Map.Entry<String, Map<String, ?>> getIsDeviceLockedCommand() {
374+
return new AbstractMap.SimpleEntry<>(IS_LOCKED, ImmutableMap.<String, Object>of());
375+
}
376+
355377
public static Map.Entry<String, Map<String, ?>> getSettingsCommand() {
356378
return new AbstractMap.SimpleEntry<>(GET_SETTINGS, ImmutableMap.<String, Object>of());
357379
}

src/main/java/io/appium/java_client/ios/LocksIOSDevice.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
package io.appium.java_client.ios;
1818

19+
import static io.appium.java_client.MobileCommand.getIsDeviceLockedCommand;
1920
import static io.appium.java_client.MobileCommand.lockDeviceCommand;
21+
import static io.appium.java_client.MobileCommand.unlockDeviceCommand;
2022

2123
import io.appium.java_client.CommandExecutionHelper;
2224
import io.appium.java_client.ExecutesMethod;
@@ -27,11 +29,30 @@ public interface LocksIOSDevice extends ExecutesMethod {
2729

2830
/**
2931
* Lock the device (bring it to the lock screen) for a given number of
30-
* seconds.
32+
* seconds or forever (until the command for unlocking is called). The call
33+
* is ignored if the device already locked.
3134
*
32-
* @param duration for how long to lock the screen. Minimum time resolution is one second
35+
* @param duration for how long to lock the screen. Minimum time resolution is one second.
36+
* A negative/zero value will lock the device and return immediately.
3337
*/
3438
default void lockDevice(Duration duration) {
3539
CommandExecutionHelper.execute(this, lockDeviceCommand(duration));
3640
}
41+
42+
/**
43+
* Unlocks the device if it is locked or returns immediately if the device is already unlocked.
44+
*/
45+
default void unlockDevice() {
46+
CommandExecutionHelper.execute(this, unlockDeviceCommand());
47+
}
48+
49+
/**
50+
* Get the current state of the device.
51+
*
52+
* @return true if the device is locked or false otherwise.
53+
*/
54+
default boolean isDeviceLocked() {
55+
return CommandExecutionHelper.execute(this, getIsDeviceLockedCommand());
56+
}
57+
3758
}

0 commit comments

Comments
 (0)