diff --git a/app/src/androidTest/java/org/isoron/uhabits/ui/MainTest.java b/app/src/androidTest/java/org/isoron/uhabits/ui/MainTest.java
index e76e4d783..05877fcb0 100644
--- a/app/src/androidTest/java/org/isoron/uhabits/ui/MainTest.java
+++ b/app/src/androidTest/java/org/isoron/uhabits/ui/MainTest.java
@@ -64,15 +64,13 @@ public class MainTest
@Before
public void setup()
- {
- disableAnimations();
- skipTutorial();
- }
-
- public void disableAnimations()
{
Context context = InstrumentationRegistry.getInstrumentation().getContext();
- new SystemAnimations(context).disableAll();
+ SystemHelper sys = new SystemHelper(context);
+ sys.disableAllAnimations();
+ sys.unlockScreen();
+
+ skipTutorial();
}
public void skipTutorial()
diff --git a/app/src/androidTest/java/org/isoron/uhabits/ui/SystemAnimations.java b/app/src/androidTest/java/org/isoron/uhabits/ui/SystemHelper.java
similarity index 58%
rename from app/src/androidTest/java/org/isoron/uhabits/ui/SystemAnimations.java
rename to app/src/androidTest/java/org/isoron/uhabits/ui/SystemHelper.java
index 56138290e..5fa69e80e 100644
--- a/app/src/androidTest/java/org/isoron/uhabits/ui/SystemAnimations.java
+++ b/app/src/androidTest/java/org/isoron/uhabits/ui/SystemHelper.java
@@ -1,5 +1,6 @@
package org.isoron.uhabits.ui;
+import android.app.KeyguardManager;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.IBinder;
@@ -8,12 +9,7 @@ import android.util.Log;
import java.lang.reflect.Method;
-/**
- * Disable animations so that they do not interfere with Espresso tests.
- *
- * Source: https://code.google.com/p/android-test-kit/wiki/DisablingAnimations
- */
-public final class SystemAnimations extends AndroidJUnitRunner
+public final class SystemHelper extends AndroidJUnitRunner
{
private static final String ANIMATION_PERMISSION = "android.permission.SET_ANIMATION_SCALE";
private static final float DISABLED = 0.0f;
@@ -21,48 +17,73 @@ public final class SystemAnimations extends AndroidJUnitRunner
private final Context context;
- SystemAnimations(Context context) {
+ SystemHelper(Context context)
+ {
this.context = context;
}
- void disableAll() {
+ void unlockScreen()
+ {
+ try
+ {
+ KeyguardManager mKeyGuardManager = (KeyguardManager) context
+ .getSystemService(Context.KEYGUARD_SERVICE);
+ KeyguardManager.KeyguardLock mLock = mKeyGuardManager.newKeyguardLock("lock");
+ mLock.disableKeyguard();
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+
+ void disableAllAnimations()
+ {
Log.i("SystemAnimations", "Trying to disable animations");
int permStatus = context.checkCallingOrSelfPermission(ANIMATION_PERMISSION);
- if (permStatus == PackageManager.PERMISSION_GRANTED) {
+ if (permStatus == PackageManager.PERMISSION_GRANTED)
setSystemAnimationsScale(DISABLED);
- } else {
+ else
Log.e("SystemAnimations", "Permission denied");
- }
}
- void enableAll() {
+ void enableAllAnimations()
+ {
int permStatus = context.checkCallingOrSelfPermission(ANIMATION_PERMISSION);
- if (permStatus == PackageManager.PERMISSION_GRANTED) {
+ if (permStatus == PackageManager.PERMISSION_GRANTED)
+ {
setSystemAnimationsScale(DEFAULT);
}
}
- private void setSystemAnimationsScale(float animationScale) {
- try {
+ private void setSystemAnimationsScale(float animationScale)
+ {
+ try
+ {
Class> windowManagerStubClazz = Class.forName("android.view.IWindowManager$Stub");
- Method asInterface = windowManagerStubClazz.getDeclaredMethod("asInterface", IBinder.class);
+ Method asInterface =
+ windowManagerStubClazz.getDeclaredMethod("asInterface", IBinder.class);
Class> serviceManagerClazz = Class.forName("android.os.ServiceManager");
Method getService = serviceManagerClazz.getDeclaredMethod("getService", String.class);
Class> windowManagerClazz = Class.forName("android.view.IWindowManager");
- Method setAnimationScales = windowManagerClazz.getDeclaredMethod("setAnimationScales", float[].class);
+ Method setAnimationScales =
+ windowManagerClazz.getDeclaredMethod("setAnimationScales", float[].class);
Method getAnimationScales = windowManagerClazz.getDeclaredMethod("getAnimationScales");
IBinder windowManagerBinder = (IBinder) getService.invoke(null, "window");
Object windowManagerObj = asInterface.invoke(null, windowManagerBinder);
float[] currentScales = (float[]) getAnimationScales.invoke(windowManagerObj);
- for (int i = 0; i < currentScales.length; i++) {
+ for (int i = 0; i < currentScales.length; i++)
currentScales[i] = animationScale;
- }
+
setAnimationScales.invoke(windowManagerObj, new Object[]{currentScales});
Log.i("SystemAnimations", "All animations successfully disabled");
- } catch (Exception e) {
- Log.e("SystemAnimations", "Could not change animation scale to " + animationScale + " :'(");
+ }
+ catch (Exception e)
+ {
+ Log.e("SystemAnimations",
+ "Could not change animation scale to " + animationScale + " :'(");
}
}
}
\ No newline at end of file
diff --git a/app/src/debug/AndroidManifest.xml b/app/src/debug/AndroidManifest.xml
index 0829dbe45..10d453a48 100644
--- a/app/src/debug/AndroidManifest.xml
+++ b/app/src/debug/AndroidManifest.xml
@@ -22,5 +22,6 @@
xmlns:android="http://schemas.android.com/apk/res/android">
+