DONGGUAN, a southerly Chinese city near Hong Kong, is better known for cranking out cheap trinkets than for producing high-end equipment of any kind. And yet, amid the grit and grime is a gleaming low-rise factory producing some 50m smartphones a year for OPPO, a firm started by China’s BBK Electronics but which is now run independently.

Inside, as well as the usual assembly lines and serried workers, the factory has dozens of staff in quality engineering and testing, conducting 130 different tests on OPPO’s phones before they are released to the market. Such zealous pursuit of quality would be expected of factories that produce phones for Apple—the world-class facilities run by Taiwan’s Foxconn in nearby Shenzhen house similar teams. But it is unusual at a firm that makes relatively inexpensive handsets for the local market.

OPPO, and its sister firm, Vivo, also a child of BBK, started out in 2004 and 2009 respectively, making cheap and cheerful phones like plenty of other obscure Chinese manufacturers. They probably didn’t even register on Apple’s radar. Xiaomi was the Chinese handset-maker to watch; urban sophisticates, enticed by viral marketing, flocked to its slick devices. But in June 2016 OPPO’s R9, which costs around $400, overtook the iPhone, which is priced at twice that, as China’s best-selling handset. Vivo, which targets younger consumers with lower prices, is also surging.

The two brands’ achievements are remarkable. Two years ago they were struggling to join China’s top five smartphone-makers; now they are among the biggest five globally. One out of every three smartphones sold in China in the third quarter of 2016 carried one of their brands; in 2012 their combined share was below 3%.

That should give Apple pause. Tim Cook, its boss, predicted in 2013 that China would become his firm’s biggest market. But iPhone sales there have stagnated (see chart). In the third quarter its market share fell to 7.1%, down from 11.4% a year earlier. Xiaomi has even more reason to fret. About six years ago it bet on an “asset-light” strategy, meaning it relied almost entirely on selling its phones online. This worked brilliantly when the overall market for smartphones was growing, and the richest cities, with the largest number of tech-aware consumers, were booming. Xiaomi was once valued at some $46bn, but its fortunes in China have plunged. That is chiefly due to the fact that growth has shifted sharply to the rising middle classes in smaller cities. Consumers there are less experienced with smartphones than their fancier cousins in Beijing and Shanghai, and are wary of buying them online. They want to touch and compare handsets. OPPO and Vivo spotted this difference early. OPPO in particular shot to the top because it invested heavily in bricks-and-mortar retail distribution in lower-tier cities. Today the firm’s phones are sold at some 200,000 retail outlets across the mainland, which gives its salesmen the chance to coddle customers and nudge them to buy pricier phones. At first, OPPO’s strategy was masterminded by Duan Yongping, founder of BBK, who began by selling basic electronics. He is known in China as “Duanfett”, a play on Warren Buffett, because of his financial acumen and also his admiration for Mr Buffett (he paid over $600,000 at an auction to have lunch with him in 2007). Mr Duan has since retired, but still influences the firms’ cultures.

It took discipline not to be waylaid by the striking (though short-lived) success of Xiaomi’s hype-fuelled internet strategy. Many other companies tried to copy it. From 2011 to 2013, insiders say, OPPO looked hard at expanding its online sales channels, but decided against it. Sky Li, managing director of OPPO’s international mobile business, says the reason lies in his firm’s long-held adherence to the philosophy of ben fen—loosely translated, sticking to one’s knitting.

Instead, OPPO became still more expert at incentivising its physical retailers. It has shown itself willing to share some of its profits with local stores. It uses a sophisticated system of subsidies that vary by model and season. One retailer in a small town in Sichuan says that although he sells many brands of smartphones, OPPO’s generous subsidies make him extra-eager to peddle its wares.

That has its costs, of course: OPPO does not disclose the size of its total subsidies nor its profit margin, which may be low compared with other smartphone makers. Fat profits are hard to come by in China’s giant smartphone market. Because it is simple for firms to outsource almost every aspect of phonemaking, from designing components and chipsets to contract manufacturing, the barrier to entry is low (the physical networks that OPPO and Vivo have built will be far harder to replicate than an online presence). Teeming firms means vicious price competition, especially for cheaper phones. The price of a Chinese smartphone may drop to as little as $50, analysts reckon.

Pressures at home explain why Chinese firms are also looking abroad. In the fourth quarter of 2016, Xiaomi and Vivo were vying with each other behind Samsung in the race for second place in India’s smartphone market. Huawei, a local telecoms-equipment giant that ranks third in the domestic market, already makes two-fifths of its sales outside China; Shao Yang of its consumer-business group says this share will rise to three-fifths within five years. OPPO is already a force in India, and is in second place in South-East Asia behind Samsung. It has opened a new marketing centre in Cairo to spearhead expansion in Africa and the Middle East.

Kevin Wang of IHS Markit, a research firm, nonetheless reckons that a round of consolidation must be on its way. Within five years, he reckons, most of the 50 or so local Chinese phone manufacturers will be gone. If OPPO and Vivo can stay at the summit, that would be nearly as surprising as the dizzying speed of their ascent.