Many of those who used to work in factories, such as Mr Li in Hangzhou, are ill-equipped to find new jobs in service industries. Official data show that more than two-thirds of workers laid off in recent years were poorly educated and around half were aged 40 or older. Those are big handicaps. The government has assigned 100bn yuan ($14.5bn) to pay for the resettling and retraining of workers laid off in the steel and coal industries. But the scheme’s details are unclear. Migrants, usually first out of the door, often cannot afford to stay in a city without a job. Those who do find work in service industries are not necessarily happier. In the third quarter of 2016, for the first time, labour unrest in such firms was more common than in manufacturing, according to China Labour Bulletin. The Hong Kong-based NGO recorded 2,271 protests by workers in all industries between January and November (see map). That is more than 14 times as many as in the same period of 2011.

Drawbridge up

As anxieties grow, migrants are likely to suffer. Like those in the West who resent foreign immigrants, Chinese urbanites often blame their cities’ problems on outsiders, albeit on people from other parts of the country (who often speak very different dialects and lack “civilised” city ways). The 280m such migrants in urban China feel marginalised and resented. Weibo, a microblogging site, has accounts dedicated to subjects such as “Beijingers safeguarding the city of Beijing”. In May, 12 city and provincial governments tried to broaden their pool of university entrants by reducing quotas for local students. Parents in three cities staged demonstrations, worried their children would lose a precious advantage (pictured is one such protest in the eastern city of Nanjing).

More often, migrants are subjected to a kind of apartheid, in effect excluded from subsidised urban health care and other public services because they have no urban hukou, or residence permit. Urban schools commonly (and illegally) require that parents of migrant children pay extra fees and produce documents such as rental or job contracts that few of them can supply. Children who do get places are sometimes taught separately from those of urban-born parents. The central government is making it easier for migrants to obtain hukou in small towns and cities where apartment blocks often lie empty but jobs are scarce. But it is getting harder for people from the countryside to settle in megacities such as Beijing and Shanghai, owing to measures such as the demolition of ramshackle housing where many of them live and stricter qualifications for local hukou.

The Communist Party has treated the presidential election in America and Britain’s vote to leave the European Union as propaganda victories. People’s Daily, the party’s mouthpiece, gleefully reported on the “dark, chaotic and negative” election campaign that had revealed the “ill” state of America’s “so-called democracy”. China Daily called the Brexit vote a “political earthquake”. Its message was clear: giving people the freedom to make such momentous decisions can have dangerous consequences. With the West plunged into uncertainty, China has seized the chance to present itself as a beacon of stability.

Yet the party knows that in China, too, the rise of inequality and loss of manufacturing jobs present big challenges. Mr Xi may talk confidently of keeping China open, but the case for doing so is not clear to many of China’s citizens, nor even to the government (ask foreign businesses in China about the difficulties they face). Since the country first launched its “reform and opening” policy in the late 1970s, arguments have never ceased over how far to go. In the 1990s, when the party launched its first wave of SOE closures, resulting in millions of lay-offs, some angry workers even began to embrace a neo-Maoist movement that harked back to the days of guaranteed jobs (and far firmer controls on internal migration). As he prepared to take over in 2012, Mr Xi engaged in a fierce struggle with another leader, Bo Xilai, who had gained huge popularity partly thanks to his Maoist rhetoric. Mr Bo is now in jail, but Mr Xi has adopted his Mao-loving style and has lashed out at Mao’s critics.

Parents want to take back control

Anti-elite sentiment, such as Britain and America are experiencing, is the party’s worst fear. Mr Xi is a member of the party’s upper class: his father was Mao’s deputy prime minister until he was purged. Many of his closest allies are also “princelings”, as offspring of the party’s grandees are often called. That is why he has tried hard to portray himself as a “common man”, highlighting his experiences of living in a cave and working in the fields during Mao’s Cultural Revolution. He is appealing to popular nationalism, too, with talk of the country’s “great rejuvenation” and the “Chinese dream” (shades of Mr Trump’s “Make America Great Again”).

China does not have the complication of free elections, much less referendums. But the party feels that it needs to appear responsive to popular opinion in order to stay in power. That is becoming more difficult as economic growth slows and the main public demand—for greater wealth—becomes harder to satisfy. Even with strong institutions, rule of law and freedom of the press, Britain and America are struggling to contain popular rage. China is dealing with many of these same forces with fewer outlets for discontent. Mr Xi is trying to keep anger from spilling over by locking up dissidents with greater resolve than any Chinese leader has shown in years. He knows that global elites are under attack. That is making him all the more determined to protect China’s.