The gunman who killed 26 people at a small-town Texas church was treated at a mental health center in New Mexico and briefly escaped in 2012, according to a police report.

Devin Patrick Kelley was also caught trying to bring guns onto Holloman Air Force Base in New Mexico when he was stationed there, according to an El Paso police report obtained by several media outlets.

Kelley, who was 21 at the time, had made death threats against superior officers, the report said.

He was committed to a mental health facility in Santa Teresa, New Mexico, but at some point escaped and was later found by police at a bus station in downtown El Paso in June 2012.

Meanwhile at the First Baptist Church in tiny Sutherland Springs, investigators continued analyzing a gruesome crime scene and tried to gain access to the shooter's cellphone, a longstanding challenge for the FBI in thousands of other cases.

Authorities aimed to conclude the crime-scene investigation at the church by Wednesday evening. Investigators have no reason to believe anyone conspired with Kelley, who acted alone, said Texas Department of Public Safety Regional Director Freeman Martin.

Martin repeated earlier statements that the shooting appeared to stem from a domestic dispute involving Kelley and his mother-in-law, who sometimes attended services at the church but was not present on Sunday.

"We don't know what he was thinking or what was in his mind," Martin said. "There was conflict. He was upset with the mother in law."

The gunman's phone was flown to an FBI lab for analysis, but agents have yet to access it, said Christopher Combs, who is in charge of the agency's San Antonio division.

The inability to access the shooter's phone highlights a longstanding frustration of the FBI, which said it has been unable to retrieve data from half the mobile devices it tried to access in less than a year.

Director Christopher Wray said last month that in the first 11 months of the fiscal year, agents were unable to access the content inside more than 6,900 mobile devices, an issue he said stymies investigations.

The FBI and other law enforcement officials have long complained about being unable to unlock and recover evidence from cellphones and other devices seized from suspects even if they have a warrant. Technology companies have refused to help, insisting they must protect customers' digital privacy.

The long-simmering debate was on display in 2016, when the Justice Department tried to force Apple to unlock an encrypted cellphone used by a gunman in a terrorist attack in San Bernardino, California. The department eventually relented after the FBI said it paid an unidentified vendor who provided a tool to unlock the phone and no longer needed Apple's assistance, avoiding a court showdown.

The Justice Department under President Donald Trump has suggested it will be aggressive in seeking access to encrypted information from technology companies. But in a recent speech, Deputy Attorney General Rod Rosenstein stopped short of saying exactly what action it might take.

Kelley had a history of domestic violence that spanned years before the attack and was able buy weapons because the Air Force did not submit his criminal history from his time in the military to the FBI, as required by military rules.

If Kelley's past offenses had been properly shared, they would have prevented him from buying a gun, the Air Force acknowledged Monday.

Investigators also revealed that Kelley had sent threatening text messages to his mother-in-law, a member of the church, before the attack, and that sheriff's deputies had responded to a domestic violence call in 2014 at his home involving a girlfriend who became his second wife.

Later that year, he was formally ousted from the Air Force for a 2012 assault on his ex-wife in which he choked her and struck her son hard enough to fracture his skull.

At a news conference in South Korea, Trump was asked if he would support "extreme vetting" for gun purchases in the same way he has called for "extreme vetting" for people entering the country. Trump responded by saying stricter gun control measures might have led to more deaths in the shooting because a bystander who shot at the gunman would not have been armed.

"If he didn't have a gun, instead of having 26 dead, you would have had hundreds more dead," Trump said.

Investigators collected at least 15 empty magazines that held 30 rounds each at the scene, suggesting the assailant fired at least 450 rounds. About 20 people were wounded.

Based on evidence at the scene, investigators believe Kelley died of a self-inflicted gunshot wound after he was chased by bystanders, one of whom was armed, and crashed his car.

While in the military, Kelley served in logistics readiness at Holloman Air Force Base in New Mexico from 2010 until his 2014 discharge, Air Force spokeswoman Ann Stefanek said.

He was discharged for the assault involving his previous wife and her child and had served a year of confinement after a court-martial. Under Pentagon rules, information about convictions of military personnel for crimes such as assault should be submitted to the FBI's Criminal Justice Investigation Services Division.

Stefanek said the service is launching a review of its handling of the case and taking a comprehensive look at its databases to ensure other cases have been reported correctly.

A few months before he received the bad-conduct discharge, sheriff's deputies went to his home to check out the domestic violence complaint involving him and his then-girlfriend. People in the house said there was no problem, and no arrests were made. Kelley married the girlfriend two months later.

Kelley lived in New Braunfels, about 35 miles (55 kilometers) north of the church, and had recently started a job as an unarmed security guard at a nearby resort.

___

Weber reported from New Braunfels. Associated Press writers Sadie Gurman in Washington, John Mone in Sutherland Springs, Nomaan Merchant in Houston and Diana Heidgerd in Dallas also contributed to this report.

___

Sign up for the AP's weekly newsletter showcasing our best reporting from the Midwest and Texas: http://apne.ws/2u1RMfv .