Necessary disclaimer: I am not a lawyer so please don't take my statements here on face value, do your own due diligence before pulling off any stunts.
When passing through customs check, the customs agents have the right to ask for your fingerprint or any other biometrics but they don't have the right to ask you to enter your password/pin-code.
So there is an option in both iPhone and Android, check for iPhone but in Android it is called Lockdown Mode
. This makes it so that your phone can only be opened with the designated pin-code or password.
What I suggest with devices having finger-print or facial unlock, use the biometric lock for daily use and keep a looong passcode.
One way to memorize a long number is to not use a custom number but to pick one of the constants from Physics/Chemistry/Mathematics. That way even if you forget the exact digits, you can just look up its value online. The security lies in no-one knowing what constant you have used. They don't even know that you are using a constant. Go for atleast 10-digit pin.
Then comes the risk of immigration agents detaining you and when you are travelling alone you don't even have the option to contact your lawyer because the agents might cut your access to your devices too.
So for this you set something that's called a "dead man's switch". The concept comes from war, here someone rigs up a switch not in the way that when they press it the bomb blasts. But in the way that if they release it, the bomb blasts. So even if someone kills them there is a much higher chance of the bomb going off.
What you have to do is, right before you enter the immigration check. Message someone you trust that you are about to pass through customs. Give them all the details as to the airport where you are, the flight by which you came, etc. Ask them to contact your lawyer if they don't hear back from you within a specified time (a couple of hours probably). Then when you are cleared of immigration just let them know that you are out of the hairy-zone.
I got the idea of this from one of CGP Grey's video over on YouTube.
Want to discuss this or any other interesting thing, hit me up on Twitter @varun_barad.