본문

171024(화) - Application Fundamentals

Application Fundamentals


Application Fundamentals

- android app은 Java programming language로 작성된다.

- Android SDK tools는 code, any data, resource files를 compile하여 .apk (Android package인 APK)에 저장

- APK에는 Android app의 모든 contents가 포함되며, Android-powered devices가 app을 설치하는데 사용되는 파일


- 각각의 Android app은 Android security 기능으로 보호되는 own security sandbox에 lives

· Android operating system은 각각의 app이 different user인, multi-user Linux system이다.

· 기본적으로 system은 각 app에 unique Linux user ID를 부여한다. (ID는 system에서만 사용되며 app에서는 알 수 없음)

· system은 app의 모든 파일에 대한 permissions를 설정하여 해당 app에 할당된 user ID만 access 할 수 있도록 한다.

· each process는 own virtual machine(VM)이 있으므로, app's code가 other app으로부터 독립적으로 runs 된다.

· 기본적으로 every app runs own Linux process.

· Android system은 app's components 중 하나를 executed해야 할 때 process를 시작하고, 더 이상 필요하지 않거나 system이 다른 app을 위해서 must recover memory해야 하는 경우 process를 shuts down한다.


- Android system은 least privilege principle을 implements 한다.

- 즉, 기본적으로 each app은 작업을 수행하는데 필요한 components에만 access 가능하다.

- 이런 정책은 permission이 부여되지 않은 system의 일부에 app이 access할 수 없는 very secure environment을 만든다.


- app이 다른 app과 data를 공유하고, app이 sytsem service에 access하는 방법도 존재한다.

· 두 개의 app이 동일한 Linux user ID를 공유. 서로의 파일에 access 가능하다. 

ㆍSystem resources를 절약하기 위해서 동일한 user ID를 사용하는 app을 same Linux process에서 실행하고 same VM을 공유 가능하다. App은 동일한 certificate를 signed해야 한다.


ㆍapp은 user contract, SMS messages, SD card, camera and Blutooth 등과 같은 device에 permission을 요청 가능하며, user는 explicit 하게 permission을 부여해야 한다. Working with System Permissions.


- Android system design의 unique aspect는 any app can start another app's component.

- ex) want the user to capture a photo with the device camera, developing an activity to capture a photo 하는 대신에 another app에서 이 작업을 수행 가능하다. camera app의 code를 incorporate or even link할 필요가 없다.


- system starts a component, if not already running면 start the process 하고, instantiates the classes needed for the component

- ex) app starts the activity in the camera app, 해당 activity는 app process가 아니라 camera app에 속한 process에서 run

- 따라서 unlike apps on most other systems, Android apps  don't have a single entry point (not have main() function)

- system은 each app in a separate process with file permissions로 run하기 때문에 app은 another app의 component를 직접 activate 할 수 없으나, Android system은 가능하다.


- another app에서 component를 activate하려면 spacifies your intent message를 system에 deliver해야 한다.



App components

- app components는 Android app의 essential building blocks이다.

- 각 components는 system or user가 app을 enter할 수 있는 entry point

- 일부 components는 다른 componens에 depend on.


- Activities

ㆍuser와 interacting 하기위한 entry point이다.

ㆍuser interface가 있는 single screen을 represents 한다.

ㆍ일관된 user experience를 형성하기는 하지만, 각 activity는 서로 independent 하다.

ㆍ해당 app에서 허용할 경우 다른 app에서 activity를 시작하는것도 가능

ㆍactivitys는 system과 app간의 아래 key interactions를 facilitates한다.

- System이 activity를 hosting하는 process를 keeps running 하도록 user가 현재 cares 하는것을 tracking 한다.

- 이전에 사용된 process는 user가 return 할 수 있는 작업(stopped activities)을 포함하고 있고, 이러한 process를 유지하는데 more highly prioritize 를 부여한다는 사실을 knowing 한다.


- app이 process가 kill되어 user가 이전 state restored로 return 하게 도와준다.

- app간에 user flows를 implement하고 system이 이러한 flow를 coordinate하는 방법을 provide한다.


ㆍActivity는 Activity의 sub class로 implement한다.


- Services

ㆍservice는 all kind reasons로 background에서 app running을 하기 위한 general-purpose entry point이다.

ㆍ이 component는 background에서 long-running operations 하거나 remote process 작업을 수행하기 위해 background에서 실행된다.


ㆍservice는 user interface를 수행하지 않는다.

ㆍactivity같은 다른 components는 service를 run, interact 하기 위해 start and bind 할 수 있다.

ㆍapp을 관리하는 방법에 대해 2가지 very distinct semantics한 방법이 있다. 

ㆍ시작된 service는 작업이 완료될 때 까지 service를 계속 실행하도록 system에 알린다.

ㆍuser가 app을 떠난 이후에도 some data를 sync하거나 music을 play 가능하다.

ㆍbackground에서 data를 sync하거나 음악을 playing 하는것은 start service의 두가지 type을 말하며, system은 이를 handle하는 방식을 modify한다.


First

- music play는 user가 알고있는 내용이다. 따라서 app은 user에게 notification을 foreground로 보내고 싶다고 say하면서 system에 telling 한다. 


- System은 service process가 keep running 하도록 really hard try 해야 한다는 것을 알고 있다. service가 사라지면 사용자가 unhappy하기 때문.


Second

-  regular background service는 user가 running을 directly aware하는것이 아니므로, system은 process managing에 있어서 더 자유롭다.


- user에게 more immediate things에 대해서 RAM이 즉각 필요한 경우, service가 종료되고 나중에 다시 시작되도록 allow 가능하다.


