Cell-phone evidence was discovered by federal investigators that established the gunman’s ties to Al Qaeda, not only before last year’s deadly attack at Naval Air Station Pensacola, but before he arrived in the U.S.

During a press conference, FBI Director Christopher Wray said the gunman, Second Lt. Mohammed Saeed Alshamrani, was “radicalized” at least as far back as 2015.

FBI investigators said Alshamrani, had been in contact with a member of Al Qaeda who, in turn, encouraged the attacks that killed three sailors and injured eight. He was in contact up until the night before the deadly shooting.

A deputy from the Escambia County Sheriff’s Office ultimately shot and killed Alshamrani.

The communication was discovered after investigators broke through the encryption on a phone belonging to Alshamrani. Wray said he spent “years” planning the attack.

Alshamrani was a Saudi aviation student at the base when he carried out the attacks, federal officials said. In January, Barr called the December attack an “act of terrorism” and Alshamrani — a second lieutenant with the Royal Saudi Air Force — was “motivated by jihadist ideology.”

Attorney General William Barr said Alshamrani, during last year’s anniversary of the September 11, 2001 terrorist attacks, also posted a message online that “the countdown has begun” and later traveled to New York City to visit the 9/11 Memorial on Thanksgiving weekend.

Wray said the FBI obtained search warrants months ago for Alshamrani’s phone, but Apple refused to help.

“We received effectively no help from Apple,” he said. “We did it ourselves.”

Barr scolded Apple during the press conference for refusing to cooperate with the FBI investigation.

“Apple’s desire to provide privacy for its customers is understandable but not at all costs,” he said. “There’s no guarantee that we can be successful in the future or we can avoid massive delays, in this case, four months. We need American tech leaders to work with us, not against us.”