Fix imf tests.

- fix hard keyboard detection logic
- use FLAG_ACTIVITY_MULTIPLE_TASK to force test activities to start with IME

Bugs 2677320, 2677355

Change-Id: I1b943ee17fddcae5087faefa9fa5603dd3f18ec1
diff --git a/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java b/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
index 50e2009..bc77e04 100755
--- a/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
+++ b/tests/ImfTest/tests/src/com/android/imftest/samples/ImfBaseTestCase.java
@@ -19,6 +19,7 @@
 import android.app.Activity;
 import android.app.KeyguardManager;
 import android.content.Context;
+import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.SystemClock;
 import android.test.InstrumentationTestCase;
@@ -38,7 +39,7 @@
     public final long WAIT_FOR_IME = 5000;
 
     /*
-     * Unfortunately there is now way for us to know how tall the IME is, 
+     * Unfortunately there is now way for us to know how tall the IME is,
      * so we have to hard code a minimum and maximum value.
      */
     public final int IME_MIN_HEIGHT = 150;
@@ -48,20 +49,23 @@
     protected T mTargetActivity;
     protected boolean mExpectAutoPop;
     private Class<T> mTargetActivityClass;
-    
+
     public ImfBaseTestCase(Class<T> activityClass) {
         mTargetActivityClass = activityClass;
     }
-    
+
     @Override
     public void setUp() throws Exception {
         super.setUp();
         final String packageName = getInstrumentation().getTargetContext().getPackageName();
-        mTargetActivity = launchActivity(packageName, mTargetActivityClass, null);
+        Intent intent = new Intent(Intent.ACTION_MAIN);
+        intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
+        mTargetActivity = launchActivityWithIntent(packageName, mTargetActivityClass, intent);
         // expect ime to auto pop up if device has no hard keyboard
-        mExpectAutoPop = mTargetActivity.getResources().getConfiguration().hardKeyboardHidden == 
-            Configuration.HARDKEYBOARDHIDDEN_YES;
-        
+        int keyboardType = mTargetActivity.getResources().getConfiguration().keyboard;
+        mExpectAutoPop = (keyboardType  == Configuration.KEYBOARD_NOKEYS ||
+                keyboardType == Configuration.KEYBOARD_UNDEFINED);
+
         mImm = InputMethodManager.getInstance(mTargetActivity);
 
         KeyguardManager keyguardManager =
@@ -115,26 +119,26 @@
             assertFalse(destructiveCheckImeUp(rootView, servedView));
         }
     }
-    
+
     public boolean destructiveCheckImeUp(View rootView, View servedView) {
         int origHeight;
         int newHeight;
-        
+
         origHeight = rootView.getHeight();
-        
+
         // Tell the keyboard to go away.
         mImm.hideSoftInputFromWindow(servedView.getWindowToken(), 0);
-        
+
         // Give it five seconds to adjust
         newHeight = rootView.getHeight();
         long timeoutTime = SystemClock.uptimeMillis() + WAIT_FOR_IME;
         while (Math.abs(newHeight - origHeight) < IME_MIN_HEIGHT && SystemClock.uptimeMillis() < timeoutTime) {
             newHeight = rootView.getHeight();
         }
-        
+
         return (Math.abs(origHeight - newHeight) >= IME_MIN_HEIGHT);
     }
-    
+
     void pause(int millis) {
         try {
             Thread.sleep(millis);