Upload
others
View
5
Download
0
Embed Size (px)
Citation preview
ANDROID NATIVE APP: INTRODUCTION TO ANDROIDRoberto Beraldi
Role of an operating system
OPERATING SYSTEM
CPU MEMORY DEVICES
APPLICATIONS
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’)
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)
Zygote
Preloaded classes
VM VM
FORK
VM
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
Process list
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)
Process management• Foreground(active)
• Visible process
• Service Process
• Hidden Process
• Empty processes
Less likely to be killed
Another example• Check the anchestor
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
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/
Other actions, can you guess?• android.intent.action.DIAL• android.intent.action.MAIN• android.intent.action.SENDTO -d sms:123
File systems (typical)
/System /bin, /xbin/ à Linux binary/frameworks à .jar
/System/app
Example: access to sqlite3
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)
CPU usage
Make and example on the emulator or a real device
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
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.
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)
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
Android versions
8.0
5.0
6.0
7.0NEW
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
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)
Android architecture
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
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).
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
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.• …
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