There are free and open source apps for Android that automatically lock the device when the accelerometer detects rapid acceleration, which is a simple detection method. For example, Private Lock is on F-Droid:
- Private Lock (source): https://github.com/wesaphzt/privatelock
- Private Lock (F-Droid): https://f-droid.org/en/packages/com.wesaphzt.privatelock/