As per Jodi Helmer, if your dog scratches at their ears often, shakes their head repeatedly, or has a bad smell or discharge ...
So, most likely, if your dog has ear mites, they caught the infection from another animal with whom they had been socializing ...