Android 7.1+ Has "Panic Detection"

If you've used a smartphone for more than a week, you've no doubt experienced applications that freeze or go crazy in some other way. Typically a user presses the screen fractically to either stop the application or minimize it. Now, Google is enabling a "Panic Detection" that will detect frantic button presses on the screen and device and will close the application and return you to the home screen. If applications hang, it can be very frustrating trying to get your phone back. This is a great step in the right direction.

Quite simply, if a rogue applications attempts to hijack the user’s screen and prevent the user from leaving (perhaps by implementing an Accessibility Service to intercept all key events), Android will itself override the application to bring back the home screen. The user can then presumably uninstall the malicious application from the launcher.

Source: XDA-Developers