DO NOT MERGE. Revert "Add Gamepad HID tests."

This reverts commit 98e5f0ba365020d8f4fef779e4f2829802149cea.

Change-Id: I579f28158fa68639eacadaa5dd744b4ad1eefe86
diff --git a/tests/tests/hardware/AndroidManifest.xml b/tests/tests/hardware/AndroidManifest.xml
index 1d1e3a8..7b15b61 100644
--- a/tests/tests/hardware/AndroidManifest.xml
+++ b/tests/tests/hardware/AndroidManifest.xml
@@ -71,8 +71,6 @@
             android:process=":camera2ActivityProcess">
         </activity>
 
-        <activity android:name="android.hardware.input.cts.InputCtsActivity"
-            android:label="InputCtsActivity" />
     </application>
 
     <instrumentation android:name="android.support.test.runner.AndroidJUnitRunner"
diff --git a/tests/tests/hardware/res/raw/gamepad_press_a.json b/tests/tests/hardware/res/raw/gamepad_press_a.json
deleted file mode 100644
index ff3ca4f..0000000
--- a/tests/tests/hardware/res/raw/gamepad_press_a.json
+++ /dev/null
@@ -1,39 +0,0 @@
-{
-    "id": 1,
-    "command": "register",
-    "name": "Odie (Test)",
-    "vid": 0x18d1,
-    "pid": 0x2c40,
-    "descriptor": [0x05, 0x01, 0x09, 0x05, 0xa1, 0x01, 0x85, 0x01, 0x05, 0x09, 0x0a, 0x01, 0x00,
-        0x0a, 0x02, 0x00, 0x0a, 0x04, 0x00, 0x0a, 0x05, 0x00, 0x0a, 0x07, 0x00, 0x0a, 0x08, 0x00,
-        0x0a, 0x0e, 0x00, 0x0a, 0x0f, 0x00, 0x0a, 0x0d, 0x00, 0x05, 0x0c, 0x0a, 0x24, 0x02, 0x0a,
-        0x23, 0x02, 0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x0b, 0x81, 0x02, 0x75, 0x01, 0x95,
-        0x01, 0x81, 0x03, 0x05, 0x01, 0x75, 0x04, 0x95, 0x01, 0x25, 0x07, 0x46, 0x3b, 0x01, 0x66,
-        0x14, 0x00, 0x09, 0x39, 0x81, 0x42, 0x66, 0x00, 0x00, 0x09, 0x01, 0xa1, 0x00, 0x09, 0x30,
-        0x09, 0x31, 0x09, 0x32, 0x09, 0x35, 0x05, 0x02, 0x09, 0xc5, 0x09, 0xc4, 0x15, 0x00, 0x26,
-        0xff, 0x00, 0x35, 0x00, 0x46, 0xff, 0x00, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0x85,
-        0x02, 0x05, 0x08, 0x0a, 0x01, 0x00, 0x0a, 0x02, 0x00, 0x0a, 0x03, 0x00, 0x0a, 0x04, 0x00,
-        0x15, 0x00, 0x25, 0x01, 0x75, 0x01, 0x95, 0x04, 0x91, 0x02, 0x75, 0x04, 0x95, 0x01, 0x91,
-        0x03, 0xc0, 0x05, 0x0c, 0x09, 0x01, 0xa1, 0x01, 0x85, 0x03, 0x05, 0x01, 0x09, 0x06, 0xa1,
-        0x02, 0x05, 0x06, 0x09, 0x20, 0x15, 0x00, 0x26, 0xff, 0x00, 0x75, 0x08, 0x95, 0x01, 0x81,
-        0x02, 0x06, 0xbc, 0xff, 0x0a, 0xad, 0xbd, 0x75, 0x08, 0x95, 0x06, 0x81, 0x02, 0xc0, 0xc0],
-    "report": [0x01, 0x00, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
-
-{
-    "id": 1,
-    "command": "report",
-    "report": [0x01, 0x01, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
-
-{
-    "id": 1,
-    "command": "delay",
-    "duration": 10
-}
-
-{
-    "id": 1,
-    "command": "report",
-    "report": [0x01, 0x00, 0x80, 0x90, 0x80, 0x7f, 0x73, 0x00, 0x00]
-}
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java b/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java
deleted file mode 100644
index accdcaf..0000000
--- a/tests/tests/hardware/src/android/hardware/input/cts/InputCallback.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.input.cts;
-
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-
-public interface InputCallback {
-    public void onKeyEvent(KeyEvent ev);
-    public void onMotionEvent(MotionEvent ev);
-}
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java b/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java
deleted file mode 100644
index b16cadb..0000000
--- a/tests/tests/hardware/src/android/hardware/input/cts/InputCtsActivity.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.input.cts;
-
-import android.app.Activity;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class InputCtsActivity extends Activity {
-    private InputCallback mInputCallback;
-
-    @Override
-    public boolean dispatchGenericMotionEvent(MotionEvent ev) {
-        if (mInputCallback != null) {
-            mInputCallback.onMotionEvent(ev);
-        }
-        return true;
-    }
-
-    @Override
-    public boolean dispatchTouchEvent(MotionEvent ev) {
-        if (mInputCallback != null) {
-            mInputCallback.onMotionEvent(ev);
-        }
-        return true;
-    }
-
-    @Override
-    public boolean dispatchTrackballEvent(MotionEvent ev) {
-        if (mInputCallback != null) {
-            mInputCallback.onMotionEvent(ev);
-        }
-        return true;
-    }
-
-    @Override
-    public boolean dispatchKeyEvent(KeyEvent ev) {
-        if (mInputCallback != null) {
-            mInputCallback.onKeyEvent(ev);
-        }
-        return true;
-    }
-
-    public void setInputCallback(InputCallback callback) {
-        mInputCallback = callback;
-    }
-}
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java b/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java
deleted file mode 100644
index 92fba12..0000000
--- a/tests/tests/hardware/src/android/hardware/input/cts/tests/GamepadTestCase.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.input.cts.tests;
-
-import android.util.Log;
-import android.view.KeyEvent;
-
-import java.io.Writer;
-import java.util.List;
-
-import com.android.cts.hardware.R;
-
-public class GamepadTestCase extends InputTestCase {
-    private static final String TAG = "GamepadTests";
-
-    public void testButtonA() throws Exception {
-        sendHidCommands(R.raw.gamepad_press_a);
-        assertReceivedKeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_BUTTON_A);
-        assertReceivedKeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_BUTTON_A);
-        assertNoMoreEvents();
-    }
-}
diff --git a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java b/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
deleted file mode 100644
index fba5f51..0000000
--- a/tests/tests/hardware/src/android/hardware/input/cts/tests/InputTestCase.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * Copyright 2015 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.hardware.input.cts.tests;
-
-import android.app.UiAutomation;
-import android.hardware.input.cts.InputCtsActivity;
-import android.hardware.input.cts.InputCallback;
-import android.system.ErrnoException;
-import android.system.Os;
-import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.InputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import java.util.List;
-import java.util.UUID;
-
-public class InputTestCase extends ActivityInstrumentationTestCase2<InputCtsActivity> {
-    private static final String TAG = "InputTestCase";
-    private static final String HID_EXECUTABLE = "hid";
-    private static final int SHELL_UID = 2000;
-    private static final String[] KEY_ACTIONS = {"DOWN", "UP", "MULTIPLE"};
-
-    private File mFifo;
-    private Writer mWriter;
-
-    private BlockingQueue<KeyEvent> mKeys;
-    private BlockingQueue<MotionEvent> mMotions;
-    private InputListener mInputListener;
-
-    public InputTestCase() {
-        super(InputCtsActivity.class);
-        mKeys = new LinkedBlockingQueue<KeyEvent>();
-        mMotions = new LinkedBlockingQueue<MotionEvent>();
-        mInputListener = new InputListener();
-    }
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        mFifo = setupFifo();
-        clearKeys();
-        clearMotions();
-        getActivity().setInputCallback(mInputListener);
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        if (mFifo != null) {
-            mFifo.delete();
-            mFifo = null;
-        }
-        closeQuietly(mWriter);
-        mWriter = null;
-        super.tearDown();
-    }
-
-    /**
-     * Sends the HID commands designated by the given resource id.
-     * The commands must be in the format expected by the `hid` shell command.
-     *
-     * @param id The resource id from which to load the HID commands. This must be a "raw"
-     * resource.
-     */
-    public void sendHidCommands(int id) {
-        try {
-            Writer w = getWriter();
-            w.write(getEvents(id));
-            w.flush();
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Asserts that the application received a {@link android.view.KeyEvent} with the given action
-     * and keycode.
-     *
-     * If other KeyEvents are received by the application prior to the expected KeyEvent, or no
-     * KeyEvents are received within a reasonable amount of time, then this will throw an
-     * AssertionFailedError.
-     *
-     * @param action The action to expect on the next KeyEvent
-     * (e.g. {@link android.view.KeyEvent#ACTION_DOWN}).
-     * @param keyCode The expected key code of the next KeyEvent.
-     */
-    public void assertReceivedKeyEvent(int action, int keyCode) {
-        KeyEvent k = waitForKey();
-        if (k == null) {
-            fail("Timed out waiting for " + KeyEvent.keyCodeToString(keyCode)
-                    + " with action " + KEY_ACTIONS[action]);
-            return;
-        }
-        assertEquals(action, k.getAction());
-        assertEquals(keyCode, k.getKeyCode());
-    }
-
-    /**
-     * Asserts that no more events have been received by the application.
-     *
-     * If any more events have been received by the application, this throws an
-     * AssertionFailedError.
-     */
-    public void assertNoMoreEvents() {
-        KeyEvent key;
-        MotionEvent motion;
-        if ((key = mKeys.poll()) != null) {
-            fail("Extraneous key events generated: " + key);
-        }
-        if ((motion = mMotions.poll()) != null) {
-            fail("Extraneous motion events generated: " + motion);
-        }
-    }
-
-    private KeyEvent waitForKey() {
-        try {
-            return mKeys.poll(1, TimeUnit.SECONDS);
-        } catch (InterruptedException e) {
-            return null;
-        }
-    }
-
-    private void clearKeys() {
-        mKeys.clear();
-    }
-
-    private void clearMotions() {
-        mMotions.clear();
-    }
-
-    private File setupFifo() throws ErrnoException {
-        File dir = getActivity().getCacheDir();
-        String filename = dir.getAbsolutePath() + File.separator +  UUID.randomUUID().toString();
-        Os.mkfifo(filename, 0666);
-        File f = new File(filename);
-        return f;
-    }
-
-    private Writer getWriter() throws IOException {
-        if (mWriter == null) {
-            UiAutomation ui = getInstrumentation().getUiAutomation();
-            ui.executeShellCommand("hid " + mFifo.getAbsolutePath());
-            mWriter = new FileWriter(mFifo);
-        }
-        return mWriter;
-    }
-
-    private String getEvents(int id) throws IOException {
-        InputStream is =
-            getInstrumentation().getTargetContext().getResources().openRawResource(id);
-        return readFully(is);
-    }
-
-
-    private static void closeQuietly(AutoCloseable closeable) {
-        if (closeable != null) {
-            try {
-                closeable.close();
-            } catch (RuntimeException rethrown) {
-                throw rethrown;
-            } catch (Exception ignored) { }
-        }
-    }
-
-    private static String readFully(InputStream is) throws IOException {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        int read = 0;
-        byte[] buffer = new byte[1024];
-        while ((read = is.read(buffer)) >= 0) {
-            baos.write(buffer, 0, read);
-        }
-        return baos.toString();
-    }
-
-    private class InputListener implements InputCallback {
-        public void onKeyEvent(KeyEvent ev) {
-            boolean done = false;
-            do {
-                try {
-                    mKeys.put(new KeyEvent(ev));
-                    done = true;
-                } catch (InterruptedException ignore) { }
-            } while (!done);
-        }
-
-        public void onMotionEvent(MotionEvent ev) {
-            boolean done = false;
-            do {
-                try {
-                    mMotions.put(MotionEvent.obtain(ev));
-                    done = true;
-                } catch (InterruptedException ignore) { }
-            } while (!done);
-        }
-    }
-}