Android's process attribute documentation claims that the newly spawned process can either be private to the application or global. It is determined based on the first character of string value specified to the attribute.
A value starting with : indicates a application private process, which can't be shared with other applications.
android:process=":local"
And a value starting with . and a lower case represents a global process, shareable across applications.
android:process=".global"
The idea of having a single global process across applications is motivated by effective resource usage. This makes sense for 3rd party libraries as its components could be shared across applications. In android world, processes could share components only when they are signed by the same certificate and share a user id. I had blogged about this a while back here.
However, lets say the library exposed the component to be hosted in an application private process and is being used by multiple applications sharing user id and signed by same certificate,
<service android:name="MagicService" android:process=":privateprocess"/>
Android framework creates multiple application specific processes to host the MagicService even though they share the same user id and certificate simply because the component was declared as not shareable.
u0_a206 13298 224 946588 89320 ffffffff 00000000 S com.sample.one
u0_a206 13433 224 888132 24764 ffffffff 00000000 S com.sample.one:privateprocess
u0_a206 13667 224 965744 72336 ffffffff 00000000 S com.sample.two
u0_a206 13819 224 889172 24912 ffffffff 00000000 S com.sample.two:privateprocess
This is not the case when the library exposes MagicService to be hosted in a global process.
<service android:name="MagicService" android:process=".globalprocess"/>
u0_a204 11222 224 943248 84496 ffffffff 00000000 S com.sample.one
u0_a204 11352 224 904064 28380 ffffffff 00000000 S .globalprocess
u0_a204 11470 224 963612 75008 ffffffff 00000000 S com.sample.two
This is the ideal scenario for library developers as long as their components logic is shareable across applications. This reduces the memory overhead especially when the library is used by an organization with multiple applications in play store.
Having said this, what happens when this library is used by applications not sharing a user id? In this case android falls back to creating multiple application specific process to host the component. This is why the documentation claims that the component will run in a global process of that name, provided that it has permission to do so.
A value starting with : indicates a application private process, which can't be shared with other applications.
android:process=":local"
And a value starting with . and a lower case represents a global process, shareable across applications.
android:process=".global"
The idea of having a single global process across applications is motivated by effective resource usage. This makes sense for 3rd party libraries as its components could be shared across applications. In android world, processes could share components only when they are signed by the same certificate and share a user id. I had blogged about this a while back here.
However, lets say the library exposed the component to be hosted in an application private process and is being used by multiple applications sharing user id and signed by same certificate,
<service android:name="MagicService" android:process=":privateprocess"/>
Android framework creates multiple application specific processes to host the MagicService even though they share the same user id and certificate simply because the component was declared as not shareable.
u0_a206 13298 224 946588 89320 ffffffff 00000000 S com.sample.one
u0_a206 13433 224 888132 24764 ffffffff 00000000 S com.sample.one:privateprocess
u0_a206 13667 224 965744 72336 ffffffff 00000000 S com.sample.two
u0_a206 13819 224 889172 24912 ffffffff 00000000 S com.sample.two:privateprocess
This is not the case when the library exposes MagicService to be hosted in a global process.
<service android:name="MagicService" android:process=".globalprocess"/>
u0_a204 11222 224 943248 84496 ffffffff 00000000 S com.sample.one
u0_a204 11352 224 904064 28380 ffffffff 00000000 S .globalprocess
u0_a204 11470 224 963612 75008 ffffffff 00000000 S com.sample.two
This is the ideal scenario for library developers as long as their components logic is shareable across applications. This reduces the memory overhead especially when the library is used by an organization with multiple applications in play store.
Having said this, what happens when this library is used by applications not sharing a user id? In this case android falls back to creating multiple application specific process to host the component. This is why the documentation claims that the component will run in a global process of that name, provided that it has permission to do so.
No comments:
Post a Comment