The trick is the accelerometer, the small motion sensor that rotates your screen when you turn the phone sideways. When a phone is charging and resting still, that sensor can pick up the faint early tremor of a quake.
If it feels movement that looks like an earthquake, the phone sends an anonymous signal and a rough location to Google’s servers. The servers then check whether many nearby phones are reporting the same thing at the same moment. When enough of them agree, Google concludes a quake is underway and sends warnings to people in the area that is about to shake.
The warning can beat the shaking because earthquakes release two kinds of waves. The first, called P-waves, are fast but fairly gentle. The damaging S-waves follow more slowly. A radio signal from your phone travels far faster than either, so the network can raise the alarm while the strong waves are still on their way.
Things work a little differently on the US West Coast. In California, Oregon and Washington, Android takes its warnings from ShakeAlert, the government-backed system that relies on a network of 1,675 ground sensors. Google started that partnership in 2020, then began sending alerts from its own phone-based detection in April 2021, first in New Zealand and Greece.