I don't think they directly copied Oracle code. The original Android SDK was based on the Apache Harmony project: https://en.wikipedia.org/wiki/Apache_Harmony#Use_in_Android_SDK
That project was created with the blessing of Sun Microsystems: https://www.theinquirer.net/inquirer/news/1019575/apache-to-cleanroom-java-with-suns-blessing
From what I understand, Harmony was developed using "clean room" principles. They had one team of developers use the existing code to write the specs, this is basically the function names and parameters and documenting what the result should be. Then another team was handed this spec and implemented it all using totally new code. This spec is the only part that was copied, everything else was implemented from scratch.
It sucks that this happened with the blessing of Sun back in the day and they were since bought by Oracle. Oracle just wants money and saw this as a way to squeeze a lot out of Google. They don't care about anything else.