This is one of the most persistent misunderstandings about China.
China had a closed, planned economy. It began opening up to foreign investment in the 1980s, but not all at once in every sector. China's general approach has been gradual, instead of the "shock therapy" that the ex-Soviet Union went through (which destroyed its economy).
China initially allowed foreign investment in certain sectors, with conditions like involvement of a local joint-venture partner. An example of this was Volkswagen building a factory in Shanghai in 1984, with the Chinese company SAIC as a local partner with 50% ownership.
Over time, the number of sectors that are open to foreign investment has increased (most sectors are now open), and the rules on investment have been loosened. For example, joint-venture requirements in the automotive sector were phased out and completely eliminated by 2022. Tesla completely owns its operations in China. Toyota has announced that it is buying out its JV partner. Other Western automotive manufacturers have taken majority stakes in their operations.
China has been moving towards more openness to foreign investment over time, not less. It does have policies like "Made in China 2025" that are intended to move up the value chain, and avoid getting stuck making low-value plastic toys forever. China wants to be like the US and EU, after all - a developed economy that manufactures lots of high-tech goods.