Skip to content

Instantly share code, notes, and snippets.

@oguzbabaoglu
oguzbabaoglu / CustomJUnitRunner.java
Created Feb 10, 2016
Custom AndroidJUnitRunner with wake lock
View CustomJUnitRunner.java
import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
import static android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;
public class CustomJUnitRunner extends AndroidJUnitRunner {
@Override public void onCreate(Bundle arguments) {
super.onCreate(arguments);
ActivityLifecycleMonitorRegistry.getInstance().addLifecycleCallback(new ActivityLifecycleCallback() {
@oguzbabaoglu
oguzbabaoglu / u2020wake.java
Created Feb 10, 2016
Wake lock solution in u2020
View u2020wake.java
String name = U2020TestRunner.class.getSimpleName();
// Unlock the device so that the tests can input keystrokes.
KeyguardManager keyguard = (KeyguardManager) app.getSystemService(KEYGUARD_SERVICE);
keyguard.newKeyguardLock(name).disableKeyguard();
// Wake up the screen.
PowerManager power = (PowerManager) app.getSystemService(POWER_SERVICE);
wakeLock = power.newWakeLock(FULL_WAKE_LOCK | ACQUIRE_CAUSES_WAKEUP | ON_AFTER_RELEASE, name);
wakeLock.acquire();