android-framework-Android系统原理与开发

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Jollen Android Framework & HAL Copyright (C) 2010 Jollenʼs Consulting http://www.jollen.org/consulting

Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
Anyone
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
➡ ➡
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
static void Dalvik_dalvik_system_Zygote_fork(const u4* args, JValue* pResult) { pid_t pid; setSignalHandler(); dvmDumpLoaderStats("zygote"); pid = fork(); RETURN_INT(pid); }

Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Android Service 6.1 Android Process 6.2 Component 6.3 SystemServer 6.4 ServiceManager 6.5 SensorManager SensorService Main Thread
http://www.jollen.org/consulting

Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
➡ ➡ ➡ ➡
Jollen
Android Framework & HAL
/** * Filename: dalvik/dalvikvm/Main.c */ int main(int argc, char* const argv[]) { /* * Start VM. The current thread becomes the main thread of the VM. */ if (JNI_CreateJavaVM(&vm, &env, &initArgs) < 0) { fprintf(stderr, "Dalvik VM init failed (check log file)\n"); goto bail; } }
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Component
Main Thread
VM Process
Jollen
Android Framework & HAL
Zygote HelloWorld
fork() Component Activity
Main Thread
Main Thread
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
➡ ➡
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Zygote
fork()'d
SystemServer
Touch
startActivity()
Launcher
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Zygote
3 fork()'d
App
2 !"#$%&'
SystemServer
1 startActivity()
http://www.jollen.org/consulting
public class ZygoteInit { ... public static void main(String argv[]) { registerZygoteSocket(); preloadClasses(); // Do an initial gc to clean up after startup gc(); if (argv[1].equals("true")) { startSystemServer(); } Log.i(TAG, "Accepting command socket connections"); if (ZYGOTE_FORK_MODE) { runForkMode(); } else { runSelectLoopMode(); } } ... closeServerSocket();
Jollen Chen <jollen@jollen.org> Blog http://www.jollen.org/blog http://www.jollen.org/wiki http://www.jollen.org/consulting
2010/6/29 ( ) 09:00~16:30 6
See: http://www.jollen.org/wiki/Zygote_Native
Jollen Android Framework & HAL Copyright (C) 2010 Jollenʼs Consulting http://www.jollen.org/consulting

➡ ➡
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
Class Loader .dex
bytecode Execute Engine
Native Method JNI Host OS (Linux)
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
➡ ➡ ➡
➡ ➡ ➡
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
http://www.jollen.org/consulting
➡ ➡ ➡
VM Process
Component
Main Thread
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
}
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
public class HelloWorld extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } }
Байду номын сангаас
! " # $ % & ' () * + ,
(Moko365 Inc) 3G Android Android 3G Linux
2009
(, . /
ʼ
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting


LED App LedService (Java) LedService (Native) HAL LED Stub
1
2
Jollen Android Framework & HAL Copyright (C) 2010 Jollenʼs Consulting http://www.jollen.org/consulting
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
int main(int argc, char* const argv[]) { /* * Find [class].main(String[]). */ jclass startClass; jmethodID startMeth; char* cp; /* convert "com.android.Blah" to "com/android/Blah" */ slashClass = strdup(argv[argIdx]); for (cp = slashClass; *cp != '\0'; cp++) if (*cp == '.') *cp = '/'; startClass = (*env)->FindClass(env, slashClass); startMeth = (*env)->GetStaticMethodID(env, startClass, "main", "([Ljava/lang/String;)V"); if (!methodIsPublic(env, startClass, startMeth)) goto bail; /* * Invoke main(). */ (*env)->CallStaticVoidMethod(env, startClass, startMeth, strArray); }


➡ ➡ ➡
Jollen
Android Framework & HAL
Copyright (C) 2010 Jollenʼs Consulting
http://www.jollen.org/consulting
public class SystemServer { private static final String TAG = "SystemServer"; native public static void init1(String[] args); public static void main(String[] args) { System.loadLibrary("android_servers"); init1(args); } public static final void init2() { Log.i(TAG, "Entered the Android system server!"); Thread thr = new ServerThread(); thr.setName("android.server.ServerThread"); thr.start(); } }
相关文档
最新文档