android native app: introduction to androidberaldi/macc/04_introductionandroidoperating... ·...
TRANSCRIPT
![Page 1: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/1.jpg)
ANDROID NATIVE APP: INTRODUCTION TO ANDROIDRoberto Beraldi
![Page 2: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/2.jpg)
Role of an operating system
OPERATING SYSTEM
CPU MEMORY DEVICES
APPLICATIONS
![Page 3: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/3.jpg)
Android = OS + Middleware• Based on Linux• Not just another distribution. • There are important changes related to
• PROCESS MANAGEMENT• MEMORY MANAGMENET• IPC
• OS uses several “Managers” to take its decisions:• Activity Manager• Packeges Manager
• An Application runs inside a Process. • An application is composed of smaller components,
singularly managed (have a ‘lifecycle’)
![Page 4: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/4.jpg)
Process Management in android• Processes host applications
• Processes running applications are all created from the sameprocess, called Zygote (not fork and exec as in linux, only fork)
• Zygote contains a pre-warmed execution environment, i.e. required to all app run (e.g., jvm, libraries, etc..).
• This reduces the start-up time
• All components run in the same thread.. (but thread can/must be created)
![Page 5: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/5.jpg)
Zygote
Preloaded classes
VM VM
FORK
VM
![Page 6: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/6.jpg)
Interacting via shell• ABD is a tool used to interact with the Android OS
• It gives a limited shell where (some) classical Linux command can be issued, e.g., uname, ps, df, ls,..
• ADB can be attached to emulator or real device
• See some real example, just to have a flavor
• A full system access is obtained installing termux app
![Page 7: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/7.jpg)
Process list
![Page 8: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/8.jpg)
Process management• Out of memory (OOM) a state where no additional memory
can be allocated for use by programs or the operating system.
• OOM killer is the mechanism the kernel uses to recovermemory by killing processes
• In Android, OOM killer is different from tradition linux because
• Processes are ranked according to the state of the containedapplication
• After killed, an application can be resuemed (the OS allows to persist the app state across kill/resume)
![Page 9: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/9.jpg)
Process management• Foreground(active)
• Visible process
• Service Process
• Hidden Process
• Empty processes
Less likely to be killed
![Page 10: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/10.jpg)
Another example• Check the anchestor
![Page 11: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/11.jpg)
Sandboxing• Each process that runs an anapplication belongs to a
unique and different user• Files created by an app then cannot be read from other
apps• Inter-Process (app-to-app) communication via Intent
![Page 12: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/12.jpg)
Inter-process communication• App-to-app communication occurs using a kind of a ‘message’ called
INTENT
• An intent can either for an explicit target application (or app component, see later)
• or the sender wants to perform an action, but it has no idea about whchapplication can do it (implicit intent)
• why? can be useful .. for what?
• Example (just to play…), run them from adb shell.
• am start -a android.intent.action.VIEW http://www.diag.uniroma1.it• am start -a android.intent.action.VIEW content://contacts/people/
![Page 13: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/13.jpg)
Other actions, can you guess?• android.intent.action.DIAL• android.intent.action.MAIN• android.intent.action.SENDTO -d sms:123
![Page 14: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/14.jpg)
File systems (typical)
![Page 15: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/15.jpg)
/System /bin, /xbin/ à Linux binary/frameworks à .jar
![Page 16: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/16.jpg)
/System/app
![Page 17: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/17.jpg)
Example: access to sqlite3
![Page 18: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/18.jpg)
CPU management• To reduce battery drain CPU frequency is reduced (1GHz à 50 MHz)
• Standby• Deep sleep (set a timer to weak up)
• Wakelocks (avoid the CPU go to sleep)
![Page 19: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/19.jpg)
CPU usage
Make and example on the emulator or a real device
![Page 20: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/20.jpg)
Security management (basic stuff) • Secure boot chain
• Only signed OS from known origin can be loaded• Integrity, Authenticity
• OS Update• Downgrade not possible
• Application isolation (user per app)• Sandbox
• Permission-based access control• Users grant/revoke permissions to make sensible operations
• Application signing• Only signed apps can be installed (e.g., from Apple)• Updates must come from the same developer
![Page 21: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/21.jpg)
Higher level resource management• Package Manager – The system by which applications are able to find
out information about other applications currently installed on the device.
• Telephony Manager – Provides information to the application about the telephony services available on the device such as status and subscriber information.
• Location Manager – Provides access to the location services allowing an application to receive updates about location changes.
• Activity Manager – Controls all aspects of the application lifecycle and activity stack.
• Resource Manager – Provides access to non-code embedded resources such as strings, color settings and user interface layouts.
• Notifications Manager – Allows applications to display alerts and notifications to the user.
![Page 22: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/22.jpg)
Running an app the traditional way
• The OS manages processes providing the execution environment
• Call fork and then execOPERATING SYSTEM
User Process
Run-time support
Code to run
Signal Sys callStac
k,he
apSw
libra
ries,
etc
App can system call the OSOS can send sw interruptsCan be ignored, but SIGSEGV,..Handler can be registered
Service
System Process (Deamon)
![Page 23: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/23.jpg)
Running app in android
OPERATING SYSTEM
ZygoteDaemons
Server Process
AppProcess
AppProcess
Server process contains all the android managersAll processes are forked from ZYGOTE (slow start up time)
Activty manager…
All managers in one process
![Page 24: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/24.jpg)
Android versions
8.0
5.0
6.0
7.0NEW
![Page 25: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/25.jpg)
Android fragmentation ..
OS update brings new features…
Not all manufactures update the OS…
How to solve this problem?
Applications then ‘remain old’..
Support libraries and GPS
![Page 26: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/26.jpg)
Support libraries• As new features are added (e.g., toolbar, actionbar,
fragments,…) support libraries are developed, so that such features are also available to older android versions• v4 support, v7 appcompat,etc.. (see documentation)
• Android API are very dynamic, so it can happen that some method or widget are deprecated (always take a look at the official documentation)
![Page 27: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/27.jpg)
Android architecture
![Page 28: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/28.jpg)
Android architecture (kernel)• Provides a level of abstraction between the device
hardware and it contains all the essential hardware drivers like camera, keypad, display etc.
• Implement network stack, multitasking, etc..• Binder is a special driver designed to provide secure
communication between apps
![Page 29: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/29.jpg)
Android architecture: ART
• Introduced with android 5 (before DVM)• Register based architecture• Code runs directly on hw (as opposed to DVM)• Each app runs in its own process and with its own
instance of the Android Runtime (ART).
![Page 30: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/30.jpg)
Native SW libraries (C/C++)
Surface Manager:Rendering of Views2D graphics
Open GL ES2D and 3D graphics
Media Framework:Manage different codec, e.g.mp3,H.264,MPEG4,etc.
Web engine
(Bionic)C standard library
![Page 31: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/31.jpg)
Android framework
• The entire feature-set of the Android OS is available through Java packages.• android.app – Provides access to the application model and is the cornerstone of all Android
applications.• android.content – Facilitates content access, publishing and messaging between
applications and application components.• android.database – Used to access data published by content providers and includes SQLite
database management classes.• android.graphics – A low-level 2D graphics drawing API including colors, points, filters,
rectangles and canvases.• android.hardware – Presents an API providing access to hardware such as the accelerometer
and light sensor.• …
![Page 32: ANDROID NATIVE APP: INTRODUCTION TO ANDROIDberaldi/MACC/04_IntroductionAndroidOperating... · Inter-process communication • App-to-app communication occurs using a kind of a ‘message’](https://reader033.vdocuments.mx/reader033/viewer/2022042308/5ed48db03d6f7d64f90679cd/html5/thumbnails/32.jpg)
Bird’s eye view to application’s components
User Interface• Views/Layouts• Activity• Fragment
Computation• Service/Activity • Broadcast receiver
• May use separate thread • Implements the “business logic”
UI runs in a thread à responsiveness
Data
• Preference• File• SQLite• Content provider• Cloud
• Many ways to store data
Material design