Otherwise, some applications which expect touchscreen device would crash due to lacking of related resources.
This change is essential to LEB. --- tasks/fake-ts/Android.mk | 29 +++++++++++++++++ tasks/fake-ts/fake-ts.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 0 deletions(-) create mode 100644 tasks/fake-ts/Android.mk create mode 100644 tasks/fake-ts/fake-ts.c
diff --git a/tasks/fake-ts/Android.mk b/tasks/fake-ts/Android.mk new file mode 100644 index 0000000..27a9298 --- /dev/null +++ b/tasks/fake-ts/Android.mk @@ -0,0 +1,29 @@ +# Copyright (C) 2011 Linaro Ltd. +# +# 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/tasks/fake-ts/fake-ts.c b/tasks/fake-ts/fake-ts.c new file mode 100644 index 0000000..b5ec551 --- /dev/null +++ b/tasks/fake-ts/fake-ts.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2009 0xlab - http://0xlab.org/ + * + * 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; +} +