Indeed, as tingol wrote, parts (as the Linux kernel) had to be open sourced. But also for the large rest I believe open sourcing Android had more advantages than disadvantages for Google - thus it made sense. This does not contradict the fact that Google might not be fond of forks.