Google knew about it earlier since they were partnering for Maps & YouTube, but it's incorrect to state that Google was doing Android in response to the iPhone.
The Android acquisition was initially a response to the horribly fragmented and underpowered mobile phone ecosystem that Google was trying to get its software onto. Android & the Open Handset Alliance unified it and gave Google an easier way to develop for billions of devices. Android had to be redesigned after the iPhone launched to switch to the new stylus-free & button-free paradigm, but it initially wasn't a response to the iPhone.