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
17package com.android.commands.monkey;
18
19import android.app.IActivityManager;
20import android.view.IWindowManager;
21
22/**
23 * abstract class for monkey event
24 */
25public 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_NOOP = 7;
35
36    public static final int INJECT_SUCCESS = 1;
37    public static final int INJECT_FAIL = 0;
38
39    // error code for remote exception during injection
40    public static final int INJECT_ERROR_REMOTE_EXCEPTION = -1;
41    // error code for security exception during injection
42    public static final int INJECT_ERROR_SECURITY_EXCEPTION = -2;
43
44    public MonkeyEvent(int type) {
45        eventType = type;
46    }
47
48    /**
49     * @return event type
50     */
51    public int getEventType() {
52        return eventType;
53    }
54
55    /**
56     * @return true if it is safe to throttle after this event, and false otherwise.
57     */
58    public boolean isThrottlable() {
59        return true;
60    }
61
62
63    /**
64     * a method for injecting event
65     * @param iwm wires to current window manager
66     * @param iam wires to current activity manager
67     * @param verbose a log switch
68     * @return INJECT_SUCCESS if it goes through, and INJECT_FAIL if it fails
69     *         in the case of exceptions, return its corresponding error code
70     */
71    public abstract int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose);
72}
73