The US Supreme Court recently ruled in US v. Riley and US v. Wurie that law enforcement must still apply for a warrant before searching a cell phone confiscated following an arrest. The scope of the well-established search "incident to arrest" does not extend to cell phones under most circumstances. The fact that an arrestee has diminished privacy interests does not mean that the Fourth Amendment falls out of the picture entirely. Not every search "is acceptable solely because a person is in custody."...to the contrary, when "privacy-related concerns are weighty enough" a "search may require a warrant, notwithstanding the diminished expectations of privacy of the arrestee."
Proponents of applying an exception to the warrant requirement argued that ANY item found on the arrestee, including the contents of a cell phone, should be subject to a warrantless search incident to arrest. Opponents to the "search incident to arrest" exception argued that the only real threat cell phones pose to officer safety arises where the cell phone has been fashioned into a weapon or a weapon has been fashioned to look like a cell phone. Opponents argued that a cursory search of the tangible cell phone would determine if it presents a real safety threat and that a search of the digital contents of the cell phone is not justified.
Also persuasive to the Riley Court was the fact that much of the data viewed on a cell phone may not be stored on the cell phone, and it is often not clear to the person reading the data where the data is being stored. Because proponents acknowledged that data accessible through a cell phone but stored elsewhere would not be subject to a search under the search incident to arrest exception, the Court pointed out that allowing cell phone data to be searched under that exception would only further complicate matters.
In the end, the smartest way to avoid illegal searches of your cell phone is to utilize a passcode or finger print security measure (now available on the newer phones) in order to prevent the unauthorized (and illegal in some cases) access to your phone. You certainly don't have to share your code with law enforcement prior to speaking to your lawyer. Invoking your right to counsel early in the confrontation will help you avoid an illegal search of your phone. At the very least, your attorney can advise you whether to surrender your pass code at the scene.