Simulate events in Android Emulator

I had to do some testing with application which expected certain boot events to occur to start properly.

Since it was an emulator, boot event was never received and so I was not able to start all background services related to that boot event.

To fix this, I just had to use adb to simulate the event using following commands:

Before anything create new Android profile with non-production image:

Start Android emulator using following flags

# Start emulator for profile "Pixel_2_API_30" which is created via Android Studio device manager. 
# Device must be stopped via device manager in order for this command to work!

~/Android/Sdk/emulator/emulator -avd Pixel_2_API_30 -writable-system -selinux disabled -qemu -enable-kvm

First list devices

~/Android/Sdk/platform-tools/adb devices -l

Root device

~/Android/Sdk/platform-tools/adb -s <device-id> root
~/Android/Sdk/platform-tools/adb -s <device-id> shell avbctl disable-verification
~/Android/Sdk/platform-tools/adb -s <device-id> disable-verity
~/Android/Sdk/platform-tools/adb -s <device-id> reboot 
# Wait for reboot


~/Android/Sdk/platform-tools/adb -s <device-id> root
~/Android/Sdk/platform-tools/adb -s <device-id> remount

Then I had to run the command to emit the event to the specified device

adb -s <device-id> shell am broadcast -a android.intent.action.BOOT_COMPLETED -p <app-package>

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *