Home | History | Annotate | Download | only in monkey
      1 /*
      2  * Copyright (C) 2008 Google Inc.
      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 java.io.FileOutputStream;
     20 import java.io.IOException;
     21 
     22 import android.app.IActivityManager;
     23 import android.view.IWindowManager;
     24 /**
     25  * monkey keyboard flip event
     26  */
     27 public class MonkeyFlipEvent extends MonkeyEvent {
     28 
     29     // Raw keyboard flip event data
     30     // Works on emulator and dream
     31 
     32     private static final byte[] FLIP_0 = {
     33         0x7f, 0x06,
     34         0x00, 0x00,
     35         (byte) 0xe0, 0x39,
     36         0x01, 0x00,
     37         0x05, 0x00,
     38         0x00, 0x00,
     39         0x01, 0x00,
     40         0x00, 0x00 };
     41 
     42     private static final byte[] FLIP_1 = {
     43         (byte) 0x85, 0x06,
     44         0x00, 0x00,
     45         (byte) 0x9f, (byte) 0xa5,
     46         0x0c, 0x00,
     47         0x05, 0x00,
     48         0x00, 0x00,
     49         0x00, 0x00,
     50         0x00, 0x00 };
     51 
     52     private final boolean mKeyboardOpen;
     53 
     54     public MonkeyFlipEvent(boolean keyboardOpen) {
     55         super(EVENT_TYPE_FLIP);
     56         mKeyboardOpen = keyboardOpen;
     57     }
     58 
     59     @Override
     60     public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
     61         if (verbose > 0) {
     62             Logger.out.println(":Sending Flip keyboardOpen=" + mKeyboardOpen);
     63         }
     64 
     65         // inject flip event
     66         try {
     67             FileOutputStream f = new FileOutputStream("/dev/input/event0");
     68             f.write(mKeyboardOpen ? FLIP_0 : FLIP_1);
     69             f.close();
     70             return MonkeyEvent.INJECT_SUCCESS;
     71         } catch (IOException e) {
     72             Logger.out.println("Got IOException performing flip" + e);
     73             return MonkeyEvent.INJECT_FAIL;
     74         }
     75     }
     76 }
     77