It wasn't long ago that Brazil was trumpeting its bona fides on electronic surveillance, slamming the National Security Agency's spying programs as a "grave violation of human rights and of civil liberties" in a 2013 speech to the United Nations.

Now, though, Brazil is finding itself in an awkward position as it moved to block an immensely popular messaging app within its own borders for 48 hours. Prosecutors demanded that the service, WhatsApp, be shut off for its 100 million Brazilian customers after the company did not comply with a secret order for user data. (That ban was soon reversed by a higher court, but the damage was done.)

Law enforcement had been struggling with WhatsApp for months, according to the BBC, trying to get access to a drug suspect's messages on the Facebook-owned service. After WhatsApp ignored the request twice, a judge ordered that the service be suspended.

Brazil was among the NSA's biggest critics in 2013 after former agency contractor Edward Snowden leaked details of its spying operations. In response, Brazil announced the construction of a $185 million fiber optic pipeline that would carry Internet data to and from Portugal, bypassing the United States and reducing the chances of interception by U.S. authorities. No U.S. businesses will be allowed to help out in the project.

The country has also taken an active role in international negotiations concerning how the Internet should be built and maintained. But Brazil's efforts to set an example may be undone by its attempt to restrict WhatsApp — particularly in light of some of President Dilma Rousseff's previous vows.

"My government will do everything within its reach to defend the human rights of all Brazilians," Rousseff said in her 2013 U.N. speech, "and to protect the fruits borne from the ingenuity of our workers and our companies."

That last bit may hold a clue to explaining Brazil's actions. Local wireless carriers have worked to undermine WhatsApp, saying the Internet messaging service is illegal and threatens their business.

Brazilians themselves have risen up, some calling for Rousseff's impeachment. Others have moved to adopt Telegram, an alternative messaging service that also has been in the news lately as a communications conduit for the Islamic State militant group.

The swiftness with which many Brazilians switched services should be instructive for U.S. policymakers who may be tempted to view crime-fighting and counterterrorism as a game of Whac-a-Mole. When a government singles out one communications technology for punishment, it's easy for the real targets — criminal suspects — to shift to other services, circumventing the sanctions.

There's a distinction between lawful, court-approved requests for data and indiscriminate surveillance. Brazil wasn't demanding that WhatsApp give away all the data on its users. But what constitutes "lawful," and when a court should approve the requests, and under what circumstances, are questions that U.S. policymakers have been grappling with for years. It's not easy, which may be one reason that Facebook chief executive Mark Zuckerberg reacted so strongly to Brazil's decision this week.

"I am stunned that our efforts to protect people's data would result in such an extreme decision by a single judge to punish every person in Brazil who uses WhatsApp," he wrote on Facebook.