They can do it at the border or within 100 miles of it
Also, depending on how you handle your opsec with the phone, they can do it during a detention too if they trick you into opening it via pass code or force you to open with your ugly face or finger.