/**
  * Interface method implementation. Reads and processes commands sent to the service proxy.
  * Expects data in the command protocol defined in the class summary. Discards commands that do
  * not have a {@link TaskHandler} mapping.
  *
  * @see
  *     org.jboss.netty.channel.SimpleChannelUpstreamHandler#handleUpstream(org.jboss.netty.channel.ChannelHandlerContext,
  *     org.jboss.netty.channel.ChannelEvent)
  */
 public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent event) throws Exception {
   if (MessageEvent.class.isAssignableFrom(event.getClass())) {
     CommandInterpreter commandInterpreter = new CommandInterpreter();
     CommandInterpreter.ProxyCommand readCommand =
         commandInterpreter.readCommand((MessageEvent) event);
     LOGGER.debug("Read Command : " + readCommand);
     String pool = readCommand.getCommandParams().get("pool");
     TaskHandlerExecutor executor;
     // Try to execute command using ThreadPool, if "pool" is found in the command, else the
     // command name
     if (pool != null) {
       executor = this.repository.get(readCommand.getCommand(), pool);
     } else {
       executor = this.repository.get(readCommand.getCommand(), readCommand.getCommand());
     }
     executor.setParams(readCommand.getCommandParams());
     executor.setData(readCommand.getCommandData());
     try {
       TaskResult result = executor.execute();
       LOGGER.debug("The output is: " + result);
       // write the results to the channel output
       commandInterpreter.writeCommandExecutionResponse(ctx, event, result);
     } catch (Exception e) {
       LOGGER.error("Error in executing command/fallBack : " + readCommand, e);
       throw new RuntimeException("Error in executing command : " + readCommand, e);
     }
   }
   super.handleUpstream(ctx, event);
 }
 @Override
 public void onAccessibilityEvent(AccessibilityEvent accessibilityEvent) {
   try {
     if (!PreferenceManager.getDefaultSharedPreferences(this).getBoolean("usexposed", false)) {
       AccessibilityNodeInfo ani = accessibilityEvent.getSource();
       String command = accessibilityNodeInfoRecursion(ani);
       if (command != null) {
         if ((lastCommand + timeOut) < accessibilityEvent.getEventTime()
             && CommandInterpreter.interpret(this, command, true)) {
           lastCommand = accessibilityEvent.getEventTime();
         }
         Log.v("command", command);
       }
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 3
0
 public boolean handleKey(char c) throws CommandException {
   return interpret.handleKey(c);
 }