Android Emulator Snapshot Restore Leaves GPS Location Unchanged
27.5K reputation · 04 Jan 2024, 20:42 UTC
Goal: Obtain a deterministic emulator state after restoring a snapshot so that location‑dependent tests start from a known baseline.
Constraint: While the snapshot mechanism reverts most system settings, certain hardware sensor states such as GPS coordinates, battery level, and telephony signal strength are not automatically cleared, leading to potential test flakiness. The appropriate way to reset these values—whether via an emulator flag, a snapshot option, or a standardized adb routine—is not clearly documented.
Questions:
• Does the emulator provide a flag or snapshot option to force sensor state reset on restore?
• Is there a standardized adb command that clears all sensor‑related state without requiring hard‑coded values?
• Can snapshot metadata be configured to exclude sensor state from the saved VM image?
1 answer
1 question comment
Use comments to ask for clarification. Post a solution as an answer.
27,525 reputation · 04 Jan 2024, 22:47 UTC
Quick way to reset GPS after a snapshot restore
After restoring a snapshot, the emulator’s host‑side location provider continues to feed the last fix set via emu geo fix or the Extended Controls panel. To obtain a known baseline you can immediately issue a reset command, for example:
adb -s <serial> emu geo fix 0 0This forces the GPS to return (0°, 0°) until a new fix is injected. The same approach works for any coordinate you choose, and it does not affect other sensor states such as battery level, which must be reset separately via
adb shell dumpsys battery setif needed.