Does not work that way, it’s not just an us thing. all boarder crossings are regulated that way. The laws are written that they can search you, your stuff and electronics. It’s because drug smugglers, people that commit visa fraud and over stay their visits, human trafficking, they will check for any signs of illicit activity like messages in your phone on drug or prostitution deals. They do random stops all the time, not just because you are suspicious. I mean if you refuse they will just apply for a warrant from a judge and hold you or confiscate your device.