It’s totally legal for a US Customs and Border Patrol officer to ask you to unlock your phone and hand it over to them. And they can detain you indefinitely if you don’t. Even if you’re a American citizen.
I’ll never bring my phone on an international flight again. Neither should you.
Quincy Larson

It’s also legal to tell that officer at the border you refuse to unlock your phone. And technically….US Customs and Border Patrol doesn’t have any agreements with the software companies or cell service companies to access the phone in anyway. Only the owner of the phone does. It would be a clear violation of both law and agreements to allow anyone else unauthorized to gain access to a phone.