Default [Q] How UID of an app determined during install in Android?

The following link gives a brief description about package installation process in android.

java,dzone,com/articles/depth-android-package-manager

I'm curious to know how the UID of an app is determined during its installation based on set the permissions present in its manifest file.

Also there is the platform.xml (in /frameworks/base/data/etc directory for 4.0 ICS Source code)file which contains list of permissions with gid associated with them. The description says

The following tags are associating low-level group IDs with permission names. By specifying such a mapping, you are saying that any application process granted the given permission will also be running with the given group ID attached to its process, so it can perform any filesystem (read, write, execute) operations allowed for that group.

In a similar way there is a list of high level permissions assigned to specific uid's as well.

My question is when an app is installed with permissions X,Y, Z how does its access specified is it from the mapping from this platform.xml

Also everytime the app is run does the mapping take place at every instant (that doesn't seem right from the initial design of android where the app permissions cannot be changed unless there is an update). So if that is the case where does it store saying this app should run with such and such access or such and such uid.

I hope I made my question clear, let me know if you need more information. I'm just trying to learn more on how the internals of the Android OS work.

Thanks