LONDON — The British government is scrambling to fend off accusations of trying to turn the country into a virtual police state with plans to conduct some trials in secret and allow authorities to track the phone calls, emails, text messages and online activity of the entire population.

Civil liberties advocates are aghast over revelations this week that officials are preparing to introduce legislation to expand state surveillance in the interests of national security. Separately, the government of Prime Minister David Cameron is proposing that certain civil court proceedings take place behind closed doors if sensitive matters of intelligence are involved.

Together, the moves are being seen by many Britons, including members of Cameron’s own Conservative Party, as another attack on freedom and privacy in a country where security cameras are already ubiquitous and police enjoy strong counter-terrorism powers.

The almost instant backlash has put the normally unruffled Cameron and his government on the defensive. Ministers are promising to listen to concerns and look for ways to guard against abuses of authority.

But Cameron vowed to press forward with the legislation.

“We should take every step that is necessary to keep the country safe. We shouldn’t put our civil liberties at risk by doing so, but where there are gaps that need to be plugged, we need to plug those gaps,” he said during a speech Wednesday. “You can achieve both security and a respect for liberty, but it means having to take difficult decisions.”

Some of the strongest criticism has come from his ruling coalition, including from his No. 2. Deputy Prime Minister Nick Clegg heads the Liberal Democrats, the junior partner in government and a party that traditionally has been a strong supporter of civil liberties.

Clegg acknowledged a need to update some of Britain’ssecurity practices in light of new forms of technology and media, such as Skype and Twitter, but said he would not allow a sweeping expansion of police snooping rights to be rushed through Parliament.

“The security establishment will always say they need new powers tomorrow,” Clegg told the Guardian newspaper. “It is the role of the politicians and Parliament to make sure that requests for new powers … are properly scrutinized and checked. That is the checks and balances in a democracy.”

The government’s proposal for greater surveillance powers, as outlined in the British media, would permit authorities to track virtually any resident’s use of the cellphone system and the Internet. Intelligence-gathering units could see what numbers someone called or texted and what websites he or she visited, and how often.

Ministers were at pains to emphasize that the content of emails and text messages would not be examined, at least not without specific permission from a judge. But the traffic patterns could, for example, alert police to a sudden flurry in communications between suspected terrorists.

“No one is going to be looking through ordinary people’s emails or Facebook posts,” Home Secretary Theresa May said.

Still, civil liberties advocates decried a further contraction of individual privacy in Britain, where some critics say that the lack of a written constitution makes it harder to prevent erosion of personal freedoms.

They also warned against the idea of secret court proceedings for matters involving sensitive intelligence.

Activists say that such rules could have prevented a public airing of the circumstances surrounding the death of Jean Charles de Menezes, an innocent Brazilian who was shot by security forces on the London Underground in 2005 not long after terrorists killed 52 people in an attack on the transportation system.

henry.chu@latimes.com