Question about UiAutomator

I am new at Appium that is why I did not understand some aspects during the working process.

Is UiAutomator installed on phone or it comes with AndroidSDK?

Ui Automator framework has three core components all of which comes with Android SDK
https://developer.android.com/training/testing/ui-automator.

This is great resource. However I did not figured out yet how the whole framework works