ㆍBound service는 some other app or the system에서 service를 사용하기 원하기 때문에 run된다.

- 기본적으로 another process에서 API를 providing 하는 service이다.

- 따라서 system은 이러한 process간의 dependency를 알고 있으므로, process A가 process B의 service에 bound 되면 A를 위해서 process B를 keep running 해야한다는것을 알고 있다.


- 또한 process A가 user cares이면, process B를 user cares로 tread해야하는것도 알고 있다.

- flexibility (better or worse) 때문에, services는 all kinds of higher-level system concepts을 위한 really useful building block으로 turned out 되었다.


ㆍservice는 implemented as a subclass of Service


app targets이 Android 5.0(API level 21) or later, schedule actions를 위해 JobScheduler를 사용한다. 


JobScheduler는 conserving battery하기 위해 optimally scheduling jobs하고, Doze API를 사용하여 reduce power consumption 한다.


- Broadcast receivers

ㆍbroadcast receiver는 system이 regular user flow 외부에서 event를 app에 deliver하여, app이 system-wide broadcast announcements에 respond할 수 있게 해주는 component이다.


ㆍboradcast reciever는 app에 대해서 well-defined entry이므로 system은 not currently running app에도 broadcast receiver를 전달 가능하다.

ㆍex) app의 broadcast receiver에 alarm을 전달하면, app이 계속 실행될 필요가 없다.

ㆍ대부분의 broadcasts는 system에서 발생(screen turned off, battery low, picture captured etc)

ㆍapp은 broadcast initiate 가능하다.

ㆍalthough broadcast receivers는 user interface로는 보여지지 않지만, event 발생시 status bar notification으로 alert 가능하다.

ㆍcommonly, broadcast receiver는 other component에 대한 gateway일 뿐이며, minimal amount of work를 수행하기 위한것이다.

ㆍbroadcast receiver is implemented as a subclass of BroadcastReceiver  and 각각의 broadcast는 Intent object로 전달한다.


- Content providers

ㆍcontent provider는 file system, SQLite database, web, other persistent storage location에 저장할 수 있는 sheared set of app data를 관리한다.


ㆍcontent provider가 allow하는 경우 content provider를 통해 다른 apps이 query or modify the data 할 수 있다.

ㆍex) Android system은  user's contact information을 manages하는 content provider를 제공한다.

ㆍ적절한 permissions가 있는 app은 ContactsContract.Data와 같은 content provider를 query하여 particular person에 대한 information을 read and write할 수 있다.


ㆍcommon case를 위해 많은 API와 support built되어 있기 때문에 content provider를 database의 abstraction이라고 생각하기 쉬우나, 이러한 관점은 system-design perspective에 벗어난다.


ㆍTo the system, content provider는 URI scheme으로 식별되는 named data items를 publishing 하기 위한 app의 entry point 이다.

ㆍapp은 포함된 data를 URI namespace에 map하여 해당 URI를 다른 entities에 전달하는 방식으로 data에 access 할 수 있다.

ㆍsystem에서 app managing을 할 수 있는 few particular things가 있다.

- assigning  URI여도 app을 계속 running할 필요는 없으므로, app을 종료한 후에도 URI를 유지 가능

- system은 해당 URI에서 app의 data를 retrieve해야할 때, owning app이 still running인지 확인해야 한다.

- URIs provide important fine-grained security model

- ex) app can place URI for an image it has on clipboard, but 다른 app에서 freely access하지 못하도록 content provider locked up

- ex) second app이 clipboard에서 해당 URI에 attempts access하려고 하면 system은 해당 URI의 behind data에만 access allowed 하도록 temporary URI permission grant한다. 하지만 second app에는 access할 수 없다.


ㆍcontent provider는 useful for reading and writhing data that is private to app and not shared

ㆍcontent provider는 ContentProvider 의 subclass이다.



Activating components

- 4가지 component types 중에 activities, services, broadcast receiver가 intent (asynchronous message)에 의해서 activated된다.

- intents는 individual component를 runtime에 서로 bind 한다.

- whether component가 belongs to your app or another, other component의 action을 request하는 messengers라고 할 수 있다.

- intent는 특정 component(explicit intent) 또는 특정 type의 component(implicit intent)를 activate 하는 message를 정의하는 intent object로 생성된다.

- activities and service의 경우 intent는 수행할 action을 정의하고 시작하려는 component가 작업할 data의 URI를 지정할 수 있습니다.

ㆍex) intent는 image, web page를 여는 action을 convey할 수 있다.


-  in some case에서 activity를 시작하여 result를 intent로 받을 수 있다.

-  broadcast recievers에서 intent는 broadcast되는 announcement를 간단히 정의한다.

ㆍex) battery low broadcast에서는 only include battery is low string만 action에 포함된다.


- activities, services, and broadcast receivers와 달리 content providers는 intent에 의해서 activated되지 않는다.

- rather, ContentResolver의 request에 의해서 targeted될 때 activated된다.

- content resolver는 contents providers와의 모든 transaction을 처리하므로 provider와 component는 content resolver object의 methods를 call할 필요가 없다.

- 이로 인해서 content provider와 component 간에 abstraction layer가 생긴다.

- 각 component의 type을 위한 methods가 나뉘어져 있다.

 Intent to startActivity() or startActivityForResult()

ㆍAndroid 5.0 (API level 21) later, you can use the JobScheduler 

ㆍearlier Android version, Intent to startService()Intent to bindService().

Intent to methods such as sendBroadcast()sendOrderedBroadcast(), or sendStickyBroadcast().

content provider by calling query() on a ContentResolver.


- more informations (Intents and Intent Filters) (Activities, Services BroadcastReceiver, and Content Providers.

)
















공유

댓글