Clean up wakeup/sleep API in sl4a.

Remove the duplicate wake up API.
Update deprecated API to check if screen is on.
Add an API to wake up device with a delay.

Change-Id: I92a08022ebf1899e3fb3b2b783dc79bebe284661
diff --git a/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java b/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
index 2bc1d83..ea3acfc 100644
--- a/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/SettingsFacade.java
@@ -29,15 +29,12 @@
 import com.android.internal.widget.LockPatternUtils;
 import com.googlecode.android_scripting.BaseApplication;
 import com.googlecode.android_scripting.FutureActivityTaskExecutor;
-import com.googlecode.android_scripting.Log;
 import com.googlecode.android_scripting.future.FutureActivityTask;
 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
 import com.googlecode.android_scripting.rpc.Rpc;
 import com.googlecode.android_scripting.rpc.RpcOptional;
 import com.googlecode.android_scripting.rpc.RpcParameter;
 
-import java.lang.reflect.Method;
-
 /**
  * Exposes phone settings functionality.
  *
@@ -197,31 +194,24 @@
         return oldValue;
     }
 
-    @Rpc(description = "Checks if the screen is on or off (requires API level 7).",
-            returns = "True if the screen is currently on.")
-    public Boolean checkScreenOn() throws Exception {
-        Class<?> powerManagerClass = mPower.getClass();
-        Boolean result = null;
-        try {
-            Method isScreenOn = powerManagerClass.getMethod("isScreenOn");
-            result = (Boolean) isScreenOn.invoke(mPower);
-        } catch (Exception e) {
-            Log.e(e);
-            throw new UnsupportedOperationException("This feature is only available after Eclair.");
-        }
-        return result;
+    @Rpc(description = "Returns true if the device is in an interactive state.")
+    public Boolean isDeviceInteractive() throws Exception {
+        return mPower.isInteractive();
     }
 
-    @Rpc(description = "Wakeup screen(requires API level 19).")
-    public void wakeupScreen() throws Exception {
-        Class<?> powerManagerClass = mPower.getClass();
-        try {
-            Method wakeUp = powerManagerClass.getMethod("wakeUp", long.class);
-            wakeUp.invoke(mPower, SystemClock.uptimeMillis());
-        } catch (Exception e) {
-            Log.e(e);
-            throw new UnsupportedOperationException("This feature is only available after Kitkat.");
-        }
+    @Rpc(description = "Issues a request to put the device to sleep after a delay.")
+    public void goToSleep(Integer delay) {
+        mPower.goToSleep(SystemClock.uptimeMillis() + delay);
+    }
+
+    @Rpc(description = "Issues a request to put the device to sleep right away.")
+    public void goToSleepNow() {
+        mPower.goToSleep(SystemClock.uptimeMillis());
+    }
+
+    @Rpc(description = "Issues a request to wake the device up right away.")
+    public void wakeUpNow() {
+        mPower.wakeUp(SystemClock.uptimeMillis());
     }
 
     @Rpc(description = "Get Up time of device.",
diff --git a/Common/src/com/googlecode/android_scripting/facade/WakeLockFacade.java b/Common/src/com/googlecode/android_scripting/facade/WakeLockFacade.java
index 9c095a0..85eac84 100644
--- a/Common/src/com/googlecode/android_scripting/facade/WakeLockFacade.java
+++ b/Common/src/com/googlecode/android_scripting/facade/WakeLockFacade.java
@@ -18,7 +18,6 @@
 
 import android.content.Context;
 import android.os.PowerManager;
-import android.os.SystemClock;
 import android.os.PowerManager.WakeLock;
 
 import com.googlecode.android_scripting.jsonrpc.RpcReceiver;
@@ -88,16 +87,6 @@
         mManager = new WakeLockManager(mmPowerManager);
     }
 
-    @Rpc(description = "Issue a request to put the device to sleep right away.")
-    public void goToSleepNow() {
-        mmPowerManager.goToSleep(SystemClock.uptimeMillis());
-    }
-
-    @Rpc(description = "Issue a request to wake the device up right away.")
-    public void wakeUpNow() {
-        mmPowerManager.wakeUp(SystemClock.uptimeMillis());
-    }
-
     @Rpc(description = "Acquires a full wake lock (CPU on, screen bright, keyboard bright).")
     public void wakeLockAcquireFull() {
         mManager.acquire(WakeLockType.FULL);