1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.commands.monkey; 18 19 import android.app.IActivityManager; 20 import android.view.IWindowManager; 21 22 /** 23 * abstract class for monkey event 24 */ 25 public abstract class MonkeyEvent { 26 protected int eventType; 27 public static final int EVENT_TYPE_KEY = 0; 28 public static final int EVENT_TYPE_TOUCH = 1; 29 public static final int EVENT_TYPE_TRACKBALL = 2; 30 public static final int EVENT_TYPE_ROTATION = 3; // Screen rotation 31 public static final int EVENT_TYPE_ACTIVITY = 4; 32 public static final int EVENT_TYPE_FLIP = 5; // Keyboard flip 33 public static final int EVENT_TYPE_THROTTLE = 6; 34 public static final int EVENT_TYPE_PERMISSION = 7; 35 public static final int EVENT_TYPE_NOOP = 8; 36 37 public static final int INJECT_SUCCESS = 1; 38 public static final int INJECT_FAIL = 0; 39 40 // error code for remote exception during injection 41 public static final int INJECT_ERROR_REMOTE_EXCEPTION = -1; 42 // error code for security exception during injection 43 public static final int INJECT_ERROR_SECURITY_EXCEPTION = -2; 44 MonkeyEvent(int type)45 public MonkeyEvent(int type) { 46 eventType = type; 47 } 48 49 /** 50 * @return event type 51 */ getEventType()52 public int getEventType() { 53 return eventType; 54 } 55 56 /** 57 * @return true if it is safe to throttle after this event, and false otherwise. 58 */ isThrottlable()59 public boolean isThrottlable() { 60 return true; 61 } 62 63 64 /** 65 * a method for injecting event 66 * @param iwm wires to current window manager 67 * @param iam wires to current activity manager 68 * @param verbose a log switch 69 * @return INJECT_SUCCESS if it goes through, and INJECT_FAIL if it fails 70 * in the case of exceptions, return its corresponding error code 71 */ injectEvent(IWindowManager iwm, IActivityManager iam, int verbose)72 public abstract int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose); 73 } 74