Search code examples
androidkernelandroid-source

Where is the property 'ro.boot.bootreason' being set in Android Open Source Project?


I have 2 devices with different android version (10 and 11) and i get a different boot reason on them. I have some specific logic and it depends on boot reason reboot or userrequested,but sometimes i just get USB during the same use cases

I saw similar topic and regarding to this comment https://stackoverflow.com/a/74610721/13694677 I can see androidboot.bootreason=usb in this file but how and where it calculates?


Solution

  • A bootloader uses uniquely-available hardware and memory resources to determine why a device rebooted, then communicates that determination by adding androidboot.bootreason= to the Android kernel command line for its launch. init then translates this command line to propagate to the Android property bootloader_boot_reason_prop (ro.boot.bootreason). For devices launching with Android 12 or later, using kernel version 5.10 or greater, androidboot.bootreason= is added to bootconfig instead of the kernel command line.

    https://source.android.com/docs/core/architecture/bootloader/boot-reason

    If you want to do logic base on boot reason, you should be careful. The vendor do not follow Android's recommendation. So the bootreason you got will be different.