Skip to main content

Posts

Showing posts from September, 2018

The Startups: SystemServer

SystemServer class kind of initializes all core system services. Before going into the codeflow its good to know about the SystemService and SystemServiceManager classes SystemSevice : This is the base class for services running in the system process. We can Override and implement the lifecycle event callback methods as needed. The lifecycle of a SystemService: /frameworks/base/services/core/java/com/android/server/SystemService.java       The constructor is called and provided with the system Context to initialize the system service.       onStart() is called to get the service running.   The service should publish its binder interface at this point using publishBinderService() .      It may also publish additional local interfaces that other services within the system server may use to access privileged internal functions.      onBootPhase(int phase) is called as many times as there are boot pha...

The Startups: ZygoteInit

ZygoteInit is the Java side startup class for Zygote Process. /frameworks/base/core/java/com/android/internal/os/ZygoteInit.java This pre-initializes some classes and waits for commands on the zygote socket Based on these commands, forks off child processes that inherit the initial state of the VM. When main process is called with start-system-server as arg: Steps: 1, registerZygoteSocket(socketName);     Registers a server socket for zygote command connections 2. preload();     Preload      -Classes          List maintained at /system/etc/preloaded-classes Load and explicitly initialize the given class Class.forName(line, true, null); //This would load and initialize the class       -Resources           Load in commonly used resources, so they can be shared across processes.   Resouces.startPreloading()   TypedArray ar = mResources.obtainTypedArray( ...

The StartUps: Android Runtime

The Zygote Process starts the Android Runtime with the following command. The code for this is at frameworks/base/core/jni/AndroidRuntime.cpp runtime.start("com.android.internal.os.ZygoteInit", args, zygote); This involves starting the virtual machine and calling the "static void main(String[] args)" method of ZygoteInit.  Event Log for Boot Progrsess Start is printed here. Steps : Check is /system/ directory is available Initialize Jni_invocation jni_invocation.Init(NULL);     - Jni_invocation: adds a layer of indirection for applications using the JNI invocation API to allow the JNI implementation to be  selected dynamically. Apps can specify a specific implementation to be used by calling InitJniInvocation.      If this is not done, the  library will chosen based on the value of Android system property "persist.sys.dalvik.vm.lib"(say libart.so, libdvm.so or libartd.so)  on the device, and otherwise fall back to a hard-code...

The Startups: App_Process

As discussed earlier the app_process(Zygote) is started by the init.rc with the following command  -- /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server The syntax to be used is   -- app_process [java-options] cmd-dir start-class-name [options] The implementation of this is present in / frameworks / base / cmds / app_process / app_main.cpp  This process starts the interpreted runtime, then starts up the application(system-server in this case)  arg -Xzygote : Starts in zygote mode  arg start-system-server: starts system-server process  When starting system server this process:  Creates Dalvik Cache Folder maybeCreateDalvikCache()  Calls Android Runtime.start, with args "start-system-server" and "abi-list"     runtime.start("com.android.internal.os.ZygoteInit", args, zygote);  When not starting in Zygote Mode, it just passes the arguements to the application process     runtime.s...

The Startups : Init

Things start up from init.rc.  If you are interested in learning init language check this link https://android.googlesource.com/platform/system/core/%2B/master/init/README.md In stock AOSP this is present in /sytem/core/roodir/ This imports : import /init.${ ro.zygote }.rc  Based on you devices ro.zygote system property the init.zygote file from the same folder is imported. init.${ ro.zygote }.rc : looks something like.. service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server         When asked to start; run zygote program by running "/system/bin/app_process". The remaining part is arguments to app_process class main         Adds this to main class; So this service would be started whenever this class is started. socket zygote stream 660 root system        Create a zygote socket onrestart write /sys/android_power/request_state wake onresta...

Prologue

This is just a write up of some of the things I figured out during my time spent on figuring out Android.  P.S I may be wrong. Things change all the time in android Most of this is based on M This is mostly about the Java part of the framework Contents: The Startups: Init The Startups: App_Process The Startups: AndroidRuntime The Startups: ZygoteInit The Startups: SystemServer ActivityManager: Basics ActivityManager: How an Activity Starts ActivityManager:Configuration Management