/dev/container device
Device Drive
- /dev/container device is a virtual one,device driver code is in
drivers/staging/android/container.c
in kernel - Container device provide the function of register and switch for container
- By ioctl operating on the device,we can finish specified function
ioctl Operation
CONTAINER_REGISTER
:its parameter is a pointer to int;to register the container's ID to which the pointer pointsCONTAINER_GET_FRONT_ID
:parameter is a pointer to int;to write in running container's IDCONTAINER_GET_STACK_POS
:parameter is a pointer to int;to write in container's ID which need get position before calling;to write in the container's position in stack after callingCONTAINER_SET_FRONT_ID
:parameter is a pointer to int;to set the container's ID to which the pointer points activeCONTAINER_WAIT_FOR_NEW_POS
:parameter is a pointer to int;to write in container's ID which need wait for position before calling;to write in the container's new position after calling
The Interface of Container
C++ Interface
- C++ layer and Java layer encapsulate the access interface of container device
-
C++ layer's encapsulation code is in
frameworks/native/libs/container/Container.cpp
;it generateslibcontainer.so
from compilation;the definition of interface is as follow:int getCurrentContainer(void) get container's ID in which current process is int registerContainer(int container) register a container's ID int getFrontContainer(void) judge the container's ID in front int isCurrentContainerTheFront(void) judge the container's ID if is in front int getContainerPosition(int container) get the container's position in stack int setFrontContainer(int container) set a container in front int waitForNewPosition(int container) make current process sleep until specified container's position changes int getAvailableContainers(int containers[]) get all running containers' ID
Java Interface
Java Interface is a kind of android.util.Container class;its source code is in /frameworks/base/core/java/android/util/Container.java
;it accesses C++ Interface by JNI(its code is in /frameworks/base/core/jni/android_util_Container.cpp
)
int getCurrentContainer()
:return the ID of container in which current process isint registerContainer(int container)
:register a container ID to tell kernel the container has startedint getFrontContainer()
:return the present active containerint setFrontContainer(int container)
:set a container activeint getContainerPosition(int container)
:get the position of a containerint waitForNewPosition(int container)
:current process stay sleep after calling;until specified container's position changes,it'll return the container's new positionint registerCurrentContainer()
:register the container in which current process is
Container Switch
IContainerManager
- IContainerManager is a interface of inter-process communication,which defines the communication protocol between App and ContainerMana;and the definition is in
frameworks/base/core/java/android/util/IContainerManager.aidl
-
Functions which IContainerManager defines as follow:
int switchToContainer(int container) switch to specified container int getCurrentContainer() get container in which current process is int getFrontContainer() get the front-end container boolean isCurrentContainerInFront() judge the container in which current process is if front-end int[] getAvailableContainers() get all running containers
Modified files
- Add file
/frameworks/base/core/java/android/util/IContainerManager.aidl
- In
/frameworks/base/Android.mk
,src_files
add line/frameworks/base/core/java/android/util/IContainerManager.aidl
;if you hope the interface is open for sdk,add it in following fileaidl_files
ContainerManagerService
- CMS is a service,whose name is "container";it realized all functions IContainerManager defines,AMS's code is in
frameworks/base/services/java/com/android/server/ContainerManagerService.java
- CMS is started by SystemServer,and consists in every container
- Client can make remote calls to CMS by Binder mechanism
Modified files
- Add file
/frameworks/base/services/java/com/android/server/ContainerManagerService.java
/frameworks/base/servcies/java/com/android/server/SystemServer.java
,add instantiation and call to ContainerManager- Modify this catalogue and it will generate
system/frameworks/services.jar
ContainerManager SDK
-
ContainerManager is a client of CMS;its code is in development/contain and it generates ermanager;generated jar package from compilation is in
out/target/common/obj/JAVA_LIBRARIES/containermanager_intermediates/classes.jar
- ContainerManager realize the check and management by remote calls to CMS's interface function
- ContainerManager belongs to Android SDK;it calls relevant functions in App to access interfaces CMS provides
Container Switchover Process
- Applications call switching function-
switchToContainer(int)
of ContainerManager class - ContainerManager class makes remote calls to
switchToContainer(int)
interface of ContainerManagerService by Binder mechanism - ContainerManagerService calls Java interface of container device;that is
setFrontContainer(int)
function ofandroid.util.Container
class - Java interface calls C++ interface by JNI;that is
setFrontContainer(int)
function of container in libcontainer.so - C++ interface open /dev/container device,and do
ioctl(CONTAINER_SET_FRONT_ID)
operation on it - Container device driver updates the sequence in container list after receiving ioctl operation to make the target container top
Reference Graph