Defendant Adan Rubio appeals his conviction by plea to possession of a controlled substance with a firearm ( Health & Saf. Code, § 12305 ), a plea entered after the trial court denied his motion to suppress the evidence found in his apartment ( Pen. Code, § 1538.5 ).1 Police had forcefully entered the apartment after responding to the scene where 11 gunshots had just been fired and officers were concerned that a shooting victim or suspect might be inside. We agree with the magistrate and the lower court that under the circumstances the warrantless entry was justified under the so-called community caretaking exception to the Fourth Amendment warrant requirement, and that the suppression motion was properly denied. We shall therefore affirm.
FACTUAL AND PROCEDURAL BACKGROUND
On October 19, 2016, at approximately 10:40 p.m., East Palo Alto Police Department Sergeant Clint Simmont received an alert on his "ShotSpotter" application that shots had been fired near 2400 Gonzaga Street. ShotSpotter triangulates the location of gunfire via microphones placed throughout the city. ShotSpotter notified Sergeant Simmont of two separate bursts of gunfire. First came five rounds from the edge of the garage driveway area of 2400 Gonzaga, then one minute later came six rounds at "the edge of the driveway, near the sidewalk." Sergeant Simmont testified that 2400 Gonzaga is located in "Da Vill," known as a high-crime neighborhood. He further testified that he had responded to more murders within a block of that location than anywhere else in East Palo Alto.
*33Sergeant Simmont and a team of four other officers arrived near the location of the shots and parked 60 to 70 feet from the edge of the driveway. Officers Andrea Dion and Rock Stilwell spoke with persons nearby and asked if they had heard gunfire. Two individuals pointed towards a boat in the driveway of 2400 Gonzaga and stated that they saw flashes coming from the other side of the boat. As the officers approached the house with their guns out, they found a spent shell casing on the ground at the top of the driveway near the garage. Sergeant Simmont believed the casing was a .45 caliber round and may have come from a semiautomatic weapon.
Approximately one minute after the officers found the spent shell casing, a man identified as Joshua Bazan walked through the wooden gate of a fence that separated the front and back yards of the house. Sergeant Simmont recognized Bazan from prior contacts and testified that Bazan frequently drinks and yells at police. Sergeant Simmont also testified that Bazan did not reside at 2400 Gonzaga. As he came through the gate, Bazan began yelling obscenities at the officers and assumed a combative position. The officers arrested Bazan and placed him in a patrol car.
After Bazan's arrest, Officer Dion located two additional spent casings behind the open gate that Bazan had passed through. Sergeant Simmont concluded the gunfire had come from near the gate, although he could not testify from which side. Sergeant Simmont testified that he was "investigating whether or not we had a victim or a shooter [who] was hiding out."
Sergeant Simmont pounded loudly on a door attached to the side of the garage and announced police presence four or five times. No one responded, but Sergeant Simmont heard what sounded like someone inside the garage pushing items against the door, and he noticed that the door appeared to be flexing. Sergeant Simmont believed someone was attempting to barricade the door. As Sergeant Simmont was knocking on the door, a man later identified as Sergio Castillo came to a window next to the garage. Sergeant Simmont ordered Castillo to open the door. Castillo indicated that the door was not the door to the garage, but instead was a door to a separate room.
Sergeant Simmont, Officer Lee, and Officer Weigand spoke with several persons at the front door to the residence. When asked whether anyone in the house had been shot, defendant's father, Francisco Rubio Sr., stated he did not know. Sergeant Simmont testified that he asked Francisco Sr. for permission to search the house, which Francisco Sr. granted. Francisco Sr. testified that the officers never asked him for permission to enter the house.
Once inside the house, officers asked Francisco Sr. who was inside the garage, and he responded that his son was. Sergeant Simmont then asked for permission to search the garage, and Francisco Sr. responded, "Sure." Attempting to open the door from the house to the garage, Francisco Sr. found that it was locked, but told the officers he would get the key.
As Francisco Sr. was getting the key, defendant emerged from the garage, opening the door "just enough to slide his body out." Defendant closed the door, which automatically locked behind him, and approached the officers with his hands in his pockets, yelling for them to shoot him. Sergeant Simmont repeatedly ordered defendant to show his hands. Defendant eventually took his hands out of his pockets and, as he did so, threw a key ring into the kitchen sink. Officers arrested defendant and placed him in a patrol car.
*34The officers retrieved the key defendant had thrown into the sink and attempted to use it to open the door to the garage. When defendant's key did not work, Sergeant Simmont and Officer Stilwell kicked the door open and entered the garage. Sergeant Simmont testified that he was uncertain what was on the other side of the door and that he had no reason to believe anyone had been shot, but he "didn't have anything to rule that out, either."
Upon entering the garage, Sergeant Simmont observed that the garage was a converted apartment. The officers did not find anyone inside the apartment, but did observe "an explosive device on a shelf." The officers also found and collected an operable .45 semiautomatic Smith & Wesson pistol on the shelf in an open closet. Sergeant Simmont noticed that the door he had knocked on earlier from the outside was barricaded by furniture.
The officers cleared the house of all occupants to secure the scene. At around 5:18 a.m., a search warrant was obtained. The officers reentered the residence and executed the warrant. The officers found an operable .357 Smith & Wesson handgun, twenty .40-caliber bullets, 87 live .357-caliber bullets, a body armor vest, six spent .357 Smith & Wesson shell casings, and a plastic twist-off bindle in a shot glass with a clear, rock-like substance. Sergeant Simmont located surveillance equipment with a view of the driveway and a video that showed three people walking down the driveway. Defendant is seen pulling out a revolver and firing six shots into the air. Defendant and two other individuals, Bazan and possibly defendant's brother, are then seen running back through the gate next to the house.
Following the filing of a five-count felony complaint, defendant filed a motion to suppress evidence. At a hearing on the motion to suppress, the prosecution argued that the warrantless entry into defendant's garage was justified under multiple theories: community caretaking, emergency aid, exigent circumstances, and consent. Citing to People v. Ray (1999) 21 Cal.4th 464, 88 Cal.Rptr.2d 1, 981 P.2d 928, the magistrate ruled that the search satisfied the community caretaking exception, but noted that it was "a very close case." The court denied the motion to suppress.
The San Mateo County District Attorney then filed a six-count felony information, charging defendant with discharge of a firearm with gross negligence (§ 246.3, subd. (a) (count one)), possession of a controlled substance with a firearm ( Health & Saf. Code, § 11370.1, subd. (a) (count two)), unlawful possession of a firearm by a felon (§ 29800, subd. (a)(1) (counts three and four)), unlawful possession of ammunition (§ 30305, subd. (a)(1) (count five)), and possession of an explosive ( Health & Saf. Code, § 12305 (count six)), with a special allegation that defendant is ineligible for probation because of two prior offenses (§ 1203, subd. (e)(4)).
Defendant filed a motion to set aside the information pursuant to section 995, alleging that the evidence presented at the preliminary hearing should have been suppressed pursuant to section 1538.5. Defendant also renewed the original motion to suppress evidence. Citing the emergency aid doctrine of the community caretaking exception, the trial court denied defendant's motion to set aside the information and denied the motion to suppress.
Following this second denial of his motion to suppress, defendant entered a plea of no contest to violating Health and Safety Code section 11370.1, as charged in count two, and admitted the special allegation pursuant to section 1203, subdivision (e)(4). The trial court sentenced him to three years of supervised probation, subject *35to conditions including nine months in the county jail or a residential substance abuse treatment program. Defendant filed a timely notice of appeal.
DISCUSSION
" '[I]t is a "basic principle of Fourth Amendment law" that searches and seizures inside a home without a warrant are presumptively unreasonable.' " ( People v. Romeo (2015) 240 Cal.App.4th 931, 939, 193 Cal.Rptr.3d 96, quoting Payton v. New York (1980) 445 U.S. 573, 585-586, 100 S.Ct. 1371, 63 L.Ed.2d 639.) " 'Nevertheless, because the ultimate touchstone of the Fourth Amendment is "reasonableness," the warrant requirement is subject to certain exceptions.' " ( People v. Troyer (2011) 51 Cal.4th 599, 602, 120 Cal.Rptr.3d 770, 246 P.3d 901.) "[W]arrantless searches are allowed when the circumstances make it reasonable, within the meaning of the Fourth Amendment, to dispense with the warrant requirement." ( Kentucky v. King (2011) 563 U.S. 452, 462, 131 S.Ct. 1849, 179 L.Ed.2d 865.) " '[T]he calculus of reasonableness must embody allowance for the fact that police officers are often forced to make split-second judgments-in circumstances that are tense, uncertain, and rapidly evolving.' " ( Id. at p. 466, 131 S.Ct. 1849.)
Defendant argues that the officers' actions here were not justified by any exception to the Fourth Amendment warrant requirement. "On appeal, a reviewing court must affirm the trial court's determinations of the factual questions if they are supported by substantial evidence, but must take the ultimate responsibility for deciding the legal question according to its independent judgment." ( People v. Duncan (1986) 42 Cal.3d 91, 97, 227 Cal.Rptr. 654, 720 P.2d 2.)
In denying defendant's motion to suppress, the magistrate relied on People v. Ray, supra , 21 Cal.4th 464, 88 Cal.Rptr.2d 1, 981 P.2d 928.2 In Ray , officers responded to a report that the door to an apartment had been open all day, and that the inside of the home was in "shambles." ( Id. at p. 468, 88 Cal.Rptr.2d 1, 981 P.2d 928.) Officers arrived on the scene and concluded that there was a " '95 percent' likelihood they had encountered a burglary or similar situation." ( Ibid. ) The officers knocked several times and announced their presence, but received no response. Concerned that they might find people inside either in need of aid or burglarizing the home, the officers entered the home to conduct a security check.
Six members of our Supreme Court agreed that the entry was proper but disagreed among themselves as to precisely which exception to the warrant requirement applied. Three justices felt that the relevant exception was "exigent circumstances," defined " 'to include "an emergency situation requiring swift action to prevent imminent danger to life or serious damage to property...." [Citation.] The action must be "prompted by the motive of preserving life or property and [must] reasonably appear[ ] to the actor to be necessary for that purpose." ' " ( People v. Ray, supra , 21 Cal.4th at p. 481, 88 Cal.Rptr.2d 1, 981 P.2d 928 (conc. opn. of George, C.J.).) The lead opinion of three other justices, viewing the emergency aid doctrine as "a subcategory of the community caretaking exception, a distinctly different principle of Fourth Amendment jurisprudence" ( id. at p. 471, 88 Cal.Rptr.2d 1, 981 P.2d 928 (lead opn. of Brown, J.)), concluded *36that the broader community caretaker exception applied.
According to the lead opinion, " 'the community caretaker exception is only invoked when the police are not engaged in crime-solving activities.' " ( People v. Ray, supra , 21 Cal.4th at p. 471, 88 Cal.Rptr.2d 1, 981 P.2d 928.) "Under the community caretaking exception, circumstances short of a perceived emergency may justify a warrantless entry." ( Id. at p. 473, 88 Cal.Rptr.2d 1, 981 P.2d 928.) " 'Community caretaking activities are varied and are performed for different reasons.' [Citation.] Each variant must be assessed according to its own rationale on a case-by-case basis. 'Although the underlying command of the Fourth Amendment is always that searches and seizures be reasonable, what is reasonable depends on the context within which a search takes place.' " ( Id. at p. 472, 88 Cal.Rptr.2d 1, 981 P.2d 928.)
Given the generality of this standard, it is hardly surprising that courts in many cases with diverse factual situations have upheld and rejected application of the community caretaking exception. One element common to all of these cases is that the law enforcement officers must not have used the caretaking exception as a pretext for other law enforcement activities. " '[T]he defining characteristic of community caretaking functions is that they are totally unrelated to the criminal investigation duties of the police.' " ( People v. Ray, supra , 21 Cal.4th at p. 471, 88 Cal.Rptr.2d 1, 981 P.2d 928.) If an entry into a home is justified by the caretaking exception, there is no bar to the seizure of contraband that is readily observed upon entry into the home. ( Id. at pp. 471-472, 88 Cal.Rptr.2d 1, 981 P.2d 928 ; People v. Stamper, supra , 106 Cal.App.3d at p. 305, 164 Cal.Rptr. 861.) In the present case, there is no suggestion that the officers who entered defendant's home were looking for contraband or doing anything other than attempting to ensure that inside there was not an injured victim or someone with a weapon who was then threatening injury to others. ( Ray, supra , at p. 471, 88 Cal.Rptr.2d 1, 981 P.2d 928.)
While the facts in none of the cases are precisely the same, several support application of the community caretaking exception here. In Ray itself, the officers were aware only that a door to the residence had been open all day and that through it could be seen that the home was in shambles, and no one responded to their repeated knocks. Their concern justified entry to conduct a security check " 'to see if anyone inside might be injured, disabled, or unable to obtain help' and to determine whether a burglary had been committed or was in progress." ( People v. Ray, supra , 21 Cal.4th at p. 468, 88 Cal.Rptr.2d 1, 981 P.2d 928.) In Stamper , which the trial court here found more persuasive, police responded to gunshots fired within a home, heard what sounded like a shotgun being chambered, were told by the two residents who emerged that no one else was inside, but nonetheless entered the residence to " 'check for any victims due to the emergency doctrine.' " ( People v. Stamper, supra , 106 Cal.App.3d at p. 304, 164 Cal.Rptr. 861.) The Court of Appeal observed, "Guns are not ordinarily fired, or prepared for firing, within a home unless aimed at a living target. The officers reasonably concluded that an injured person in need of prompt attention might be within the house. In such situations the Constitution does not require the delays of further investigation or warrant applications." ( Id. at p. 306, 164 Cal.Rptr. 861, italics in original.)
Several decisions of the United States Supreme Court confirm this approach. In *37Brigham City v. Stuart (2006) 547 U.S. 398, 126 S.Ct. 1943, 164 L.Ed.2d 650, police officers responded to a loud party at a residence where they observed through a window four adults attempting to restrain a juvenile who broke free and struck one of the adults. The officers' uninvited entry into the house was deemed unjustified by the Utah Supreme Court, but the United States Supreme Court held "the officers' entry was plainly reasonable under the circumstances.... [¶] The role of a peace officer includes preventing violence and restoring order, not simply rendering first aid to casualties." ( Id. at p. 406, 126 S.Ct. 1943.) This decision was relied on in Michigan v. Fisher (2009) 558 U.S. 45, 130 S.Ct. 546, 175 L.Ed.2d 410 (per curiam), where officers entered a home without consent or a warrant after observing signs of an altercation and a person inside the home "screaming and throwing things," refusing to answer the officers' knocks, and responding to inquiries whether he needed medical attention because of a cut on his hand by demanding "with accompanying profanity, that the officers go to get a search warrant." ( Id. at p. 46, 130 S.Ct. 546.) In reversing the decision of the Michigan courts finding no emergency, the higher court held "[i]t was error for the Michigan Court of Appeals to replace that objective inquiry into appearances with its hindsight determination that there was in fact no emergency. It does not meet the needs of law enforcement or the demands of public safety to require officers to walk away from a situation like the one they encountered here." ( Id. at p. 49, 130 S.Ct. 546.) Quoting from Brigham City that "[t]he role of a peace officer includes preventing violence and restoring order," the court held that "[i]t sufficed to invoke the emergency aid exception that it was reasonable to believe that Fisher hurt himself (albeit nonfatally) and needed treatment that in his rage he was unable to provide, or that Fisher was about to hurt, or had already hurt, someone else." ( 558 U.S. at p. 49, 130 S.Ct. 546.)
In Ryburn v. Huff (2012) 565 U.S. 469, 132 S.Ct. 987, 181 L.Ed.2d 966 (per curiam), a case applying 42 United States Code section 1983, police officers pursuing rumors that a high school student absent from school for two days had threatened to "shoot up" the school, sought to interview the student at his home. ( Ryburn , at p. 470, 132 S.Ct. 987.) Their knocking at the door of the home and phone calls to the home phone initially went unanswered. When the student's mother was contacted on her cell phone and acknowledged that she and the student were inside the home, and was told that the officers wished to speak with her, she "hung up the phone." ( Id. at p. 471, 132 S.Ct. 987.) After one or two minutes, the two came to the front steps of the home and refused the officers permission to speak with them inside the house. ( Ibid. ) When asked if there were any guns in the house, the mother "responded by 'immediately turn[ing] around and [running] into the house' " and officers without permission followed her into the house. In reversing a split decision of the Ninth Circuit Court of Appeals holding that those officers were not entitled to qualified immunity, the court upheld the district court's conclusion that the mother's "odd behavior, combined with the information the officers gathered at the school, could have led reasonable officers to believe 'that there could be weapons inside the house, and that family members or the officers themselves were in danger.' " ( Id. at p. 472, 132 S.Ct. 987.) Referring to Brigham City and other decisions, the court held that "[a] reasonable police officer could read these decisions to mean that the Fourth Amendment permits an officer to enter a residence if the officer has a reasonable basis for concluding that there is an imminent threat of violence."
*38( Ryburn , at p. 474, 132 S.Ct. 987.) Rejecting the significance of the fact that when the mother fled into the house she "was under no legal obligation to continue her conversation with the police," the court observed, "it should go without saying ... that there are many circumstances in which lawful contact may portend imminent violence." ( Id. at p. 476, 132 S.Ct. 987.) And further, "it is a matter of common sense that a combination of events each of which is mundane when viewed in isolation may paint an alarming picture." ( Id. at pp. 476-477, 132 S.Ct. 987.) Most importantly, the court criticized the circuit court for "not heed[ing] the District Court's wise admonition that judges should be cautious about second-guessing a police officer's assessment, made on the scene, of the danger presented by a particular situation. With the benefit of hindsight and calm deliberation, the panel majority concluded that it was unreasonable for petitioners to fear that violence was imminent. But we have instructed that reasonableness 'must be judged from the perspective of a reasonable officer on the scene, rather than with the 20/20 vision of hindsight' and that '[t]he calculus of reasonableness must embody allowance for the fact that police officers are often forced to make split-second judgments-in circumstances that are tense, uncertain and rapidly evolving.' [Citation.] Judged from the proper perspective of a reasonable officer forced to make a split-second decision in response to a rapidly unfolding chain of events that culminated with [the mother] turning and running into the house after refusing to answer a question about guns, petitioners' belief that entry was necessary to avoid injury to themselves and others was eminently reasonable." ( Id. at p. 477, 132 S.Ct. 987.)
Although in the present case the officers were not aware of a specific, known individual who might be in danger or might pose an imminent threat to others, as in some of these cases, the California Supreme Court's decisions in both Ray and Stamper establish that if the circumstances suggest that such a person may be inside a dwelling, police may reasonably enter to determine whether in fact such a person is present.
Under the approach required by these authorities, the officers' forced entry into defendant's garage apartment in the present case was reasonable. As the prosecutor and the Attorney General have summarized the situation, "1) there were shots fired from multiple locations in the driveway; 2) a verbally aggressive person exited the gate of the residence and took a fighting stance; 3) Sergeant Simmont recognized that the person did not live at the residence; 4) shell casings were observed outside the residence; 5) the shell casings appeared to lead to a door going into the garage; 6) when he knocked and announced his presence, Sergeant Simmont heard movement inside that sounded like someone barricading the door; 7) the sounds led officers to believe someone may have been held captive on the other side of the door; 8) [defendant] was acting erratically and refused to show his hands; and 9) the neighborhood was known as a high crime area."
As the trial court put these facts together, "what the defense is asking is for this court to second guess the actions of an officer in the field who knows that shots have been fired, sees physical evidence of the location where the firearm was discharged, hears movement within the home that he seeks entry to that is consistent with a reasonable fear that a victim of a shooting may be being secreted within the residence based on his prior experience, further that that activity to barricade the door was upon his request to enter as opposed to a verbal response saying, no, *39you can't come in. There's physical activity suggesting an attempt to barricade the door. And then the appearance of Mr. Bazan ... and his oppositional behavior in a manner where he had no right of possession over the premises ... heightened the exigent moment with regard to the decision making an officer must make in the field where firearms are being or have very recently been discharged. Accordingly, ... Sergeant Simmont's actions fall within the emergency [aid] doctrine [of the] community caretaking exception to the Fourth Amendment warrant requirement."
We agree with this analysis. In our view, the community caretaker exception applies. We add, as the Court of Appeal did in People v. Stamper, supra , 106 Cal.App.3d at page 306, 164 Cal.Rptr. 861 : "a failure of the police to investigate as they did, 'would have constituted a failure to properly discharge [their] duties as [officers] of the law.' "
DISPOSITION
The judgment is affirmed.
I CONCUR:
BROWN, J.
Unless otherwise specified, all further statutory references are to the Penal Code.
We review the propriety of the magistrate's decision, not that of the superior court that affirmed the magistrate's decision. (People v. Thompson (1990) 221 Cal.App.3d 923, 940, 270 Cal.Rptr. 863 ; People v. Stamper (1980) 106 Cal.App.3d 301, 304, 164 Cal.Rptr. 861.)