From c350f1604f348dceec28ba0d7e4cfc293333f797 Mon Sep 17 00:00:00 2001
From: Svetoslav Ganov <svetoslavganov@google.com>
Date: Thu, 10 Nov 2011 17:54:24 -0800
Subject: Instrumentation sendStringSync(String) may try to inject obsolete
 events.

KeyEvents returned by KeyCharacterMap.getEvents() have the same time stamp
and the system rejects too old events. Hence, it is possible for an event
to become stale before it is injected if it takes too long to inject the
preceding ones. Now the time of the event is set just before injecting it.

Change-Id: I72b60d261f8bda857b331d0f1b1bd97f9f15def3
---
 core/java/android/app/Instrumentation.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index d7f5c55..b607daf 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -24,14 +24,14 @@ import android.content.IntentFilter;
 import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
 import android.os.Bundle;
-import android.os.PerformanceCollector;
-import android.os.RemoteException;
 import android.os.Debug;
 import android.os.IBinder;
 import android.os.MessageQueue;
+import android.os.PerformanceCollector;
 import android.os.Process;
-import android.os.SystemClock;
+import android.os.RemoteException;
 import android.os.ServiceManager;
+import android.os.SystemClock;
 import android.util.AndroidRuntimeException;
 import android.util.Log;
 import android.view.IWindowManager;
@@ -40,7 +40,6 @@ import android.view.KeyEvent;
 import android.view.MotionEvent;
 import android.view.ViewConfiguration;
 import android.view.Window;
-import android.view.inputmethod.InputMethodManager;
 
 import java.io.File;
 import java.util.ArrayList;
@@ -834,16 +833,16 @@ public class Instrumentation {
             return;
         }
         KeyCharacterMap keyCharacterMap = KeyCharacterMap.load(KeyCharacterMap.VIRTUAL_KEYBOARD);
-        
+
         KeyEvent[] events = keyCharacterMap.getEvents(text.toCharArray());
-        
+
         if (events != null) {
             for (int i = 0; i < events.length; i++) {
-                sendKeySync(events[i]);
+                sendKeySync(KeyEvent.changeTimeRepeat(events[i], SystemClock.uptimeMillis(), 0));
             }
-        }        
+        }
     }
-    
+
     /**
      * Send a key event to the currently focused window/view and wait for it to
      * be processed.  Finished at some point after the recipient has returned
-- 
cgit v1.1