日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

android运行过程简书,Android系统的启动流程

發布時間:2023/11/27 生活经验 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android运行过程简书,Android系统的启动流程 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Android系統有哪些進程

在Linux系統啟動時,會讀取init.rc,里面配置了一些需要啟動的進程。注意:SystemServer進程不在init.rc里,因為SystemServer進程是由zygote啟動的。

如下所示:

service zygote /system/bin/app_process ...

service servicemanager /system/bin/servicemanager ...

service sufaceflinger /system/bin/suerfaceflinger ...

service media /system/bin/mediaserver ...

...

Zygote是怎么啟動的?

init進程fork出zygote進程

啟動虛擬機,注冊JNI函數

預加載系統資源(常用類、主題資源、JNI函數、共享庫等)

啟動SystemServer

private static boolean startSystemServer(...){

String args[] = {

...

"com.android.server.SystemServer",

};

int pid = Zygote.forkSystemServer(...);

if(pid==0){

handleSystemServerProcess(parsedArgs);

}

return true;

}

......

void handleSystemServerProcess(Arguments parsedArgs){

RuntimeInit.zygoteInit(parsedArgs.targetSdkVersion,parsedArgs.remainingArgs,...);

}

......

void zygoteInit(String[] argv,...){

commonInit(); //常規初始化

nativeZygoteInit(); //調用native的onZygoteInit,啟動binder。

applicationInit(argv,...); //調用Java類(SystemServer)的main函數

}

......

virtual void onZygoteInit(){

sp proc = ProcessState::self();

proc->startThreadPool();

}

......

void applicationInit(...){

invokeStaticMain(args,...);//調用Java類(SystemServer)的main函數

}

......

SystemServer.java

public static void main(String[] args){

new SystemServer().run();

}

......

private void run(){

Looper.prepareMainLooper(); //創建主線程looper

System.loadLibrary("android_servers"); //加載native層的SystemServer代碼

createSystemContext(); //創建系統上下文

startBootstrapServices(); //啟動引導服務

startCoreServices(); //啟動核心服務

startOtherServices(); //啟動其他服務

Looper.loop(); //開啟循環

}

進入Socket Loop

boolean runOnce(){

String[] args = readArgumentList();

int pid = Zygote.forkAndSpecialize();

if(pid==0){

//in child process

handleChildProc(args,...);

//should never get here, the child is expected to either throw ZygoteInit.MethodAndArgsCaller or exec().

return true;

}else{

return handleParentProc(pid,...);

}

}

系統服務是怎么發布,讓應用程序可見?

void publisBinderService(String name,IBinder service){

publishBinderService(name,service,false);

}

void publishBinderService(String name,IBinder service,...){

ServiceManager.addService(name,service,allowIsolated);

}

系統服務運行在什么線程?

工作線程:AMS、PMS、PackageManagerService

還有一些運行在公用的線程中,如在DisplayThread,FgThread,IoThread,UiThread線程中運行。

binder線程:應用接收到binder調用后,啟動線程。

系統服務的互相依賴是如何解決的?

分批啟動

AMS, PMS, PKMS

分階段啟動

階段1,階段2,階段3,……

桌面的啟動

public void systemReady(final Runnable goingCallback){

……

//啟動桌面程序的Launcher類

startHomeActivityLocked(mCurrentUserId,"systemReady");

……

}

//Launcher(Activity)的onCreate方法中會創建一個LoaderTask

mLoaderTask = new LoaderTask(mApp.getContext(),loadFlags);

//在LoaderTask中會去向Package ManagerSevice查詢已安裝應用,然后將應用圖標顯示在桌面,當用戶點擊圖標時,Launcher就會啟動應用程序。

mPm.queryIntentActivitiesAsUser();

總結

以上是生活随笔為你收集整理的android运行过程简书,Android系统的启动流程的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。