summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Huang <jim.huang@linaro.org>2011-06-29 01:22:52 +0800
committerJim Huang <jim.huang@linaro.org>2011-06-29 01:22:52 +0800
commit89a3940ca2ad04a54e4a8aa315f0089ce4621d17 (patch)
tree8d3a2d5ac8c4bbcfec2796172dc9f6abad7cab77
parentcc108a6396661b453085fd4be7011f69acf52d87 (diff)
[LINARO] Add fake touchscreen 'driver' to avoid Android activity crash
Some Android activities like 'Music' expect the presence of touchscreen device, otherwise they would crash due to lacking of corresponding system resources. To fix the crash, a fake touchscreen 'driver' is added, which utilizes uinput to register a touchscreen device in kernel.
-rw-r--r--fake-ts/Android.mk30
-rw-r--r--fake-ts/fake-ts.c76
2 files changed, 106 insertions, 0 deletions
diff --git a/fake-ts/Android.mk b/fake-ts/Android.mk
new file mode 100644
index 0000000..3c3ba4c
--- /dev/null
+++ b/fake-ts/Android.mk
@@ -0,0 +1,30 @@
+# Copyright (C) 2011 Linaro Limited
+#
+# 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.
+
+LOCAL_PATH:= $(call my-dir)
+
+ifneq ($(TARGET_SIMULATOR),true)
+
+include $(CLEAR_VARS)
+
+LOCAL_MODULE := faketsd
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := fake-ts.c
+LOCAL_PRELINK_MODULE := false
+
+include $(BUILD_EXECUTABLE)
+
+endif # !TARGET_SIMULATOR
diff --git a/fake-ts/fake-ts.c b/fake-ts/fake-ts.c
new file mode 100644
index 0000000..9fe0a20
--- /dev/null
+++ b/fake-ts/fake-ts.c
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2011 Linaro Limited
+ *
+ * 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.
+ */
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+
+#include <linux/uinput.h>
+
+/* look up source file system/core/init/devices.c for exact node */
+#define UINPUT_DEV "/dev/uinput"
+
+#define DEV_NAME "Fake Touchscreen"
+
+static int uinput_fd = 0;
+
+static void uinput_touch_init(const char* uinput_dev,
+ const char* dev_name)
+{
+ struct uinput_user_dev dev;
+
+ uinput_fd = open(uinput_dev, O_WRONLY);
+ if (uinput_fd <= 0) {
+ perror("Error opening uinput device.\n");
+ return;
+ }
+ memset(&dev, 0, sizeof(dev));
+ strcpy(dev.name, dev_name);
+ write(uinput_fd, &dev, sizeof(dev));
+
+ /* touch screen event */
+ ioctl(uinput_fd, UI_SET_EVBIT, EV_ABS);
+ ioctl(uinput_fd, UI_SET_ABSBIT, ABS_X);
+ ioctl(uinput_fd, UI_SET_ABSBIT, ABS_Y);
+ ioctl(uinput_fd, UI_SET_EVBIT, EV_KEY);
+ ioctl(uinput_fd, UI_SET_KEYBIT, BTN_TOUCH);
+
+ /* register userspace input device */
+ ioctl(uinput_fd, UI_DEV_CREATE, 0);
+}
+
+static void uinput_touch_deinit()
+{
+ if (uinput_fd > 0) {
+ close(uinput_fd);
+ }
+}
+
+int main(int argc, char* argv[])
+{
+ uinput_touch_init(UINPUT_DEV, DEV_NAME);
+
+ while (1) {
+ sleep(60);
+ }
+
+ uinput_touch_deinit();
+
+ return 0;
+}
+