Home | History | Annotate | Download | only in monkey
      1 /*
      2  * Copyright (C) 2010 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 import android.os.Build;
     22 
     23 
     24 /**
     25  * Events for running the shell command.
     26  */
     27 public class MonkeyCommandEvent extends MonkeyEvent {
     28 
     29     private String mCmd;
     30 
     31     public MonkeyCommandEvent(String cmd) {
     32         super(EVENT_TYPE_ACTIVITY);
     33         mCmd = cmd;
     34     }
     35 
     36     @Override
     37     public int injectEvent(IWindowManager iwm, IActivityManager iam, int verbose) {
     38         if (mCmd != null) {
     39             //Execute the shell command
     40             try {
     41                 java.lang.Process p = Runtime.getRuntime().exec(mCmd);
     42                 int status = p.waitFor();
     43                 System.err.println("// Shell command " + mCmd + " status was " + status);
     44             } catch (Exception e) {
     45                 System.err.println("// Exception from " + mCmd + ":");
     46                 System.err.println(e.toString());
     47             }
     48         }
     49         return MonkeyEvent.INJECT_SUCCESS;
     50     }
     51 }
     52