Home | History | Annotate | Download | only in monkey
      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_ACTIVITY = 3;
     31     public static final int EVENT_TYPE_FLIP = 4; // Keyboard flip
     32     public static final int EVENT_TYPE_THROTTLE = 5;
     33     public static final int EVENT_TYPE_NOOP = 6;
     34 
     35     public static final int INJECT_SUCCESS = 1;
     36     public static final int INJECT_FAIL = 0;
     37 
     38     // error code for remote exception during injection
     39     public static final int INJECT_ERROR_REMOTE_EXCEPTION = -1;
     40     // error code for security exception during injection
     41     public static final int INJECT_ERROR_SECURITY_EXCEPTION = -2;
     42 
     43     public MonkeyEvent(int type) {
     44         eventType = type;
     45     }
     46 
     47     /**
     48      * @return event type
     49      */
     50     public int getEventType() {
     51         return eventType;
     52     }
     53 
     54     /**
     55      * @return true if it is safe to throttle after this event, and false otherwise.
     56      */
     57     public boolean isThrottlable() {
     58         return true;
     59     }
     60 
     61 
     62     /**
     63      * a method for injecting event
     64      * @param iwm wires to current window manager
     65      * @param iam wires to current activity manager
     66      * @param verbose a log switch
     67      * @return INJECT_SUCCESS if it goes through, and INJECT_FAIL if it fails
     68      *         in the case of exceptions, return its corresponding error code
     69      */
     70     public abstract int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose);
     71 }
     72