There are ways that police officers identify themselves, and challange armed persons who could be another cop letting him know he's in danger of being shot. It's a simple phrase of three words. I wont divulge it here. Not that I believe any of you would abuse it, but this is an open forum.
I have personally experienced this situation, and have seen off duty/plain clothed officers mistakenly shot.
In one case a black officer, while off duty was effecting an arrest for robbery. Subduing an armed black perpetrator. The Officer was armed with a nickle plated revolver. At the time the standard regulation revolvers were blue steel guns for both service as well as off duty. A team of officers in a sector car responded to the robbery hearing a description of a male black armed with a gun. When they arrived they saw a male black with a non regulation gun. When they challanged him he turned to ID himself, and they fired killing the officer.
This incident caused major changes within the department reguarding officer identification. This was in a city with three major police departments, and three or four minor ones. All wearing similar uniforms, carrying the same firearms. But on different radio frequencies.
The sloution was for all officers of all departments to have with them a particular item of clothing. This artical of clothing was issued to all plain clothed officers in a set of five different colors. Every morning there would be a teletype or computer message sent to every police command in all departments issuing a color of the day. Plainclothed officers would the wear the proper color of that day identifying them as police. Uniformed officers would be told the color of the day at roll call. This worked pretty good.
In addition to the above changes a standard police challange was issued to all police oficers of all commands Those three words. So that if a plain clothed officer is displaying his firearm while effecting an arrest he would have his color of the day on, and if he heard the proper challange he knew there were uniformed officers on the scene. Also the department became very strict with the carrying of non regulation weapons. There was also a range cycle every two years with dedicated training on identifying officers under difficult conditions, and responding officers tactics.
The incidents of friendly fire became almost non existant. It still happened but is very very rare.
Well thats how one department dealt with it.