Android PPT (1) .
Android PPT (1) .
• ARCHITECTURE
• PROCESS MANAGEMENT
• MODE SWITCH AND PROCESS SWITCH
• THREAD MANAGEMENT
• MEMORY PARTITIONING
• MEMORY MANAGEMENT
Android introduction:
Definition:
Android is an open source and Linux based OS. Before we move on,
we understand some terms.
What is Operating system:
An operating system or OS is a
software program that enables
the Hardware to communicate &
operate with the Software.
• An operating system act as an interface between user and
hardware.
• An operating system provide a software platform on the top
of which other program run, called Application Software.
What is Linux:
Linux is a family of free and open source software
operating systems built around the Linux kernel.
Before we move on, we understand some terms.
Open Source:(License Free)
1.The source code of the computer program is made available
free of charge to the general public.
2.User can view the code that comprise
the software and make any kind of changes
to it they want.
3.Anyone can take the source code and
4.distribute their own program from it.
History of Operating System
• Android Inc. was founded in Palo Alto, California, in October
2003 by Andy Rubin, Rich Miner, Nick Sears, and Chris White
• The early intentions of the company were to develop an
advanced operating system for digital cameras, and this was the
basis of its pitch to investors in April 2004
• The company then decided that the market for cameras was not
large enough for its goals, and five months later it had diverted
its efforts and was pitching Android as a handset operating
system that would rival Symbian and Microsoft Windows Mobile
• In 2005, Rubin tried to negotiate deals with Samsung[19] and HTC.[20] Shortly
afterwards, Google acquired the company in July of that year for at least
$50 million, this was Google's "best deal ever"
• . The
first commercially available smartphone running Android was the
HTC Dream, also known as T-Mobile G1, announced on September 23, 2008.
Linux kernel layer:
• Heart of OS
• Contains hardware drivers (display, audio, camera)
• Level of abstraction between hardware and rest of software
stack
• Provide functionalities like process management, Memory
management and power management .
LIBRARIES
Consist of two parts
•System libraries
•android runtime
System libraries
•Collection of useful system functions written in C or C++
•called from the application framework and application through a java interface.
SQL: for data management
Media framework: supports Vedio recording and playing in mp3
Open GL: graphics rendering apis for 2D and 3D
WebKit : web browser used to display internet content
Android runtime
•core libraries
•ART (android runtime)
Core libraries
•Core libraries enable android developers to write android applications using stranded java programming
language
•Core feature
DVM(dalvik virtual mechanic)
• provide runtime environment to our
Application
ART
•The Android runtime, known as ART, is the managed runtime used by Android applications.
• It replaces the older Dalvik runtime and is responsible for executing and managing Android app code.
•ART uses Ahead-of-Time (AOT) compilation, converting app bytecode into native machine code during
installation, which can result in improved performance compared to the older Just-In-Time (JIT) compilation used
by Dalvik.
Application Framework
The Application Framework layer provides high-level
building blocks, accessible through standardized APIs, that programmers use to create new
apps
Some of the key Application Framework components are:
• Activity Manager: Manages lifecycle of applications.
• telephone manager: interaction with phone and SMS
• Package Manager: Installs and removes applications.
• location manager
Applications
• All the applications with which the user interacts directly are
part of the application layer.
•This includes set of general-purpose applications,
such as SMS program, calendar, maps, browser, contacts
•native applications
•Third party applications
Components of
Application
• Activity:
Represent a single screen visible to user
interface.
• Service:
Used to perform background information.
• Broadcast receivers:
Responds to system wide broadcast
announcement.
• Content providers:
Acts as an intermediary between an application
and its underlying data source, allowing different apps to
securely share data.
Activity state Transition Diagram
onCreate():
Does the static setup of the activity.
onStart():
Makes the activity visible to the user on
the screen.
onResume():
Passes control to the activity so user
input goes to the activity.
onPause():
System call, which places the currently
running activity on the stack, putting it in
the Paused state.
onStop( ):
To stop the activity.
On destroy( ):
Destroy the activity.
Service Lifecycle
• Unbound Service:
Unbound services, run
independently without a direct connection
to the component that started them.
• Bound Service:
Bound services are components
that allow other components
(like activities or other services)
to bind to them,
Types of Process:
• Foreground
• Visible process
• Service process
• Background process
• Empty process
Thread Management in Android
Threads
Each process is divided into threads
• UI/Main Thread
• Background Threads
Creation
Only Main Thread is created by system for a new process. Other threads
are to be created manually. We can create threads other than main
thread, by either of following methods:
• By Thread Class
• By Runnable Interface
UI Thread
• Created by system when app is launched
• Bridge between UI and other threads
• Any other thread cannot interact with UI, so all functionalities including UI have to be
served by UI Thread
Background Threads
If a task is very resource intensive (time consuming), then it runs in background thread
e.g., Infinite loop in Main Thread, network operations, database calls, etc.
States of Thread
Inter-Thread Communication
• Message Queue
The Message Queue is a queue that has a list of tasks (messages,
runnables) that will be executed in a certain thread.
• Looper
A Looper provides a message loop for a thread. The message loop
continually checks the message queue for incoming messages and processes
them one by one.
• Handler
This class is responsible for enqueuing any task to the message queue and
processing it.
Visual Representation
PROCESS AND MODE SWITCHING OF ANDROID
PROCESS SWITCHING
in the Android operating system, the process switching mechanism is
handled by the kernel's scheduler, which is responsible for managing
the CPU's allocation to various processes
the process switching mechanism in Android:
Scheduler:
preemptive schedular:(Android typically uses the Linux kernel, which
employs various scheduling policies to handle tasks running on the
system).
CFS (Completely Fair Scheduling):
( It ensures fairness by allocating CPU time slices to different tasks)
Context Switching:
saving the state (context) of the currently running process
Process Control Block (PCB):
Each process has its PCB, which holds essential information about the process,
such as process ID, state, priority, memory pointers,and CPU state. When a
context switch occurs, the PCB of the new process is loaded, and its execution
resumes.
Example:
Switching between youtube and music player
MODE SWITCHING:
MODES:
USER MODE:(user intallaed application run, restricted(limited access to
system resources)
KERNAL MODE:(full accesss to all system resources)
mode switch happened:
1:system call
2:error and exceptions etc.....
3:intrrupt(Hardware events like pressing a button, receiving data, or device
errors can trigger interrupts).
Example:(sending text message)
Memory Partitioning
• Fixed partitioning
• The system allocates fixed-size partitions of memory for different purposes, such as system
processes, applications, and user data.
• Helps allocate resources efficiently but may lead to suboptimal use of memory if
partition sizes are not well-balanced for varying workloads.
• Role of the kernel
• Crucial role by handling memory allocation and access control.
• Each partition has the necessary resources and enforces security measures to prevent
unauthorized access.
• Communication between the operating system and hardware components, contributing to the
overall stability and performance of the device.
Drawbacks
• Limited Flexibility:
May lead to inflexibility in adapting to varying storage needs.
• Storage Efficiency:
Depending on the usage pattern, fixed partitioning might result in
inefficient use of storage.
For example, if the user data partition is too small, users may face
issues with insufficient storage for apps, media, or other data.
• System Updates:
Android system updates often require a certain amount of free
space. If the system partition is too small, users might face challenges in
installing updates, which can impact security and feature access
Dynamic Partitioning
• Dynamic partitioning in Android refers to the storage
partitioning scheme introduced with Android 10.
• It allows the system to create, resize, and manage partitions
dynamically, adapting to varying storage needs.
• This flexibility enables more efficient use of device storage
and facilitates seamless system updates by isolating the
system and vendor components from user data.
• Impact :
Dynamic partitioning allows for more efficient utilization of device
storage by dynamically adjusting the size of partitions based on the specific needs
of the system, leading to better optimization of available space
• Improve System Updates :
Dynamic partitioning in Android devices allows for more efficient system updates
by splitting the system partition into multiple slots.
When an update is installed, it occurs in a separate slot, enabling the device to
use the existing partition until the update is ready to be activated. This reduces
downtime during updates, as the system can seamlessly switch between slots,
minimizing the time the device is offline during the update process.
Dynamic partitioning works in
relation to system and vendor
partitions
• System Partition
It contains the Android OS and system files. Dynamic partitioning allows the system
partition to be resized dynamically during updates, preventing the need for a large,
fixed-size partition.
• Vendor Partition
It houses vendor-specific files, drivers, and customizations. Dynamic partitioning enables
more efficient use of space, as the vendor partition can be adjusted dynamically to
accommodate changes without affecting the user's data. Overall, dynamic partitioning
enhances flexibility in managing system and vendor partitions, making it easier to
update and customize Android devices.
Memory Management
For optimizing device performance
Ensuring smooth multitasking
Preventing application crashes
Android OS based on Linux Kernal
ZRAM
Storage
ZRAM:
ZRAM may be partition on RAM.
The low priority data that is currently running on the RAM, the system
actively doesn’t need , so it does compress it and store in ZRAM.
Memory Allocation
Androids memory manager Allocate memory to app as needed. It
can occur through:
Heap Memory
Garbage Collection Mechanism
DVM or ART
Memory Deallocation
Android memory manager Deallocate memory when it is no longer
in use. It is done by:
Garbage Collection
Weak References
(Android OS use weak references to allow abjects to
be garbage collection, preventing strong reference.)
MAT
( Memory Analyzer Tool is used to identify memory leaks in
Android applications.)
Paging
Memory (RAM) are divided into Pages , generally size is 4KB.
Android make MORE FREE MEMORY by shift data on used pages
into storage.
Pages