Unlike iOS, virtually all of the Android userland, and all of its SDK, is also open source: AOSP is the name of the project containing it all.
IIRC only two major things aren't included: binary blob-only drivers, and proprietary Google apps: Play store, Maps, etc.
Despite those limitations, you can practically just `git clone` and build the entire OS for your device. :-)