Study the architecture hierarchy of Android system

Source: Internet
Author: User

If you borrow other people to study the WiFi level, compared to the Android download source. You can see how the level of architecture at the first layer of Android is.

and learn how an Android system is running.

So usually my Android development is mostly in the Java application layer, some deep point is the NDK code, will be through the NDK code. such as Proxydroid.

His proxy function is actually using the NDK, through the Jndi interface, called to a C + + layer, and then C + + hierarchy can use some C + + class library, will fork a background process

Go to the iptable agent.

If you execute the following command

Iptables-t nat-a output-p tcp--dport 80-j DNAT--to-destination 127.0.0.1:8123

will use Jndi to invoke C + +

Android_os_exec_createsubprocess method

Finally call the Create_subprocess method


static int create_subprocess (const int RDT, const char *cmd, char *const argv[],
Char *const envp[], const char* scripts, int* pprocessid)
{
pid_t pid;
int pfds[2];
int pfds2[2];
Pipe (PFDS);
if (RDT) {
Pipe (PFDS2);
}
PID = fork ();
if (PID < 0) {
LOGE ("-Fork failed:%s-\n", Strerror (errno));
return-1;
}
if (PID = = 0) {
Signal (Sigpipe, sig_ign);
if (ENVP) {
for (; *envp; ++envp) {
Putenv (*ENVP);
}
}
Dup2 (Pfds[0], 0);
Close (pfds[1]);
if (RDT) {
Close (1);
Close (2);
Dup2 (Pfds2[1], 1);
Dup2 (Pfds2[1], 2);
Close (pfds2[0]);
}
Execv (cmd, argv);
Fflush (NULL);
Exit (0);
} else {


Signal (Sigpipe, sig_ign);


*pprocessid = (int) PID;
Dup2 (Pfds[1], 1);
Close (Pfds[0]);
Write (pfds[1], scripts, strlen (scripts) +1);
if (RDT) {
Close (pfds2[1]);
return pfds2[0];
} else {
return-1;
}
}
}



Wifi System:

Java Application layer
Java Framework Layer
JNI Layer
Adapter Layer
Wpa_supplicant Program
Kernel layer

Java Application layer
--Settings, Wifiswitcher and other applications
-/system/app
Java Framework Layer
--frameworks/base/wifi/java/android/net/wifi/* (Android.net.wifi)
--Frameworks/base/services/java/com/android/server/wifiservice.java
Frameworks/base/services/java/com/android/server/wifiwatchdogservice.java
-/system/framework/framework.jar
/system/framework/services.jar
JNI Layer
--Frameworks/base/core/jni/android_net_wifi_wifi.cpp
-/system/lib/libandroid_runtime.so
Adapter Layer
--HARDWARE/LIBHARDWARE_LEGACY/WIFI/WIFI.C
-/system/lib/libhardware_legacy.so
Wpa_supplicant Program
--External/wpa_supplicant
--External/wpa_supplicant_6
-/system/bin/wpa_supplicant
/system/lib/libwpa_client.so
Kernel layer
--Kernel WiFi driver

The process of Enable Wifi:

Settings/wifienabler.java
Mwifimanager.setwifienabled (enable);
-
Frameworks/base/wifi/java/android/net/wifi/wifimanager.java
Public Boolean setwifienabled (Boolean enabled) {
mservice.setwifienabled (enabled);
}
-
Frameworks/base/services/java/com/android/server/wifiservice.java
Public Boolean setwifienabled (Boolean enable) {
Sendenablemessage (Enable, True, Binder.getcallinguid ());
}
-
Setwifienabledblocking () {
if (enable) {
Mwifistatetracker.loaddriver ();
Mwifistatetracker.startsupplicant ();
} else {
Mwifistatetracker.stopsupplicant ();
Mwifistatetracker.unloaddriver ();
}
}
-
Frameworks/base/wifi/java/android/net/wifi/wifistatetracker.java
Public synchronized Boolean loaddriver () {
return Wifinative.loaddriver ();
}
Public synchronized Boolean startsupplicant () {
return Wifinative.startsupplicant ();
}
-
Frameworks/base/wifi/java/android/net/wifi/wifinative.java
Public native Static Boolean loaddriver ();
Public native Static Boolean startsupplicant ();
-
Frameworks/base/core/jni/android_net_wifi_wifi.cpp
Static Jboolean Android_net_wifi_loaddriver (jnienv* env, Jobject clazz)
{
Return (Jboolean) (:: wifi_load_driver () = = 0);
}
Static Jboolean Android_net_wifi_startsupplicant (jnienv* env, Jobject clazz)
{
Return (Jboolean) (:: wifi_start_supplicant () = = 0);
}
-
Hardware/libhardware_legacy/wifi/wifi.c
int Wifi_load_driver () {
For build in driver
For. Ko driver, insmod/load firmware ...
}
int Wifi_start_supplicant () {
Property_set ("Ctl.start", "wpa_supplicant");
}
-
/init.rc

Service wpa_supplicant/system/bin/wpa_supplicant ...




Study the architecture hierarchy of Android system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.