“Before government agents should be able to go rifling through that trove of private data, they should have a very good reason based on individualized suspicion of illegal activity,” said Nathan Freed Wessler, a staff attorney for the American Civil Liberties Union. “People’s most private details of their lives will be made bare without justification.”

Image Haisam Elsharkawi

The policies that give border agents the latitude to search or seize devices were used under the Obama administration, to much criticism. There’s no available data to suggest that they are happening more under the administration of President Trump, though activists say they have anecdotally heard of more reports.

A customs agency spokesman said the agency could not comment on individual cases. But he said agents had inspected 4,444 cellphones and 320 other electronic devices in 2015, amounting to 0.0012 percent of the 383 million arrivals. In fiscal year 2016, the searches of electronic devices rose to 23,000.

Can agents force you to unlock your phone or laptop?

No. But they can ask you to comply voluntarily and make the experience rather uncomfortable if you resist. Travelers must decide how much trouble they’re willing to put up with.

You may end up losing your device, since agents could seize the device for weeks before it is returned. They could also copy the data. (That data must be destroyed “as expeditiously as possible” if it is not valuable, according to Homeland Security policy.)

Travelers have reported that they’ve been detained for hours and questioned aggressively. Mr. Elsharkawi, whose trip included a pilgrimage to Mecca after an 18-hour layover in Istanbul, said his payment for his Turkish Airlines flight was not refunded after he missed it.

Travelers who are not citizens could have further problems, especially if they’re flying into the United States. While citizens are guaranteed re-entry, foreign nationals could be denied entry, and the law isn’t clear on permanent residents, said Sophia Cope, a staff lawyer for the Electronic Frontier Foundation, a nonprofit organization that defends civil liberties in the digital age.