Merge change 20629 into donut
* changes: Add "wake" command to wake device up. Run wake command at first connection.
This commit is contained in:
@@ -73,6 +73,10 @@ flip [open|close]
|
|||||||
|
|
||||||
This simulates the opening or closing the keyboard (like on dream).
|
This simulates the opening or closing the keyboard (like on dream).
|
||||||
|
|
||||||
|
wake
|
||||||
|
|
||||||
|
This command will wake the device up from sleep and allow user input.
|
||||||
|
|
||||||
OTHER NOTES
|
OTHER NOTES
|
||||||
|
|
||||||
There are some convenience features added to allow running without
|
There are some convenience features added to allow running without
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ public abstract class MonkeyEvent {
|
|||||||
public static final int EVENT_TYPE_ACTIVITY = 3;
|
public static final int EVENT_TYPE_ACTIVITY = 3;
|
||||||
public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
|
public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
|
||||||
public static final int EVENT_TYPE_THROTTLE = 5;
|
public static final int EVENT_TYPE_THROTTLE = 5;
|
||||||
|
public static final int EVENT_TYPE_NOOP = 6;
|
||||||
|
|
||||||
public static final int INJECT_SUCCESS = 1;
|
public static final int INJECT_SUCCESS = 1;
|
||||||
public static final int INJECT_FAIL = 0;
|
public static final int INJECT_FAIL = 0;
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2009 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import android.app.IActivityManager;
|
||||||
|
import android.view.IWindowManager;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* monkey noop event (don't do anything).
|
||||||
|
*/
|
||||||
|
public class MonkeyNoopEvent extends MonkeyEvent {
|
||||||
|
|
||||||
|
public MonkeyNoopEvent() {
|
||||||
|
super(MonkeyEvent.EVENT_TYPE_NOOP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
|
||||||
|
// No real work to do
|
||||||
|
if (verbose > 1) {
|
||||||
|
System.out.println("NOOP");
|
||||||
|
}
|
||||||
|
return MonkeyEvent.INJECT_SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package com.android.commands.monkey;
|
package com.android.commands.monkey;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.IPowerManager;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
import android.os.ServiceManager;
|
||||||
|
import android.os.SystemClock;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
@@ -203,6 +208,36 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Command to wake the device up
|
||||||
|
*/
|
||||||
|
private static class WakeCommand implements MonkeyCommand {
|
||||||
|
// wake
|
||||||
|
public MonkeyEvent translateCommand(List<String> command) {
|
||||||
|
if (wake()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new MonkeyNoopEvent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Force the device to wake up.
|
||||||
|
*
|
||||||
|
* @return true if woken up OK.
|
||||||
|
*/
|
||||||
|
private static final boolean wake() {
|
||||||
|
IPowerManager pm =
|
||||||
|
IPowerManager.Stub.asInterface(ServiceManager.getService(Context.POWER_SERVICE));
|
||||||
|
try {
|
||||||
|
pm.userActivityWithForce(SystemClock.uptimeMillis(), true, true);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.e(TAG, "Got remote exception", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// This maps from command names to command implementations.
|
// This maps from command names to command implementations.
|
||||||
private static final Map<String, MonkeyCommand> COMMAND_MAP = new HashMap<String, MonkeyCommand>();
|
private static final Map<String, MonkeyCommand> COMMAND_MAP = new HashMap<String, MonkeyCommand>();
|
||||||
|
|
||||||
@@ -213,6 +248,7 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
COMMAND_MAP.put("trackball", new TrackballCommand());
|
COMMAND_MAP.put("trackball", new TrackballCommand());
|
||||||
COMMAND_MAP.put("key", new KeyCommand());
|
COMMAND_MAP.put("key", new KeyCommand());
|
||||||
COMMAND_MAP.put("sleep", new SleepCommand());
|
COMMAND_MAP.put("sleep", new SleepCommand());
|
||||||
|
COMMAND_MAP.put("wake", new WakeCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
// QUIT command
|
// QUIT command
|
||||||
@@ -246,6 +282,10 @@ public class MonkeySourceNetwork implements MonkeyEventSource {
|
|||||||
0, // default backlog
|
0, // default backlog
|
||||||
InetAddress.getLocalHost());
|
InetAddress.getLocalHost());
|
||||||
Socket s = server.accept();
|
Socket s = server.accept();
|
||||||
|
// At this point, we have a client connected. Wake the device
|
||||||
|
// up in preparation for doing some commands.
|
||||||
|
wake();
|
||||||
|
|
||||||
input = new BufferedReader(new InputStreamReader(s.getInputStream()));
|
input = new BufferedReader(new InputStreamReader(s.getInputStream()));
|
||||||
// auto-flush
|
// auto-flush
|
||||||
output = new PrintWriter(s.getOutputStream(), true);
|
output = new PrintWriter(s.getOutputStream(), true);
|
||||||
|
|||||||
Reference in New Issue
Block a user