Hi,
this patch adds suspend functionality to accel keyboard.

If you put Freerunner on the table so that the display
is downside it will suspend after 30 seconds.

This could also prevent battery drain when FR wakes up
by accident or bug e.g. in the middle of the night.

I have also changed SENSOR_DELAY_UI to SENSOR_DELAY_NORMAL
which is good enough for our purposes and which is best
for power saving.

Cheers

Radek
diff --git a/services/java/com/android/server/AccelKeyboardService.java b/services/java/com/android/server/AccelKeyboardService.java
index feb3e8a..5fd7123 100644
--- a/services/java/com/android/server/AccelKeyboardService.java
+++ b/services/java/com/android/server/AccelKeyboardService.java
@@ -72,6 +72,7 @@ import android.view.KeyEvent;
 import android.os.ServiceManager;
 import android.os.RemoteException;
 import android.os.SystemClock;
+import android.os.PowerManager;
 import android.view.ViewConfiguration;
 
 /**
@@ -87,6 +88,7 @@ public class AccelKeyboardService extends IAccelKeyboardService.Stub implements
     private KeyEvent keyUp;
     private long time;
     private long downTime;
+    private long sleepTime;
     private static final int TAB_LEN = 4;
 	private static float HALF_G = SensorManager.GRAVITY_EARTH / 2;
 	private SensorManager sensorManager;
@@ -138,7 +140,7 @@ public class AccelKeyboardService extends IAccelKeyboardService.Stub implements
 		if(enabled) {
 			sensorManager.registerListener(this,
 				SensorManager.SENSOR_ACCELEROMETER,
-				SensorManager.SENSOR_DELAY_UI);
+				SensorManager.SENSOR_DELAY_NORMAL);
 		} else {
 			sensorManager.unregisterListener(this);
 		}
@@ -215,6 +217,24 @@ public class AccelKeyboardService extends IAccelKeyboardService.Stub implements
 
 		time = SystemClock.uptimeMillis();
 
+		// Check for "display on the table" position
+		if (z < -HALF_G &&
+			x > -HALF_G && x < HALF_G && y > -HALF_G && y < HALF_G) {
+			if(sleepTime > 0) {
+				// Go to sleep after 30s
+				if(time - sleepTime > 30000) {
+					PowerManager pm = (PowerManager)
+						mContext.getSystemService(Context.POWER_SERVICE);
+					sleepTime = 0;
+					pm.goToSleep(time);
+				}
+			} else {
+				sleepTime = time;
+			}
+		} else {
+			sleepTime = 0;
+		}
+
 		if(keyUp != null && time > keyUp.getEventTime()) {
 			injectKey(keyUp);
 			keyUp = null;
_______________________________________________
android-freerunner mailing list
[email protected]
http://android.koolu.org/listinfo.cgi/android-freerunner-koolu.org

Reply via email to