It is not ever okay to walk up to a strange dog and pet it because some dogs will attack for no reason. I have seen a dog attack a stranger when the person came too close even if the dog was smiling and wagging its tail.
Also you do not know if a strange dog has rabies. Rabies is a deadly disease easily passed from animals to humans.
That said, I assume you know the dog is a police dog because it is being handled by a uniformed police officer. In that case, ask the officer if you may pet it. Don’t be surprised if the answer is a firm “No.”
Normally it is not okay to pet a dog while it is working.