1 / 17

안드로이드 FrameWork 노트

안드로이드 FrameWork 노트. 1. Thread 객체. Message. handleMessage(). Thread (Looper / MessageQueue / Handler) 관계. 3. run() 함수 호출. 2. start Thread. 상속관계. 생성 객체. HandlerThread. 1. HandlerThread 생성 및 Thread start. run() 함수 처리. 생성. 4. Looper 생성. Looper. Handler. Handler 생성.

zamora
Download Presentation

안드로이드 FrameWork 노트

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 안드로이드 FrameWork 노트

  2. 1 Thread 객체 Message handleMessage() Thread (Looper / MessageQueue / Handler) 관계 3 run() 함수 호출 2 start Thread 상속관계 생성 객체 HandlerThread 1 HandlerThread 생성 및 Thread start run() 함수 처리 생성 4 Looper 생성 Looper Handler Handler 생성 Message 달림 5 MessageQueue 생성 messageQueue 6 11 8 Message 추가 생성 9 추출 handleMessage() Handler 실행 Message 생성 및 Queue 삽입/추출 10 Handler Handler를 통해서 메시지 안에 Callback함수 추출 7 생성

  3. 1 Thread (Looper / MessageQueue / Handler) 관계

  4. 1 Thread (Looper / MessageQueue / Handler) 관계 메시지의 callback 실행 구조 2 callback 1 좌측 그림과 같이 우선적으로 1번이 실행되고 1번이 NULL일 경우 2번이 실행된다.

  5. 2 Thread 객체 System Server System Server 클래스는 안드로이드의 entry point 라고 볼 수 있다. 그러므로 안드로이드의 많은 부분을 이해하려면 꼭 구조를 이해해야 할 부분이기도 하다. Dalvik 단 Framework 단 ServerThread run() 함수 처리 8 Looper 생성 System Server Looper 1 main() (server lib 로딩) Zygote 9 MessageQueue 생성 System.loadLibrary("android_servers"); 2 messageQueue system_init.cpp 3 int1() JNI int1() 4 5 int2() 10 Android Context를 생성하고 모든 시스템 서비스를 각각의 Thread를 생성하여 가동한다. run() 함수 호출 7 6 start() Thread 가동 11 Looper 가동 상속관계

  6. 2 System Server 1) Application Context 생성 Context는 모든 application에 필요한 정보를 담고 있다. 예) Activity1 예) Activity2 Core Context Wrapper Context Wrapper Context Context Context Context … … … ApplicationContext ContextWrapper ContextWrapper 실질적으로 모든 Context가 존재 mBase mBase core Context 레퍼런스 복사 Application Context 인스턴스는 하나의 Process 안에는 모든 Thread가 공유 된다. 단 다른 프로세스가 생성되면 새로운 Application Context가 생성된다.

  7. 2 System Server 2) 시스템 서비스들에 대해서

  8. 2 System Server

  9. 3 SMS 서비스의 AIDL

  10. 3 SMS Manager ISms.stub ISms.Proxy SimSmsInterfaceManager remote에서 처리될 Interface Local 에서 처리될 Interface sendRawPdu() 메시지 발송 sendRawPdu() 구현 함수 SMS 서비스의 AIDL Local Process ISms asInterFace() 상속 1 4 Parcel 된 함수 형을 return sendRawPdu (arg1,arg2,..) 으로 풀어서 실행 Proxy 인스턴스를 받음 인스턴스 Proxy 생성 8 3 2 7 sendRawPdu() 메시지 발송 5 transact process 천이 6 Parcel 객체 생성 리턴 sendRawPdu(인자) 정보를 Parcel 객체에 담는다. Remote Process sendRawPdu ( ) arg 1..arg nParcel return Parcel

  11. 3 ISms.stub ISms.Proxy remote에서 처리될 Interface Local 에서 처리될 Interface SMS 서비스의 AIDL ISms onTransact() Process1 Process2 transact Native 영역 Service Manager 단

  12. 4 SMS IPC 구조 : 타 Process에 command 보내기 IPCThreadState transac() writeTransactionData() 타 Process에서 처리된 함수 데이터를 mOut변수 Parcel에 저장해 둔다. waitForResponse() IPC 통신을 가능하게 해주는 커널 드라이버에 해당 함수를 write한다. 결과를 받아야 하는 상황이면 Thread wait 상태가 되고 결과가 드라이버에서 처리 완료되면 드라이버에서 현재 Thread 를 깨우고 결과를 던져 준다. talkWithDriver() IPC 통신을 가능하게 해주는 커널 드라이버를 사용하는 함수이다.

  13. 4 SMS IPC 구조 : 타 Process에 command 보내기 IPCThreadState joinThreadPool() talkWithDriver() IPC 통신을 가능하게 해주는 커널 드라이버를 사용하는 함수이다. 본 함수에서 read할 데이터가 있는지 확인한다. read할 데이터가 있으면 mIn변수 Parcel 에 저장한다. executeCommand() mIn에 데이터가 있으면 해당 정보를 파싱하여 데이터에 담긴 실행해야 할 정보를 실행한다. 만일 응답을 주어야 할 데이터가 있으면 writeTransactionData()

  14. 5 SMSDispatcher ISms (AIDL) RIL SmsManager sendSMS() sendRawPdu() sendRawPdu() sendSMS() Local Socket으로 메시지 발송 메시지 발송용 Intent 작성 전달 EVENT_SEND RIL_REQUEST_SEND_SMS SMS 발송 과정 발송 응답 RILReceiver SmsTracker run() 5 6 실행 Handler Object 4 1 10 Looper 7 SimSmsInterfaceManager messageQueue sendRawPdu() CommandsInterface sendRawPdu 함수 정보를 Parcel에 담아서 저장 9 리턴 정보 RILRequest RILSender 2 공유 메모리 3 메시지 처리 정보 Object Handler 8

  15. 5 SMS 수신 과정 RIL Class ReceiverThread (RIL Receiver) Run() 요청에 의한 응답 Response solicited 요청하지 않은 응답 1 Response Unsolicited 새로운 메시지가 도착 했다는 상수 2 RIL_UNSOL_RESPONSE_NEW_SMS sendBroadcast() 해당 메시지를 Broadcast 한다. 3 4 7 ACTION : Intents.SMS_RECEIVED_ACTION Extra : PDU 데이타 string 형 데이타 파싱 SmsMessage Data SMSDispatcher : EVENT_NEW_SMS 실행 Handler 5 acknowledgeLastIncomingSMS() 발신측에 메시지를 잘 받았다는 SMS 발송 6 SMS DELIVERY REPORT

  16. 5 SMS 수신 과정 Java Layer C++ Layer RIL Class SenderThread (RIL Sender) Local Socket Looper messageQueue ReceiverThread (RIL Receiver) Run() 요청에 의한 응답 Response solicited readRilMessage 요청하지 않은 응답 Response Unsolicited

  17. 6 안드로이드 시스템 서비스 Content Manager Telephony Service Bluetooth Service Connectivity Service Location Manager Window Manager Activity Manager Package Manager Power Manager … Add Service 13 11 Audio Flinger Service Manager Add Service 10 12 daemons Surface Flinger Service Manager 9 usbd 8 5 adbd System Server runtime 6 debuggerd 4 7 2 3 rild Init Zygote Dalvik VM 1 커널 단 라이브러리 단 Linux Kernel Dalvik 단 Framework 단

More Related