The service principle and use of the Android system comes with

Source: Internet
Author: User

1. Description

Android background running in a lot of service, they are systemserver on when the system starts, support the normal operation of the system, such as Mountservice Monitoring for SD card installation and removal, Clipboardservice provides the Clipboard function, Packagemanagerservice provides installation removal and viewing of packages, and so on, applications can access the data provided by the service through the manager interface provided by the system, and the following will explain their tool flow

2. Illustrate basic processes

The Android system supports sensor instances to illustrate how the service and manager of the framework layer work together

1) What is sensor

Sensor sensors, such as the control of the screen switch using the gravity sensor (gsensor), as well as accelerator sensor can get x, Y, z three axes of acceleration (application such as balance ball, monkey eat banana, etc.)

2) Application call (key code below)

Sensormanager= (Sensormanager) getsystemservice (context. Sensor_service);

Lightsensor = Sensormanager.getdefaultsensor (sensor.type_light);

Sensormanager.registerlistener (Sensorlistener, Lightsensor, sensormanager.sensor_delay_normal);

3) Manager layer

A) interface to the application invocation, interacting with the service and implementing the function

Frameworks/base/core/java/android/hardware/sensormanager.java

4) Service Layer

A) Background service for management sensor running at boot time

Frameworks/base/services/java/com/android/server/sensorservice.java

b) Snesor the JNI required by the backend service, through which it interacts with the system level

Frameworks/base/services/jni/com_android_server_sensorservice.cpp

5) System Layer

A) the sensor's header file, the hardware provider realizes its function according to the definition of this file

Hardware/libhardware/include/hardware/sensors.h

b) The system layer implementation of the sensor, interacting with the kernel, which is usually provided by the hardware provider

Hareware/libsensors

6) Kernel and hardware layer

The kernel accesses the hardware while providing the upper control interface and sensor data in the form of device files.

3. System-Level implementation

1) Frameworks/base/core/java/android/*manager.java interface to the application

2) frameworks/base/core/jni/JNI of the interface to the application

3) frameworks/base/services/java/com/android/server/Backstage Service

4) Frameworks/base/services/jni/jni and System layer interface

5) hardware/libhardware/include/System Layer header file

6) HARDWARE/LIBXXX System Library Support

7) Kernel Support

4. How the application uses

1) See what services the system provides

Find Frameworks/base/core/java/android/-name *manager.java

Here you can see the portal that invokes the system service

2) General Register Listener, receive callback when event occurs

5. Create a new service (take Froyo as an example)

1) Interface: Call for interface supply

Frameworks/base/core/java/android/app/contextimpl.java Plus service name and manager

Frameworks/base/core/java/android/content/context.java Service Name Definition

2) Manager: Provide the service corresponding to the calling interface

Frameworks/base/core/java/android/app/startxxxxmanager.java implementing the Calling interface

Frameworks/base/core/java/android/app/ixxxxmanager.aidl defining the Calling interface

Frameworks/base/android.mk adding Aidl to the compilation

3) Service: Provide back-office support

Frameworks/base/services/java/com/android/server/xxxxservice.java Service Implementation

Frameworks/base/services/java/com/android/server/systemserver.java Start Service

http://yueguc.iteye.com/blog/775339

Related Article

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.