The German automaker is balancing shareholder returns with investment in electric vehicles and software amid weaker sales and intensifying competition in China.