This presentation on Android OS contains basic and core concepts of Android Operation System, like Android Architecture, Dalvik Virtual Machine, Process Management, Memory Management, Application and Service life cycle, etc...
2. 1. INTRODUCTION
2. ARCHITECTURE
3. Dalvik Virtual Machine(DVM)
4. Process Management
5. Memory Management
6. Application and Service Lifecycle
3. Android is Mobile(Device) Based OS.
Which is based on Linux 2.6 kernel.
Android Inc.(founded in 2003 and is based in Palo Alto,
California) which operated as subsidiary of Google and later
purchased by Google in 2005.
OHA Est. 5th Nov 2007, led by Google, open Source.
Open source under the Apache 2 license.
Android was publicly announced in 2007 and first phone was
sold on October 2008.
HTC was First to deliver ANDROID Mobile Device.
4.
5. • Linux kernel
• Libraries
• Android run time
– core libraries
– Dalvik virtual machine
• Application layer
• Application protocol
6.
7. Acts as an abstraction layer between the hardware and the
rest of the software stack.
Relies on Linux version 2.6 for core system services such as
security, memory management, process management,
network stack, and driver model.
Works as a HAL (Hardware Abstraction Layer or
rather Hardware Annotation Library)
8. System C library - implementation of the C library (libc).
Media Libraries - based on PacketVideo's Open CORE.
Surface Manager - composites 2D and 3D graphic layers
LibWebCore - a modern embeddable web view.
SGL - the underlying 2D graphics engine.
3D libraries - based on OpenGL ES 1.0 APIs; the libraries use
hardware 3D acceleration.
FreeType - bitmap and vector font rendering
SQLite - a powerful and lightweight relational database
engine .
9. Includes a set of core libraries of JAVA that provides most of
the functionality
Runs in its own process, with its own instance of the Dalvik
Virtual Machine
The Dalvik VM executes files in the Dvbalvik Executable
(.dex)
Compact and efficient than class files
Limited memory and battery power
10. Access location information, run background services, set
alarms, add notifications to the status bar, and much, much
more.
Build an application, including lists, grids, text boxes,
buttons, and even an embeddable web browser
Providing access to non-code resources such as localized
strings, graphics, and layout files.
Activity manager manages application life cycle.
Content provider Enable applications access data from
other applications.
11. resource manager which gives us access to non court
resources such as localized strings or various others, we can
layout so many resources, we can have in the form of PNG,
BMP as well as XML so resource manager helps us to get
access to those non code resources.
Notification manager which helps us to display custom
alerts on status bar.
location managers it handles information about the location.
telephony manager which handles information about telephony.
12.
13.
14. POP 20
POP 7
ADD 20, 7, result
PUSH result
Stack Based
Virtual Machine(ex.JVM)
16. A special Java Virtual Machine(VM) designed
to run with limited system resource.
It is basically a virtual machine for embedded
devices, which like any other virtual machine,
is a byte code interpreter.
it means it is low on memory, comparatively
slower and runs on battery power.
Google is modify DVM according to the
Android OS is named as Dalvik Turbo
virtual machine.
Java class file are converted into “.dex” Files
that Dalvik executes
Java byte code is converted into Dalvik byte-code
during this process
17. For each application android creates a new process with
single thread of execution(i.e. main thread)
By default all the components run in same thread(main
thread) If not developer explicitly creates a new thread.
In low memory situations a process is decide to kill based
upon the number of inactive components of that
process.
A process which have more number of inactive components
should be killed first.
18. A process is treated as foreground if any of components
of process holds following states.
An activity which is interacting with user. When an
activity calls methods like onstart(), onresume().
When a service is interacting with foreground activity.
When a service is started using startForeground().
when a service is executing any of the methods like
onCreate(),onStart(), onDestroy().
19. Visible, but inactive processes are those hosting
“visible” Activities. As the name suggests, visible
Activities are visible, but they aren’t in the foreground
or responding to user events.
This happens when an Activity is only partially obscured
(by a non-full-screen or transparent Activity).
There are generally very few visible processes, and
they’ll only be killed in extreme circumstances to allow
active processes to continue.
An activity which is not interacting with user. But it is
still visible to user, when an activity running method like
onPause().
20. Processes hosting Services that have been started.
Services support ongoing processing that should
continue without a visible interface.
Because Services don’t interact directly with the user,
they receive a slightly lower priority than visible
Activities.
They are still considered to be foreground processes and
won’t be killed unless resources are needed for active or
visible processes.
When a service is started using startService().
Eg: playing music in background, downloading file from
internet.
21. Processes hosting Activities that aren’t visible and that
don’t have any Services that have been started are
considered background processes.
There will generally be a large number of background
processes that Android will kill using a last-seen-first-killed
pattern to obtain resources for foreground
processes.
When an activity running method like onStop().
i.e currently user is not interacting with that activity.
Whenever a process decided to kill, it stores the state of
activity. So whenever next time user wants that activity,
we can restore the previous state of activity.
22. To improve overall system performance, Android often
retains applications in memory after they have reached
the end of their lifetimes.
Android maintains this cache to improve the start-up
time of applications when they’re re-launched.
These processes are routinely killed as required.
When a process does not have any active component.
Caching of empty process inside memory, reduces
relaunching of application once again if user wants that
application in future.
23. Page-based memory management
Virtual address to physical address mapping
No virtual memory
24. Android’s process and memory management is a little unusual.
Like Java and .NET, Android uses its own run time and virtual machine
to manage application memory.
Unlike either of these frameworks, the Android run time also manages
the process lifetimes.
Android ensures application responsiveness by stopping and killing
processes as necessary to free resources for higher-priority applications.
Each Android application runs in a separate process within its own Dalvik
instance, relinquishing all responsibility for memory and process
management to the Android run time, which stops and kills processes as
necessary to manage resources.
Dalvik Virtual Machine Dalvik is a register-based virtual machine that’s
been optimized to ensure that a device can run multiple instances
efficiently. It relies on the Linux kernel for threading and low-level
memory management.
25. The order in which processes are killed to
reclaim resources is determined by the
priority of the hosted applications. An
application’s priority is equal to its highest-priority
component.
Where two applications have the same
priority, the process that has been at a lower
priority longest will be killed first.
Process priority is also affected by inter-process
dependencies
if an application has a dependency on a
Service or Content Provider supplied by a
second application, the secondary
application will have at least as high a
priority as the application it supports.
All Android applications will remain running
and in memory until the system needs its
resources for other applications.
26. Application run in their own processes (VM, PID)
Processes are started and stopped as needed to run an
application's components
Processes may be killed to reclaim resources
Activity Manager :Manages the lifecycle of applications
Content provider : Enable applications access data from other applications
Resource Manager : Providing access to non-code resources
Window Manager
Notification manager
SQLite Databases: relational database library for storing and managing complex data
Files: you can create, write, and read files from the local storage or external media (SD Cards)
FileOutputStream, FileInputStream, and Resources classes.
=======================================================
Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.
All applications are written using the Java programming language.
Built in and user apps.
Can replace built in apps.
Activity Manager :Manages the lifecycle of applications
Content provider : Enable applications access data from other applications
Resource Manager : Providing access to non-code resources
Window Manager
Notification manager
SQLite Databases: relational database library for storing and managing complex data
Files: you can create, write, and read files from the local storage or external media (SD Cards)
FileOutputStream, FileInputStream, and Resources classes.
=======================================================
Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.
All applications are written using the Java programming language.
Built in and user apps.
Can replace built in apps.
Activity Manager :Manages the lifecycle of applications
Content provider : Enable applications access data from other applications
Resource Manager : Providing access to non-code resources
Window Manager
Notification manager
SQLite Databases: relational database library for storing and managing complex data
Files: you can create, write, and read files from the local storage or external media (SD Cards)
FileOutputStream, FileInputStream, and Resources classes.
=======================================================
Set of core applications including an email client, SMS program, calendar, maps, browser, contacts.
All applications are written using the Java programming language.
Built in and user apps.
Can replace built in apps.
A stack based virtual machine implements the general features described as needed by a virtual machine in the points above, but the memory structure where the operands are stored is a stack data structure. Operations are carried out by popping data from the stack, processing them and pushing in back the results in LIFO (Last in First Out) fashion. In a stack based virtual machine, the operation of adding two numbers would usually be carried out in the following manner (where 20, 7, and ‘result’ are the operands):
Because of the PUSH and POP operations, four lines of instructions is needed to carry out an addition operation.
An advantage of the stack based model is that the operands are addressed implicitly by the stack pointer (SP in above image). This means that the Virtual machine does not need to know the operand addresses explicitly, as calling the stack pointer will give (Pop) the next operand. In stack based VM’s, all the arithmetic and logic operations are carried out via Pushing and Popping the operands and results in the stack.
As I mentioned earlier, there is no POP or PUSH operations, so the instruction for adding is just one line.
But unlike the stack, we need to explicitly mention the addresses of the operands as R1, R2, and R3.
The advantage here is that the overhead of pushing to and popping from a stack is non-existent, and instructions in a register based VM execute faster within the instruction dispatch loop.
Another advantage of the register based model is that it allows for some optimizations that cannot be done in the stack based approach. One such instance is when there are common sub expressions in the code, the register model can calculate it once and store the result in a register for future use when the sub expression comes up again, which reduces the cost of recalculating the expression.
The problem with a register based model is that the average register instruction is larger than an average stack instruction, as we need to specify the operand addresses explicitly.
Whereas the instructions for a stack machine is short due to the stack pointer, the respective register machine instructions need to contain operand locations, and results in larger register code compared to stack code.
Every Android application runs in its own process, with its own instance of the Dalvik virtual machine. Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the Dalvik Executable (.dex) format which is optimised for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included “dx” tool.
Android programs are compiled into .dex (Dalvik Executable) files, which are in turn zipped into a single .apk file on the device. .dex files can be created by automatically translating compiled applications written in the Java programming language.