All of these aforementioned actions were taken as a means to fight terrorism.
For example, the Patriot Act allowed the federal government to go through phone records of individuals who may be suspected of terrorist activities. Along with this, it gave the federal government more power to listen in on private conversations and more flexibility in detaining people who might have made an attack on American soil.
The Department of Homeland Security has a very similar role, as this agencies entire mission is to keep America safe from possible attacks. This agency works relentlessly on this mission to stop threats from foreign and domestic citizens.