Android培訓班(35)

來源:互聯網
上載者:User

<!-- @page { margin: 2cm } P { margin-bottom: 0.21cm } -->

在init.rc檔案裡,可以看到載入下面的服務:

service zygote /system/bin/app_process -Xzygote /system/bin --zygote --start-system-server

socket zygote stream 666

onrestart write /sys/android_power/request_state wake

onrestart write /sys/power/state on

onrestart restart media

zygote服務的代碼在目錄:

Android-2.0/frameworks/base/cmds/app_process

 

zygote服務主要作用就是建立一個服務監聽使用者的命令,並且根據使用者的命令建立應用程式運行。

它的主要入口函數代碼如下:

int main(int argc, const char* const argv[])

{

// These are global variables in ProcessState.cpp

mArgC = argc;

mArgV = argv;

mArgLen = 0;

for (int i=0; i<argc; i++) {

mArgLen += strlen(argv[i]) + 1;

}

mArgLen--;

AppRuntime runtime;

這裡建立JAVA運行庫對象。

const char *arg;

const char *argv0;

argv0 = argv[0];

// Process command line arguments

// ignore argv[0]

argc--;

argv++;

// Everything up to -- or first non - arg goes to the vm

int i = runtime.addVmArguments(argc, argv);

這裡添加命令列參數。

// Next arg is parent directory

if (i < argc) {

runtime.mParentDir = argv[i++];

}

// Next arg is startup classname or "--zygote"

if (i < argc) {

arg = argv[i++];

if (0 == strcmp("--zygote", arg)) {

bool startSystemServer = (i < argc) ?

strcmp(argv[i], "--start-system-server") == 0 : false;

setArgv0(argv0, "zygote");

set_process_name("zygote");

runtime.start("com.android.internal.os.ZygoteInit",

startSystemServer);

這雷根據命令列參數來建立JAVA虛擬機器,並從 com.android.internal.os.ZygoteInit開始運行,然後啟動所有JAVA的服務。

} else {

set_process_name(argv0);

runtime.mClassName = arg;

// Remainder of args get passed to startup class main()

runtime.mArgC = argc-i;

runtime.mArgV = argv+i;

LOGV("App process is starting with pid=%d, class=%s.",

getpid(), runtime.getClassName());

runtime.start();

}

} else {

LOG_ALWAYS_FATAL("app_process: no class name or --zygote supplied.");

fprintf(stderr, "Error: no class name or --zygote supplied.");

app_usage();

return 10;

}

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.