What you’ll study
- What goes wrong when several hands share one board, in the words of what an app sees.
- How an infrared frame senses touches, why two of them make four points, and the three ways frames throw the extra points out.
- What reaches Android: slots, tracking IDs, the nearest-distance fallback that assigns pointer IDs when a device gives none, and the limit of 16.
- What the system does before your app: palm cancels, and a blocker that drops touch while a pen is down.
- What an app has to decide: one stroke per pointer, what to do with a cancel, and how to tell a pen, a finger, a palm and a pinch apart.
- How to test a drawing app for many hands without a classroom.
How it connects
Guide 4 said infrared frames have ghost points in one paragraph, and followed a touch from the glass to onTouchEvent(). Guide 5 covered pointer index versus
pointer ID, ACTION_POINTER_DOWN and FLAG_CANCELED for one app. This guide is the same path on a board with many people at it, where the mistakes that are rare on a phone happen every lesson. Guide 8 handed
simultaneous strokes off as one group, and guide 9 ended with a palm as an eraser, which depends on the palm reaching you at all. Guide 11 is about drawing all of this fast on a big screen.
Read it at your level
| Level | Read | You should be able to |
|---|---|---|
| Student | The basics, the infrared lab | Say why two fingers on an infrared board can look like four |
| Fresher | + The high level, how a frame senses | Name the three ways a frame removes ghost points, and what each can’t do |
| Junior | + Pointer IDs, the pointer lab | Say what an app sees when two hands pass, when one lifts as another lands, and when 17 touch |
| Mid | + Before your app, in an app | Key strokes by pointer ID, handle a cancel, and say what the system may drop before you |
| Senior | + Edge cases, cross questions | Decide the arbitration rules for pens, fingers and palms on a shared board, and say what you couldn’t test |
The basics
A classroom board is a touchscreen the size of a table. Four students can be at it, each with a finger or a pen, and a sleeve or a palm resting on it. To your app each touch is a pointer, with a position, a pointer ID and a tool type (guide 5). That is all it knows: it doesn’t know there are four students. Every failure on this page comes from the gap between hands and pointers:
- A ghost. The board reports a touch where nobody touched, so a stroke starts from nothing.
- A swapped ID. Two hands pass, the board hands the IDs the wrong way round, and each student’s line carries on in the other’s stroke.
- A joined stroke. One student lifts as another lands, and the new touch inherits the old ID, so one stroke runs from one hand into the next.
- A seventeenth hand. Android delivers at most 16 pointers; the rest are ignored, silently.
- A palm that draws. A resting hand starts a stroke, or cancels one.
- A pinch that draws two lines. Two fingers that meant to zoom start two strokes.
Some of these are the board’s doing, some Android’s, and some are your app’s to decide. Telling which is which is most of the work.
Try it: the infrared frame lab
An infrared frame is LEDs along two edges facing light sensors on the opposite edges. Each LED and sensor pair is a beam, and a finger that blocks beams is a touch. Drag the touches. Faint lines are the beams a finger blocks; each crossing of a blocked column with a blocked row is a candidate point. A ring is a candidate that is a real touch, and a red cross is a ghost the frame would report.
Things to try. Each starts from the lab’s defaults (Touches 2, Finger 14 px, Beams every 10 px, Method columns and rows, the touches where the lab puts them) and names every setting it changes.
- Two touches make four points. With the defaults, there are 4 crossings, 2 of them ghosts, and both ghosts are reported. The ghosts are the other two corners of the rectangle the touches span.
- One more direction removes them here. Set Method to + one diagonal set: 4 crossings, 0 ghosts reported, no real touch lost. A ghost is only kept if a blocked diagonal beam passes through it too.
- More touches, more ghosts. Set Touches to 3: 9 crossings, 6 of them ghosts, all reported. With + one diagonal set, 2 ghosts are still reported. With + both diagonal sets, 0. Set Touches to 4: 16 crossings, 12 ghosts; with one diagonal set 6 are reported, with both 0.
- The positions matter. Touches is 4 and Method is + both diagonal sets. Drag a touch until it is level with another, and the crossings fall: touches that share a row share a shadow, so they make fewer points. Drag two close together and their shadows merge; the model puts a touch at each end of the wide shadow, and in the example I tried (touch 3 dragged next to touch 1) one real touch was no longer reported. A third finger between two merged ones would not be found.
- Landing order. Set Method to Landing order: 0 ghosts and no touch lost, at 2, 3 or 4 touches. Now set it to Landing order, landed together: the 4 crossings and 2 ghosts of the first bullet are back, because there is no order to use. The model lands the touches in the order 1 to 4 each time you drag.
- A big finger changes nothing at these positions. Set Finger to Palm (22 px), or Beams every to 16 px: the counts for two touches are the same. Wider shadows only matter when the touches are close.
Across 400 random layouts of three 14 px fingers in this frame (a fixed seed), columns and rows alone lose a real touch in 30, one diagonal set still reports a ghost in 172, and both sets still report a ghost in 60 and lose a real touch in 34 (the extra four are probably down to how the model estimates a position; I haven’t traced them). These are the model’s numbers, not a panel’s.
This is a model of the ideas, with beams, shadows and crossings. It has no panel’s firmware, no beam attenuation and no timing.
The high level
| Step | What it does | Where it goes wrong |
|---|---|---|
| Sense | Beams blocked in each direction | Two touches make four crossings |
| Resolve | The controller keeps the real points: extra beam directions, landing order, or splitting the screen | Touches that land together, a third touch level with an earlier one, or touches close together |
| Track | The controller or Android gives each touch an ID that follows it | Two touches pass, or one lifts as another lands |
| Cap | At most 16 pointers per event reach the app | A seventeenth hand is ignored |
| Filter | The system cancels palms and may drop touch while a pen is down | Your app sees a cancel, or sees nothing |
| Decide | The app turns pointers into strokes, gestures and erasing | Pens, fingers, palms and pinches that look alike |
The low level
Source excerpts are from AOSP main (frameworks/native), trimmed with …. Where the text describes how a panel’s controller resolves ghost points, it is describing one published patent, which is one vendor’s method; no panel’s firmware is read here. Links are in The map.
1. How an infrared frame senses
Guide 4 gave the idea: LEDs and sensors around the bezel, pulsed in turn, a touch seen as the beams it blocks, in X and in Y. The controller gets one number per beam, blocked or not, and a touch is a run of neighbouring blocked beams, its shadow. One finger blocks a few columns and a few rows (the lab shows 2 or 3 of each for a 14 px finger and 10 px between beams), and its position is taken from the middle of the shadows. No beam knows how hard it was blocked, which is why a frame reports a contact size and no pressure (guide 4).
2. Why two touches make four points
The controller knows which columns are blocked and which rows are blocked. It does not know which column goes with which row. With one touch there is one of each, so one answer. With two touches there are two blocked columns and two blocked rows, and each column could go with each row: four crossings, two of them real. The other two are ghosts: a point on the board where nothing touches, with a shadow in its column and a shadow in its row. In general, n touches that share no column or row make n² crossings and n² − n ghosts. The lab’s four touches make 16 and 12.
Touches that share a row (or a column) make fewer crossings, because their shadows merge into one. That is why the ghosts of a frame depend on where the hands are, and why they appear and vanish as hands move.
3. Three ways to throw them out
A patent from Beijing IRTouch Systems (US 9,395,849 B2, filed 2013) describes the methods that were common before it, and its own:
- Time division. The patent’s description: touches arrive a few milliseconds apart, a second touch makes a ghost, and the real second touch is the one diagonal to the first. The lab’s Landing order is a model of that idea, and its rule for several candidates is the lab’s own: one new crossing is the new touch and is accepted; with several, only a crossing that shares no column or row with a touch it already has is kept. That throws out the ghosts, and it also throws out a real touch that lands level with an earlier one, which then looks like a ghost. With two touches that can’t happen, because there is one new crossing; with three it can. It fails outright when touches land together (the lab’s other button), because there is no order to use. The lab lands the touches in the order 1 to 4 again each time you drag.
- Partitioning. Divide the screen physically into several areas, each of which locates one touch; the patent says this is used to eliminate the ghosts produced when a touch moves, by seeing it move from one area to another. The price is in the design: one touch per area, so it limits how many hands can use the board and where. The lab does not model it.
- More beam directions. The patent’s own method scans with a second and third set of beams at angles to the first: the axis-aligned scan gives a set of candidate points, each off-axis scan gives a set it must agree with, and comparing them removes the ghosts. A ghost has a shadow in its column and its row, but usually not along a diagonal; a real touch has a shadow in all of them. The lab’s + one diagonal set and + both diagonal sets do this with 45° beams.
The lab shows two of the three, and what each leaves. The counts, for the default positions: with 3 touches, columns and rows leave 6 ghosts, one diagonal set leaves 2, two sets leave 0. They don’t remove every ghost: a ghost survives when it happens to lie in the shadow of a real touch along every direction, which is more likely with more touches (60 of 400 random three-finger layouts keep a ghost with both sets). The patent’s abstract says its off-axis scans use the same transmitting and receiving tubes, “aligned with a first direction off-axis” and then a second, and that it needs only one set of detecting elements. I don’t know what any of this costs in scan time on a real panel.
What this means for an app: you can’t see which method a panel uses, and you can’t turn ghosts off. You can see their effects: a stroke that begins where nobody touched, and strokes that jump when hands line up. The vendor’s controller decides, and some panels do better than others,, which is a reason to test on the panels you ship to.
4. What reaches Android
The controller reports contacts the way guide 4 described: Linux multi-touch slots, each with a tracking ID (type B), or no tracking IDs. Guide 4 and guide 5 followed the next step, where MultiTouchInputMapper::syncTouch maps each tracking ID to the lowest free pointer ID and delivers at most 16 pointers. Three details matter for many hands.
The cap is silent, and it cuts by slot. The mapper reads up to 32 slots but stops at 16 delivered pointers:
// MultiTouchInputMapper::syncTouch, MultiTouchInputMapper.cpp, trimmed
for (size_t inIndex = 0; inIndex < inCount; inIndex++) {
…
if (outCount >= MAX_POINTERS) {
…
break; // too many fingers!
}
The ones that are cut are the ones in higher slots. MotionEvent’s own parcel check refuses an event with more than 16 pointers (MAX_POINTERS in Input.h, the same limit guide 5 listed), so nothing downstream could carry them. A 20-point panel can’t give one app 20 hands, and the app is not told that 4 were left out.
In the pointer lab, 20 hands give 16 delivered and 4 dropped by either route.
A device without tracking IDs gets nearest-distance matching. If the device gives no tracking IDs, TouchInputMapper::assignPointerIds decides which new contact is which old one by distance:
// TouchInputMapper::assignPointerIds, TouchInputMapper.cpp, trimmed
if (currentPointerCount == 1 && lastPointerCount == 1 &&
current.rawPointerData.pointers[0].toolType == last.rawPointerData.pointers[0].toolType) {
// Only one pointer and no change in count so it must have the same id as before.
…
}
// General case.
// We build a heap of squared euclidean distances between current and last pointers … Then, we find the best
// match (by distance) for each current pointer. The pointers must have the same tool type …
After that it takes the matches in order of increasing distance, skipping pointers already matched, and gives the pointers nothing matched the lowest IDs that no match is using. Two things follow, and the lab shows both:
- A lift and a landing in one report inherit the ID. With one pointer before and one after, of the same tool type, the code says it “must have the same id as before”, whatever the distance. One student lifts, another lands anywhere, and the app sees one continuous touch. In the lab’s One lifts, another lands with Nearest distance, an ID carries on to the other hand, at any distance from 4 px to 40 px. With Device tracking IDs, it doesn’t (the lab hands each hand its own tracking ID).
- Two hands that pass between reports can swap. The greedy match takes the smallest distance first. When the pointers move farther in one report than the gap between them and pass each other within it, each new position is nearest the other’s old one, and the IDs swap. In the lab’s Two fingers pass with Nearest distance, the swap starts just above the 6 px gap (it happens at 7 px per report, not at 6 or below). The lab puts the pass exactly between two reports, which is the worst case: a pass that falls on a report never swaps. With Device tracking IDs it doesn’t, because in the lab each hand arrives with its own tracking ID. A real controller has to derive that ID from the shadows, and faces the same ambiguity one step earlier: the decision moves into the controller, where neither Android nor your app can see it.
Whether a panel gives tracking IDs is something to find out, not assume. A device that reports them has already made the decision in its controller. adb shell getevent -lp lists a device’s axes, and the one to look for is ABS_MT_TRACKING_ID (guide 4 used getevent -lt to read the events themselves).
A tracking ID’s pointer ID is not reused in the report it lifts. The mapper marks new IDs in the previous report’s set, so an ID that lifts in a report is free from the next one. With tracking IDs, one student lifting and another landing in the same report get different pointer IDs, and the old one is free a report later (the pointer lab’s grid shows it).
5. Before your app
Three things can happen to a touch between the controller and onTouchEvent().
A palm flagged by the controller is cancelled. If a slot’s tool type is a palm, syncTouch doesn’t deliver it as a touch: it marks the pointer’s ID as cancelled, and the dispatch code sends ACTION_POINTER_UP with FLAG_CANCELED (or ACTION_CANCEL if it was the last pointer; guide 4 says the same). In the framework MotionEvent.TOOL_TYPE_PALM is hidden from the SDK, so an app never sees a palm as a type. It sees a cancel. Guide 5’s rule applies: drop a pointer’s stroke on a cancel.
The software palm model is off by default. UnwantedInteractionBlocker’s palm rejection runs only when the palm_rejection_enabled flag is set, and it defaults to "0" (guide 4). Most boards rely on their controller, or on your app.
Pen down may drop touch, per device. PreferStylusOverTouchBlocker is documented in its header in one line: “When stylus is down, all touch is ignored”, with a TODO to remove it when simultaneous stylus and touch is supported. A comment in UnwantedInteractionBlocker.cpp says that when multi-device input is enabled the blocker isn’t used, and that multi-device input
by default makes a hovering stylus reject touch. Both depend on build flags. And the blocker keeps a set of devices with mixed tool types, those that deliver stylus and touch in one stream, and does nothing to them. On a shared board, one student writing with a pen while another touches could therefore get their touches cancelled, or not, depending on the
build and on whether the panel exposes pen and touch as one device or two. This guide did not find a rule that settles it for a given panel: test it on yours, with a pen down and a finger on the other side of the board.
6. In an app
One stroke per pointer ID. Keep a map from pointer ID to the stroke in progress. On ACTION_DOWN and ACTION_POINTER_DOWN, start one for the pointer at actionIndex; on moves, add each pointer’s samples to its stroke, by ID, with the history (guide 5); on ACTION_POINTER_UP and ACTION_UP, finish that pointer’s stroke; on a cancel,
drop it. Jetpack Ink’s InProgressStrokesView is built for this: startStroke(event, pointerId, brush), addToStroke(event, pointerId), finishStroke(event, pointerId) and cancelStroke(event, pointerId) take the pointer ID, and strokes that are in progress together are handed off as one group (guide 8). The Ink 1.1.0-alpha11 notes list a fix for “handling of concurrent inputs”; the snippet targets 1.0.0.
class ManyHandsInk(private val view: InProgressStrokesView, private val penBrush: Brush, private val fingerBrush: Brush) {
private val strokes = HashMap<Int, InProgressStrokeId>() // pointer ID -> its stroke
/** Call from onTouchEvent. Returns true if the event was used. */
fun onTouch(event: MotionEvent): Boolean {
when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN -> startStroke(event, event.actionIndex)
MotionEvent.ACTION_MOVE -> {
for (i in 0 until event.pointerCount) {
val id = strokes[event.getPointerId(i)] ?: continue
view.addToStroke(event, event.getPointerId(i), id)
}
}
MotionEvent.ACTION_POINTER_UP, MotionEvent.ACTION_UP -> {
val i = event.actionIndex
val pointerId = event.getPointerId(i)
val id = strokes.remove(pointerId) ?: return true
// a palm the system cancelled arrives as a POINTER_UP with FLAG_CANCELED: drop its stroke
if (isCancelled(event)) view.cancelStroke(id, event) else view.finishStroke(event, pointerId, id)
}
MotionEvent.ACTION_CANCEL -> {
for ((pointerId, id) in strokes) view.cancelStroke(id, event)
strokes.clear()
}
}
return true
}
private fun startStroke(event: MotionEvent, index: Int) {
val brush = when (event.getToolType(index)) {
MotionEvent.TOOL_TYPE_STYLUS -> penBrush
MotionEvent.TOOL_TYPE_FINGER -> fingerBrush
else -> return // an eraser or something else: not ink
}
val pointerId = event.getPointerId(index)
strokes[pointerId] = view.startStroke(event, pointerId, brush)
}
// guide 5's helper: before API 33 there is no flag, so only ACTION_CANCEL can be recognised
private fun isCancelled(event: MotionEvent): Boolean =
event.actionMasked == MotionEvent.ACTION_CANCEL ||
(Build.VERSION.SDK_INT >= 33 && (event.flags and MotionEvent.FLAG_CANCELED) != 0)
}
Telling a pen, a finger, a palm and a pinch apart is a set of rules you choose, not something Android decides for you. These are design choices, not platform behaviour, and the rows assume the board reports a stylus as TOOL_TYPE_STYLUS. I found no source for how an infrared board reports a pen: guide 4 says a frame sees a blocked beam, whatever blocks it, so a pen may arrive as a finger, and then two pens are the ambiguous “two fingers” rows. Check what your panel reports.
| Situation | What the app sees | A reasonable rule |
|---|---|---|
| A stylus lands | TOOL_TYPE_STYLUS |
Ink, from the first sample |
| The eraser end lands | TOOL_TYPE_ERASER |
Erase (guide 9) |
| A finger lands while a stylus is down | TOOL_TYPE_FINGER, often a large contact |
Probably the writing hand: don’t ink it. The system may already have cancelled it (above) |
| A finger with a large contact | getTouchMajor() above a threshold you choose |
A palm, or an eraser if you choose that (guide 9) |
| Two fingers, close together, moving apart or together | Two FINGER pointers |
A pinch: cancel their strokes and zoom |
| Two fingers, far apart | Two FINGER pointers |
Two students: two strokes |
| Two styli | Two STYLUS pointers |
Two students writing: two strokes |
The “close together” and “far apart” rows are the soft ones: nothing in the event says whether two fingers belong to one hand. Use a small distance threshold, and decide after the first few samples, not on the second pointer’s DOWN, so that a stroke that began as a finger can be cancelled when it becomes a pinch. Ink’s cancelStroke is for that. Whatever you choose, say it on screen, because two students will
disagree with whatever the board decides.
The ManyHandsInk snippet above inks every finger and every stylus with a brush: it applies none of this table’s rules (a stylus down, a palm, a pinch). Here are helpers for two of them, with thresholds you pick for your panel:
fun looksLikePalm(event: MotionEvent, index: Int, thresholdPx: Float): Boolean =
event.getToolType(index) == MotionEvent.TOOL_TYPE_FINGER &&
maxOf(event.getTouchMajor(index), event.getTouchMinor(index)) > thresholdPx
fun looksLikePinch(event: MotionEvent, a: Int, b: Int, nearPx: Float): Boolean {
if (event.getToolType(a) != MotionEvent.TOOL_TYPE_FINGER || event.getToolType(b) != MotionEvent.TOOL_TYPE_FINGER) return false
val dx = event.getX(a) - event.getX(b)
val dy = event.getY(a) - event.getY(b)
return dx * dx + dy * dy < nearPx * nearPx
}
Testing without a classroom. The pointer lab’s scenes are tests you can run on your own board or emulator: two fingers passing at a speed above the gap, a lift with a landing in the same frame, and more hands than 16. The framework checks the 16-pointer limit when a motion event is read from a parcel (MotionEvent::readFromParcel); I did not test what happens to an app’s own synthetic event with more. For a real panel, a few people at it with a log of
pointer IDs per report will show what the controller does.
Try it: the pointer lab
The same scenes as numbers. A cell is the pointer ID the app sees for that hand in that report. Red outline: the hand’s ID changed while it kept touching. Amber outline: the ID carried on from another hand’s touch.
Things to try. Each starts from the lab’s defaults (Scene Two fingers pass, IDs come from Nearest distance, Speed 8 px/report) and names every setting it changes.
- A swap. With the defaults, 2 hands’ IDs changed and 2 IDs carried on to the other hand. Set IDs come from to Device tracking IDs: 0 and 0. That is because the lab gives each hand its own tracking ID; a real controller has to work it out from the shadows.
- The threshold is the gap. With Nearest distance, set Speed to 6 px/report, and to 2: 0 and 0. The two fingers are 6 px apart. At 7 it swaps again (2 and 2). The pass falls exactly between two reports, the worst case.
- A lift and a landing. Set Scene to One lifts, another lands, with Nearest distance: 1 ID carried on, at any Distance between the two hands from 4 to 40 px. With Device tracking IDs, 0, and the new hand’s cell shows the next ID, not the old one.
- Too many hands. Set Scene to Many hands at once. At 16 Hands: 16 pointers in the busiest report, none dropped. At 20: 16 and 4. At 24: 16 and 8. The two ways to get IDs give the same counts.
The lab is a port of the rules in the AOSP code above, with its simplifications: no hover, no palms, no coordinate transforms, and equal distances are broken in generation order, where the C++ heap’s order for equal distances isn’t specified.
Checkpoint
You should be able to say:
- A board’s hands are pointers to the app, and every many-hands failure is a gap between hands and pointers.
- Two touches on an infrared frame cross at four points; n touches that share no column or row make n² and n² − n of them are ghosts.
- A frame can remove ghosts by landing order, by dividing the screen, or by scanning at more angles; in the lab landing order and extra angles each leave cases they can’t handle.
- Android delivers at most 16 pointers, cut by slot, and doesn’t tell you about the others.
- Without tracking IDs, Android matches pointers by nearest distance: one lift and one landing in one report inherit the ID, and hands that pass between reports can swap. A controller that reports tracking IDs has to decide the same thing itself.
- A palm the controller flags arrives as a cancel, not as a type; the software palm model is off by default; pen down may drop touch, depending on the build and the device layout.
- Key strokes by pointer ID, cancel on a cancel, and choose the pen, finger, palm and pinch rules yourself.
Why it helps
| Symptom | What is happening | What to do |
|---|---|---|
| A stroke starts where nobody touched | A ghost point, from the controller | Nothing in the app can see it for sure. A minimum travel or time before inking helps, and delays a tap; test on the panel |
| Two students’ lines swap halves when they cross | Nearest-distance matching swapped the IDs, or the controller’s own IDs did | Check whether the device reports tracking IDs; if it doesn’t, expect swaps when hands move farther per report than the gap between them |
| One stroke runs from one student’s spot to another’s | A lift and a landing in one report inherited the ID | Start a new stroke when a pointer jumps farther than a hand could in a frame |
| The 17th student’s finger does nothing | MAX_POINTERS is 16 |
Tell the user: the app is not told, and neither is anyone else |
| A stroke disappears as a pen goes down | Touch dropped or cancelled while a stylus is down | Test your panel; drop the cancelled pointer’s stroke and don’t treat it as an error |
| A palm leaves a mark | The cancel arrived late, or the palm model is off | Cancel the stroke on FLAG_CANCELED, and add a contact-size rule |
| A zoom draws two lines | Two fingers were treated as two students | Decide after a few samples, and cancel the strokes if it becomes a pinch |
The map
| Topic | Code | Where |
|---|---|---|
| Slots into pointers, the cap | MultiTouchInputMapper::syncTouch |
MultiTouchInputMapper.cpp |
| Nearest-distance IDs | TouchInputMapper::assignPointerIds |
TouchInputMapper.cpp |
| The pointer limits | MAX_POINTERS, MAX_POINTER_ID |
Input.h |
| Stylus over touch | PreferStylusOverTouchBlocker |
PreferStylusOverTouchBlocker.h |
| Palm rejection and the flags | UnwantedInteractionBlocker |
UnwantedInteractionBlocker.cpp |
| The hidden palm tool type | TOOL_TYPE_PALM |
MotionEvent.java |
| Infrared ghost points | The background section and method | US 9,395,849 B2 |
| How a frame senses | Beams in X and Y | Elo |
| Per-pointer ink | InProgressStrokesView |
Ink releases |
| IDs, cancel and tool types | getPointerId, FLAG_CANCELED |
guide 5 |
Edge cases
- Hover. A hovering pointer has an ID too. A pen hovering near a board can reject touch under the multi-device default (above), and a hover never starts a stroke.
- IDs after a cancel. Once a cancelled palm’s pointer-up has been delivered, its ID is free for the next touch, so a new student’s finger can get the ID a palm just had. Drop the palm’s stroke at the cancel so nothing is left under that ID.
- Rotation. The nearest-distance match works in the device’s own units before the display transform, so it is the same whatever way the board is mounted.
- Pen and finger from one student. A student writing with a pen rests their hand: a large finger contact beside a stylus. The rules above treat the finger as a palm while a stylus is down, and a student who writes with a finger and erases with a palm will fight them.
- Ghosts that move. A ghost follows its real touches, so a ghost can drag a line across the board as two hands move. A stroke that never reaches a minimum travel or time can be thrown away at
UP, but it also throws away a tap. - Version differences. This is AOSP
mainas read on 17 November 2026 and Ink 1.0.0. Release builds differ, and the stylus blocker’s behaviour depends on flags.
Cross questions
Why does an infrared board with two fingers on it sometimes show a third point?
Two touches block two columns and two rows, which cross at four points. Two are real and two are ghosts. A good controller removes the ghosts with beams at other angles, or the order the touches landed in, or by splitting the board into areas. None removes every ghost, and the cases each can't handle are the ones the infrared lab lets you drag into.
Can my app tell a ghost from a real touch?
Not reliably. The event for a ghost looks like any other: a pointer with a position and a pointer ID. The controller decides, before Android. What an app can do is notice its effects, such as a pointer that appears away from any hand and never moves, and test on the panels it ships to. This guide did not find any flag on the event that marks one.
Why did two students' lines swap when they crossed?
If the device gives no tracking IDs, Android matches each new contact to the nearest old one, smallest distance first. When two contacts pass each other between two reports and move farther than the gap between them, each new position is nearest the other's old one, and the IDs swap. The pointer lab shows it from 7 px per report with a 6 px gap. A device that reports tracking IDs has moved the problem into its controller, which has to decide the same thing from its own data.
Why did one stroke run from one student's touch into another's?
With no tracking IDs, one pointer before and one after, of the same tool type, keep the ID whatever the distance: the code says it must be the same one. If one student lifts as another lands in the same frame, the app sees one touch that jumped. Start a new stroke when a pointer's position jumps more than a hand could move in one report.
What happens to a seventeenth finger?
It is ignored. The mapper reads up to 32 slots but delivers 16 pointers, and stops at the sixteenth: the contacts in higher slots never become pointers, and the app is not told. A motion event can't hold more than 16 pointers anyway.
Does Android reject palms for me?
Only if the controller flags a contact as a palm, which Android turns into a cancel, or if the software palm model is switched on, which it isn't by default. An app sees a cancel, never a palm type, because TOOL_TYPE_PALM is hidden from the SDK. Most boards need the app's own rule, such as a contact-size threshold, as well.
Will a student's touch be ignored while another writes with a pen?
It can be. The system has a blocker that ignores touch while a stylus is down, and under a newer setting a hovering stylus rejects touch. Both depend on build flags, and a device that sends pen and touch in one stream is left alone. Which applies to a given panel is something to test, with a pen down and a finger on the far side.
How do I tell two pens from a pinch?
By tool type, for pens: two stylus pointers are two writers. Two fingers are ambiguous: the event doesn't say whether they belong to one hand. Use a distance threshold and wait a few samples before deciding, and cancel the strokes if it turns out to be a pinch.
Revision: key points
- Hands are pointers to the app; ghost points, swapped IDs, joined strokes, the 16-pointer cap and palms are the gaps.
- Two touches cross at four points on an infrared frame; n touches make n² crossings and n² − n ghosts.
- Frames remove ghosts by landing order (fails for touches landing together, and can fail for a third touch level with an earlier one), by partitioning (one touch per area), or by scanning at more angles (fewer ghosts, never none).
- The mapper reads 32 slots and delivers 16 pointers, cutting by slot, silently.
- Without tracking IDs,
assignPointerIdsmatches by nearest distance: one in and one out inherit the ID, and hands passing between reports can swap. - A controller-flagged palm becomes a
FLAG_CANCELEDpointer-up;TOOL_TYPE_PALMis hidden; the palm model is off by default. - Pen down can drop touch, depending on flags and on whether pen and touch share a device.
- Key strokes by pointer ID, cancel on cancel, and choose the pen, finger, palm and pinch rules yourself.
Cheat sheet
Each concept in a few words.
| Concept | In a few words |
|---|---|
| Pointer | All the app sees of a hand. |
| Ghost point | A crossing of blocked beams where nobody is touching. |
| Shadow | The run of blocked beams one finger makes. |
| Extra beam angles | Diagonal scans must agree: fewer ghosts, never none. |
| Landing order | Trust earlier touches; a new one diagonal to them is real. |
| Tracking ID | A contact’s name from the controller. |
| Nearest-distance matching | Android’s fallback for IDs; hands passing between reports can swap. |
| 16-pointer cap | Higher slots are dropped without telling the app. |
| Palm cancel | A controller-flagged palm arrives as FLAG_CANCELED. |
| Pen over touch | Touch may be dropped while a pen is down. |
Read next
- The patent for the ideas: US 9,395,849 B2, “Infrared touch screen multi-point recognizing method and infrared touch screen”
- The source: the files in The map, especially
assignPointerIdsandsyncTouch - References: Ink releases, and guide 4 and guide 5 for the path and the event
- Where real software uses this: the interactive whiteboards that let several people write at once; the lab is a model of the problem, not of any one product
Search terms that find more: infrared touch ghost points multi-touch, ABS_MT_TRACKING_ID slots protocol B, assignPointerIds, MAX_POINTERS 16 Android, FLAG_CANCELED palm, PreferStylusOverTouchBlocker, pointer id swap, multi-user whiteboard touch.
The fine print
The source was read from AOSP main (frameworks/native, frameworks/base) on 17 November 2026 and the Kotlin sources of androidx.ink 1.0.0 and 1.1.0-alpha11 release notes. The patent was read in its background section and abstract, not in full. The Kotlin snippets compile against androidx.ink 1.0.0 and were linted at minSdk 26; they were not run on a device, and nothing in this guide was run on a panel. Both labs are TypeScript models whose tests check the rules written in them, with no library or panel vectors to check against: the infrared lab is this guide’s own geometry (beams, shadows, crossings, and three ways of removing ghosts); the pointer lab is a port of the AOSP rules described above, without hover, palms or transforms, and with equal distances broken in generation order. The infrared lab’s statistics are over 400 random layouts from a fixed seed, with a 14 px finger and 10 px between beams. They are not measurements of any panel, and no panel’s firmware is run. The page was checked in one desktop browser at about 1411 px: the infrared lab in dark with three touches and the pointer lab in light with 20 hands, drags sent as synthetic pointer events, and every “Things to try” number read back from the page. Narrow widths and a phone were not checked. On 18 November both labs were opened again on the dev server and their starting numbers read back (the infrared lab: 4 crossings, 2 ghosts, 2 reported; the pointer lab: 2 IDs changed, 2 carried on).
Part of the ink series: 1. Why naive drawing feels bad, 2. Canvas, Paint and Path, 3. Looper, epoll and vsync, 4. From glass to your app, 5. Reading a MotionEvent, 6. Smoothing and predicting the pen, 7. From points to a stroke mesh, 8. Drawing with low latency, 9. The eraser.