Let’s say you are an inmate at the Baltimore City Detention Center and, somehow, you were able to sneak a cellphone past the pat-down security checkpoint and cellphone-sniffing dogs. If you tried to use that phone inside the jail in the past five weeks, state officials say, your call wouldn’t have gone through and you would have heard this message instead: “The cellular device you are attempting to use has been identified as contraband and is illegal to possess under the Maryland statute 9-417.”

After years of trying to find a legal way to keep the jail’s inmates from making illegal calls — especially those to keep drug trades running, organize gang activity or order violence — state officials are confident that they have largely cut off inmates’ mobile connections to the outside world. The new $5.4 million “Managed Access” system has been installed in two detention centers, and officials hope to soon install it elsewhere.

“Not only are we seeking to improve security here in the prisons, but we are also seeking to improve security throughout our state,” said Maryland Gov. Martin O’Malley (D) at a press conference at the Baltimore jail Friday morning. “These are pretty deadly instruments for gangs to use to intimidate witnesses on the outside, to order hits on rival gangs.”

The need to crackdown on contraband cellphones has intensified with exposure of the workings of the Black Guerilla Family, a prison gang that’s also known as BGF. The gang blossomed in Maryland’s correctional facilities around 2008, thanks in part to the “proliferation of cell phones inside of prisons,” according to a November indictment.

The gang collected dues, along with a tax on drugs and other contraband that was smuggled into the jail, all of which was overseen by a “Minister of Finance,” according to the indictment. A gang leader, Tavon White, impregnated four female guards — one was impregnated twice — during a three-year stay, according to the indictment. Two guards had “Tavon” tattooed on their bodies.

The indictment states that BGF members and associates engaged in criminal activities “including, but not limited to, trafficking in controlled substances, bribery, extortion, money laundering, obstruction of justice, assault, robbery, murder and witness retaliation.”

“The availability of contraband cell phones was the crucial device to link and coordinate all BGF criminal activity inside and outside the prison facilities,” the indictment states. In at least one instance, a corrections officer warned a BGF leader about an upcoming search for such phones.

Maryland has been trying to crack down on contraband cellphones for years. The state invested in more advanced security technology and dogs that can sniff out phones, along with increasing the penalties for getting caught with a phone and more vigorously prosecuting offenders. Officials are confident that those changes have already driven down the number of cellphones in Maryland jails.

It would have been cheaper and easier to just jam up cell phone reception in the jail, O’Malley said, but the Federal Communications Commission will not allow that. Years ago, Maryland asked for permission and was turned down.

“FCC put us through batteries of tests and examinations, sent some guy out here in a van from Colorado to set up equipment all over the place, waltzed us around, spent a lot of time and told us: ‘No, we’re not allowed to block cell phones,’ ” O’Malley said.

Maryland appealed to Congress to change the federal law but that approach also failed, he said. O’Malley said the new “Managed Access” system, created by Maryland-based Tecore Networks, works within the law.

It sets up a “frequency umbrella” around the jail and monitors all cellphone calls coming in and going out. It allows calls made on authorized, registered phones and calls made outside the jail walls. It also allows through all calls to 911. But it prevents any calls from unauthorized phones.

It has taken Tecore and corrections officials weeks of testing to fine-tune system to identify any hidden pockets where phones would somehow work, while ensuring that people walking on the sidewalk outside the jail walls wouldn’t have their calls blocked.

The Baltimore jail’s unique and sprawling architecture provided a series of challenges. The oldest part of the jail, constructed in the 1850s, looks like a blackened stone castle. It has dozens of fanciful torrents and narrow arched windows covered with bars, rising up from behind more modern yellow-brick buildings and reels of barbed wire. O’Malley described its style as ”early American Alcatraz architecture” and pointed out that it’s one of the largest jails run by a state.

O’Malley announced the new system at a news conference inside the jail Friday morning. As reporters arrived, they were given the full BCDC treatment — a patdown, a walk (or two) through a metal detector and close inspection of their bags, coat pockets and inner compartments of wallets.

Cellphones were strictly forbidden, and things like makeup compacts were taken away, as the glass could be broken and used as a weapon. Even a spokeswoman for the Department of Public Safety and Correctional Services had her pile of folders holding press releases carefully scrutinized.

After all of that, the media horde didn’t get to hang out with any inmates, let alone see one. The focal point of the news conference, held in a spartan visitors lounge lined with metal lockers, was a testing of the new system. Reporters didn’t have their phones to try the system themselves, so a corrections official hooked his iPhone up to the speaker system and tried calling his wife. Nothing happened. He tried calling a coworker. Again, nothing.

That’s when one of O’Malley’s communications staffers — they got to keep their cellphones — tried to call her voicemail and got the recording. She put it on speakerphone and replayed it several times.

O’Malley stood and listened. His political trajectory started here in Baltimore, where he was first an assistant state’s attorney and later served on the Baltimore City Council and was elected mayor. The jail corruption scandal has been an embarrassment to the tough-on-crime governor, who is thinking about running for president in 2016.

O’Malley said Friday that when he took on the “sacred trust” of being governor seven years ago, the two most ”challenged” departments were juvenile services and corrections, both of which have seen improvement.

Toward the end of the news conference, a reporter revisited the idea that cleaning up the jails will prevent crime elsewhere and said that the plan doesn’t seem to be working.

“Is that depressing for you,” the reporter asked, “that you clean up the jails and violent crimes spikes outside?”

O’Malley said that although Baltimore has seen an “uptick” in homicides in the past year, Prince George’s County has seen a 40 percent reduction in homicides over three years and the rate of violent crime across the state is at a 30-year low.

“Every county is important, every city is important,” he said, but then added: “You cannot gloss over the loss of life, especially here in Baltimore City, which has the greatest potential for saving lives.”