Android Open Source Project may be free but check out any Android phone sold in the west at least and it will be loaded with closed source Google software.
That is a good business. But the point is still pretty clear that Google seems to make very large investments into products that are then given away for free to many/most users (Search, Chrome, Gmail, the whole Google Workspace product suite, YouTube) with the no obvious business plan other than to drive ad revenue, sometimes in ways as indirect as just having people spend more time on the Internet.
... which is free for consumers, and also for manufacturers to license ...
>the most popular web browser in the world
... which is free ...
>runs a major cloud provider
... which is unprofitable ...