What is the role of the outer metal connector? (the one with two square holes) Does it have a potential? Is it insulated from the 4 pins? Are the 4 pins insulated from each other?
The metal shroud around USB connectors is called "shield".
The shield serves two purposes, (1) To protect from over-the-air ESD events, and (2) to shield internal high-frequency noise from being emitted out and meet emission regulations for EMI levels. These two processes have different electrical characteristics, so the treatment of shield connection must have somewhat more sophisticated handling than just grounding. It also depends whether this is a portable device, or a stationary equipment.
(1) ESD event is a high-voltage one-time discharge pulse about 50ns long. The purpose of shieled is to intercept the plasma filament, and route the discharge current (10 A-50 A) aside from the signal ground at pins of ICs. Therefore the best way is to ground the shield solidly to system ground plane and chassis.
(2) EMI: USB uses high-speed signaling, which employs internal switching frequencies of 480MHz and higher harmonics of it. Even if the external signaling is differential over a shielded bi-axial cables (which is supposed to cancel direct emissions), inner workings of digital electronics and unbalanced return currents create so-called "ground bouncing". In essence, the digital signal ground in the device is noisy, bouncing. If the shield is directly connected to this ground, the conductive braid along the entire USB cable will emit as a good antenna. Therefore, the shield should be disconnected from digital ground.
As one can see, these requirements are contradictory. The industry solution is to use a de-coupling circuit between the shield shroud and signal ground. Different manufacturers recommend slightly different solutions for this filter. Googling for something like [EMI shielding and ESD protection of computer interfaces] will give a lot of recommendations, LC, RC, etc.
My preference is to use a 0.1uF ceramic cap 0603 size, with a resistor of about 330 Ohms to provide galvanic path. The filter works on specifics of this particular size of ceramic caps. These caps have an impedance of capacitive type at frequencies up to 10-20MHz (so a 50ns pulse gets well-coupled with ground plane and dissipates in power supplies), but at frequencies above 50MHz it becomes an inductor, so if provides a good de-coupling of cable shield from the noisy digital ground.
The outer metal shield of the USB connector is part of the cable screening or shielding. The cable will have either a woven wire sheath that is connected to the metal connector parts OR the cable will have a conductive foil wrap that is intermingled with a single wire bare wire that connects to the connector shield part.
When the cable is plugged into the mating equipment the cable connector metal shield contacts with the like shield of the connector on the equipment. The shields of the equipment connectors are connected to the chassis or internal ground system of the product. One of the purposes of this shielding connection system it to keep the two attached systems at equal potential.
Most often the connection of the equipment connector shield is to the same internal circuit node as the USB GND wire. Careful design is often used to arrange things so that the shield shunts external electrical disturbances, such as electrostatic discharges (ESD), directly to the chassis in the shortest path possible to a possible earth wire connection. This shunting attempts to keep as much of the high voltage ESD out of the internal circuitry as possible where it could cause damage to the electronics.
Another purpose of the shielding is to help prevent internal RF signals in the products from being emitted out on the cable. It is often necessary to arrange the product USB connector shields a part of an EMI containment system to prevent RF leaks from going over legal limits.
The outer metal connector is the USB connector shield. It will shield the wires from EMI. Note that the shield should not serve as connecting wire, i.e. should just be grounded by one end.