# SDL: Android: TouchDevice -1 is reserved for SDL synthetic devce (See #5322)

**URL:** <https://discourse.libsdl.org/t/sdl-android-touchdevice-1-is-reserved-for-sdl-synthetic-devce-see-5322/34785>\
**Category:** SDL Commits\
**Created:** [February 8, 2022, 10:44am UTC](https://discourse.libsdl.org/t/sdl-android-touchdevice-1-is-reserved-for-sdl-synthetic-devce-see-5322/34785 "2022-02-08T10:44:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [February 8, 2022, 10:44am UTC](https://discourse.libsdl.org/t/sdl-android-touchdevice-1-is-reserved-for-sdl-synthetic-devce-see-5322/34785/1 "2022-02-08T10:44:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/68dd84f1de159b2e6ae1d5a23f842ee87f8a175a>

```diff
From 68dd84f1de159b2e6ae1d5a23f842ee87f8a175a Mon Sep 17 00:00:00 2001
From: Sylvain <[EMAIL REDACTED]>
Date: Tue, 8 Feb 2022 11:42:24 +0100
Subject: [PATCH] Android: TouchDevice -1 is reserved for SDL synthetic devce
 (See #5322)

---
 .../src/main/java/org/libsdl/app/SDLActivity.java | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
index 812163ca36b..173fcb0614b 100644
--- a/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
+++ b/android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
@@ -1205,7 +1205,17 @@ public static void initTouch() {
         for (int id : ids) {
             InputDevice device = InputDevice.getDevice(id);
             if (device != null && (device.getSources() & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) {
- nativeAddTouch(device.getId(), device.getName());
+ int touchDevId = device.getId();
+ /*
+ * Prevent id to be -1, since it's used in SDL internal for synthetic events
+ * Appears when using Android emulator, eg:
+ * adb shell input mouse tap 100 100
+ * adb shell input touchscreen tap 100 100
+ */
+ if (touchDevId < 0) {
+ touchDevId -= 1;
+ }
+ nativeAddTouch(touchDevId, device.getName());
             }
         }
     }

```
