What is the fastest way to shutdown unrooted Android phone?


Question

Sometimes I need to have my phone shut down as fast as possible. In older phones I was able to remove the battery, but after some "innovations" this feature is no longer present. Is there any better option than using casual shutdown and waiting for long seconds until it gets down? It is especially bad when I pour water on my phone and the touchscreen refuses to work.



I am using Xiaomo Pocophone F1 with Android 9.0.


Answer

In fact without removing battery it's not possible to shut down a device completely in order to avoid the loss that could possibly occur due to short circuit caused by water.



Let's have a brief look at what shut down means and what are possible options to achieve this.



HOW SHUTDOWN WORKS?

Android is based on Linux kernel which is the very first executable of operating system which is run during boot process. Kernel initializes necessary hardware and prepares a basic environment before executing init, the very first userspace process we can see. It's init which then starts and takes care of all services and processes. On shutdown, reverse of this happens.



INIT

When you tap Power Off from Power Menu, or when you issue reboot -p command from terminal app or adb, it sets Android property sys.powerctl to shutdown (with an optional reason for shutdown) which tells init it's time to save any unsaved work to persistent storage, stop all services and processes gracefully (or brutally), sync filesystem caches, un-mount filesystems and then hand over charge to kernel by making syscall reboot (ref). Kernel then makes sure all userspace processes are stopped including init, forcibly unmounts any stubborn filesystems and ultimately powers down hardware devices including CPUs and RAM.



Android's init supports two modes: shutdown and reboot. Linux init has some more shutdown options including halt and poweroff. See this answer for more details.



KERNEL

Most of the time during shut down is taken by init. In order to save time you can bypass init and ask kernel directly for a poweroff by making syscall:



reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF)


That's what busybox poweroff -f command or the magic SysRq key O (equivalent to Alt-SysRq-O on a PC) would do (ref). Both should be preceded by sync to avoid damaging filesystems. From commandline we can do:



~# echo 1 >/proc/sys/kernel/sysrq 
~# echo s >/proc/sysrq-trigger
~# echo o >/proc/sysrq-trigger


This is the fastest way to shutdown OS on rooted device.



HARD REBOOT

But how to power down the device if even the kernel becomes non-responsive? Hardware can usually take care of this i.e. if you keep power button pressed for a fixed time interval. There's some hard-coded value (mostly 10 seconds) inside Power Management Unit (PMIC). No process will be stopped, no filesystem would be unmounted, no goodbye would be conveyed, just the power will be cut to CPU, RAM and other relevant hardware resources. Most SoCs (which have PMIC embedded inside) implement this as reboot, not shut down.






So to summarize the above lines, there are two ways to shutdown device: through init or calling kernel directly. Both can be achieved through simple shell commands or can be mapped to some hardware key or special key combination. But water can make any hardware key useless, so this method can't be a universal solution.






POWER BUTTON

But the point is, your device isn't fully powered off whichever path you have chosen. During boot process there are things which are powered up before the OS loads (and possibly be powered up even when there is no OS on device). There must be a circuitry in PMIC (e.g. a microcontroller in low-power mode and may be some software stack too) which is always powered up so than it can listen to your request for switching on the device when you press power button for a few seconds, or even when you connect a charger to device in powered-off state.



COMMUNICATION PROCESSOR

Also the baseband processor (BP) - which runs modem and is responsible for all communication through mobile networks e.g. call, SMS and internet - is totally isolated from Application Processor (the one we call CPU) and is not governed by Android kernel; it runs an independent RTOS. And as they say, government agencies may use it to track you even when you think your device is powered off. So it means it may possibly be (partially or fully or periodically) running when Android isn't running.






If nothing else, at least battery terminals are always live, connected to some part of motherboard which may get short when got wet. So if your device isn't water resistant and the battery doesn't have some short-circuit protection built-in, you can never be dead sure your device won't get damaged when water poured on it.


Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes