anatomy of an android

53
Anatomy of an Android 김용욱 (@dalinaum)

Upload: leonardo-kim

Post on 10-May-2015

1.717 views

Category:

Technology


4 download

TRANSCRIPT

Page 1: Anatomy of an android

Anatomy of an Android김용욱 (@dalinaum)

Page 2: Anatomy of an android

Android Version

● 1.5 Cupcake● 1.6 Donut● 2.0 2.1 Eclair● 2.2 Froyo (Frozen Yogurt)● 2.3.x Gingerbread (2.3.7)● 3.x Honeycomb (3.2)

....● 4.x Ice Cream Sandwich

Page 3: Anatomy of an android

 

Page 4: Anatomy of an android

시작점

●Anatomy & Physiology of an Android (2008 Google IO)○ Patrick Brady (Google)

● Inside the Android Application Framework (2008 GIO)○Dan Morill (Google)

Page 5: Anatomy of an android

Linux Kernel

 

Page 6: Anatomy of an android

리눅스 커널

●리눅스 커널 위에 동작하지만 리눅스는 아니다.

●리눅스의 표준 유틸리티를 사용하지 않는다.

●리눅스의 커널 버전은 크게 중요하지 않음.

Page 7: Anatomy of an android

리눅스 커널

●메모리, 프로세스 관리가 뛰어나다.

●퍼미션 기반의 보안 모델을 가지고 있다.

●오픈소스

Page 8: Anatomy of an android

리눅스 커널

●Timed GPIO (Generic-purpose I/O)● Power Management●Ashmem (Anonymous shared memory)● Binder● Low Memory Killer● Kernel Debugger● Logger●Alarm

Page 9: Anatomy of an android

Timed GPIO(generic purpose I/O)

●Mike Lockwood (Google)

●일정 시간동안 사용자영역에서 GPIO에 접근하기 위해 열어 둔 인터페이스

●바이브레이터 등에 사용됨.

●  drivers/staging/android/○ timed_output.[h|c]○ timed_gpio.[h|c]

Page 10: Anatomy of an android

Power Management

●작성자: Google (iSad...)

●Suspend 전에 애플리케이션의 종료 기회 제공.

● kernel/power/ 디렉토리에 위치

○ suspend.c○ userwakelock.c○ earlysuspend.c○ consoleearlysuspend.c○ fbearlysuspend.c

Page 11: Anatomy of an android
Page 12: Anatomy of an android

Ashmem (Anonymous shared memory)

● Robert Love (Google, Ex-Noveller)○  Linux Kernel Developmen의 저자

○Android의 Logger도 작성.

●여러 프로세스 간의 데이터 공유를 위함.

● pmem과의 차이점은 "익명"이라는 점.

●mm/ashmem.c

Page 13: Anatomy of an android

Binder (Android IPC, like RPC)

●Dianne Hackborn (Google, Ex-BeOSer)

● Binder (BeOS) -> OpenBinder (Palm)-> Binder (Android)

● RPC같은 IPC를 구현

● driver/staging/android○ binder.[h|c]

Page 14: Anatomy of an android
Page 15: Anatomy of an android
Page 16: Anatomy of an android

Low memory killer

●Arve Hjønnevåg (Google, Ex-BeOSer)

●리눅스 메모리관리○사용량이 많은 프로세스 희생.○다수 프로세스를 살리는 데 있음.

●안드로이드 - 포그라운드 앱 우선○프로세스마다 현재 상태 기록.

● driver/staging/android○ lowmemorykiller.c

Page 17: Anatomy of an android

Low memory killer example (init.rc)# Define the oom_adj values for the classes of processes that can be# killed by the kernel.  These are used in ActivityManagerService.   setprop ro.FOREGROUND_APP_ADJ 0   setprop ro.VISIBLE_APP_ADJ 1   setprop ro.SECONDARY_SERVER_ADJ 2   setprop ro.HIDDEN_APP_MIN_ADJ 7   setprop ro.CONTENT_PROVIDER_ADJ 14   setprop ro.EMPTY_APP_ADJ 15

# Define the memory thresholds at which the above process classes will# be killed.  These numbers are in pages (4k).   setprop ro.FOREGROUND_APP_MEM 1536   setprop ro.VISIBLE_APP_MEM 2048   setprop ro.SECONDARY_SERVER_MEM 4096   setprop ro.HIDDEN_APP_MEM 5120   setprop ro.CONTENT_PROVIDER_MEM 5632   setprop ro.EMPTY_APP_MEM 6144

Page 18: Anatomy of an android

HAL (Hardware Abstraction Layer)

 

Page 19: Anatomy of an android

HAL (Hardware Abstraction Layer)

●리눅스 커널 디바이스를 안드로이드로 부터 분리하기 위함

●라이선스 문제○리눅스 커널은 GPL - 공개해야 함.○커널만 공개하고 하드웨어 드라이버 로직을 HAL로 분리

○Google과 Apple은 자신들이 원하는 내용만 공개.

●호환성 문제○안드로이드는 리눅스 커널 드라이버 구조를 몰라도 됨.

Page 20: Anatomy of an android

Android Runtime

 

Page 21: Anatomy of an android

Dalvik

●Dan Bornstein (Obvious Corp, Ex-Googler)

●Dalvik - Dan이 살던 지명.

●레지스터 방식의 Java Virtual Machine.

○Oracle(Sun) VM은 스택방식

○Oracle의 특허 회피

○ARM에 최적화.

●DEX 포맷 사용

○ JAR보다 용량 효율적.

Page 22: Anatomy of an android

Libraries

 

Page 23: Anatomy of an android

Libraries● Bionic C (Shinichiro Kwasaki-Hitachi)

○Non-GPL Lib C, Very small●WebKit (Don Melton-Apple, Martin Jones, Torben Weis)

○ KDE (KHTML) -> Apple (Webkit)●Media Framework (StageFright)

○OpenCore (PV)  -> StageFright (Google, 보다 단순함)

●SQLite (D. Richard Hipp-Hipp, Wyrick & Company, Inc.)○경량 DB (앱에 내장 되는 형태)○최근에는 LevelDB로 대체 움직임

●Native Servers○SurfaceFlinger, AudioFlinger

Page 24: Anatomy of an android

Native Servers 

Page 25: Anatomy of an android

Application Framework

 

Page 26: Anatomy of an android

Application Framework

●Core Platform Services

●Hardware Services

●Application Framework

Page 27: Anatomy of an android

Core platform Services

●Activity Manager● Package Manager●Window Manager● Resource Manager● Content Providers● View System

Page 28: Anatomy of an android

What is Activity?

 

Page 29: Anatomy of an android

 

Page 30: Anatomy of an android

Intent

 

Page 31: Anatomy of an android

Intent (URL을 액티비티으로 연결)<activity android:name=".MyActivity"><intent-filter><category android:name="android.intent.category.DEFAULT"/> <category android:name="android.intent.category.BROWSABLE"/> <data android:scheme="http" android:host="mysite.com android:pathPrefix="/news/articles/"/> </intent-filter></activity>

● http://mysite.com/news/articles가 보이면 저기로 연결.●웹브라우저 (링크클릭) -> (링크에 대한 인텐트) -> 우리

앱●안드로이드 앱은 액티비티로 서로 연결되어 있음.●전화가 왔을 때 인텐트를 확인하여 스팸이면 끊어버리는

앱.●카드 사 전화를 가계부 웹 서비스에 올리는 앱.

Page 32: Anatomy of an android

Looper & Message Queue

 

Page 33: Anatomy of an android

Fragment (Android 3.0 Honeycomb)

 

Page 34: Anatomy of an android

 

 

Page 35: Anatomy of an android

 

2 Fragments in 1 Activity

Page 36: Anatomy of an android

 

Action Bar - 현재 상태, 아이콘, 메뉴 

Page 37: Anatomy of an android

 

System Bar - 뒤로가기, 홈, 창 변환 버튼, 노티파이케이션.

Page 38: Anatomy of an android

 

 

Page 39: Anatomy of an android

Hardware Services

●Telephony Service● Location Service● Bluetooth Service●WiFi Service●USB Service●Sensor Service●NFC Service (Android 2.3.3)

Page 40: Anatomy of an android

Application Framework

●RTFM○Read the fine manual, please :)

Page 41: Anatomy of an android

Layer Interaction

There are 3 main flavors of Android layer cake:

●App -> Runtime Service -> Lib

●App -> Runtime Service -> Native Service -> Lib

●App -> Runtime Service -> Native Daemon -> Lib

Page 42: Anatomy of an android
Page 43: Anatomy of an android
Page 44: Anatomy of an android

Layer Interaction

There are 3 main flavors of Android layer cake:

●App -> Runtime Service -> Lib

●App -> Runtime Service -> Native Service -> Lib

●App -> Runtime Service -> Native Daemon -> Lib

Page 45: Anatomy of an android
Page 46: Anatomy of an android
Page 47: Anatomy of an android

Layer Interaction

There are 3 main flavors of Android layer cake:

●App -> Runtime Service -> Lib

●App -> Runtime Service -> Native Service -> Lib

●App -> Runtime Service -> Native Daemon -> Lib

Page 48: Anatomy of an android
Page 49: Anatomy of an android
Page 50: Anatomy of an android

Make world

●Official○AOSP (Android Open Source Project)

■ http://source.android.com/●  Custom

○  CyanogenMod (CM)■ http://www.cyanogenmod.com/

○  CodeAuroraForum (CAF)■ https://www.codeaurora.org/

●Groups○  http://groups.google.com/group/android-contrib○  http://groups.google.com/group/android-platform○  http://groups.google.com/group/android-building

Page 51: Anatomy of an android

Recommend

CyanogenMod - de facto standard custom ROM

Page 52: Anatomy of an android

Special Thanks to JBQ

Thanks JBQ, who moves truck-loads of source code in and out of the Googleplex 

Jean-Baptiste Queru (Google)

Page 53: Anatomy of an android

Q&A