0% found this document useful (0 votes)
43 views

Android OS notes

Uploaded by

mukombrandon3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

Android OS notes

Uploaded by

mukombrandon3
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Android Operating System

Title: Basics of the Android Operating System


1. Introduction to Android
Android is a mobile operating system developed by Google, primarily for touchscreen devices
such as smartphones and tablets.
Release: Launched in 2008, initially created by Android Inc., later acquired by Google in 2005.
Open Source: Based on a modified version of the Linux kernel, Android is open-source, meaning
developers can modify and adapt the software.
2. Key Features
User Interface: Android’s UI is intuitive, touch-responsive, and customizable, supporting gestures
like swiping, tapping, and pinching.
Applications (Apps):
Android supports millions of apps, downloadable from Google Play Store.
Apps can also be installed via APK files.
Multitasking: Supports running multiple apps simultaneously, allowing for background processes
and task switching.
Notifications: Real-time alerts appear on the home screen or notification panel, displaying
messages, reminders, and other app updates.
Customization: Highly customizable with widgets, themes, and icon packs, allowing users to
personalize their experience.
3. Versions of Android
Naming Convention: Initially named after desserts (e.g., Cupcake, Lollipop), Android later
switched to numerical versions.
Updates: Regular updates improve performance, security, and introduce new features.
Recent Versions: Current versions include Android 12, Android 13, and updates to these continue.
ANDROID ARCHITECTURE
Android architecture is structured in layers to simplify development, testing, and maintenance.
Each layer is responsible for different aspects of the Android operating system and provides
specific functionality. The key layers in Android architecture include:
• Linux Kernel
• Hardware Abstraction Layer (HAL)
• Android Runtime (ART)
• Native C/C++ Libraries
• Java API Framework
• System Applications

Let’s break down each layer:


1. Linux Kernel
The Linux kernel is the core component of the Linux operating system and serves as the
fundamental layer that interacts directly with a computer’s hardware. It plays a critical role in
managing system resources, providing an interface for applications, and ensuring system stability
and security. In the context of Android, it’s the underlying layer of the Android OS architecture.

Key Functions of the Linux Kernel:


• Process Management:
The kernel manages all processes running on a system. It schedules processes, allocates CPU
time, and handles multitasking.
This management ensures that each application receives a fair amount of processing time and
allows multiple applications to run concurrently without interfering with each other.
• Memory Management:
The kernel controls how memory is allocated to different processes and applications.
It manages the allocation and deallocation of memory to ensure efficient use of system memory,
handles virtual memory, and prevents memory leaks.
• Device Drivers:
Linux kernel includes drivers that allow it to communicate with and control hardware
components like storage, network interfaces, input devices, display, and more.
By abstracting hardware details, drivers make it easier for software applications to interact with
the hardware without needing to know its specifics.
• File System Management:
The kernel manages file systems, which organize how data is stored and retrieved on storage
devices.
• Networking:
The kernel includes networking components that handle communication between devices over
networks.
• Security and Permissions:
The kernel enforces security policies, including access control, permissions, and isolation
between processes.
• Hardware Abstraction:
Why Linux Kernel for Android?
Google chose the Linux kernel for Android due to its stability, security features, and broad
hardware support. The kernel also has an open-source license, which allows Google to customize
and extend it to meet Android’s unique requirements, such as improved power management and
memory efficiency.

2. Hardware Abstraction Layer (HAL)


The Hardware Abstraction Layer (HAL) is a layer in Android that acts as an intermediary between
the operating system and the hardware components of a device.
It defines standard interfaces that provide a consistent way for the higher-level Android system
components (like the Android Framework and apps) to access hardware without knowing its
specific details.

Key Purposes of the Hardware Abstraction Layer:


• Abstraction of Hardware Details:
HAL abstracts the hardware specifics, providing a standard interface for Android to access
hardware components (e.g., camera, GPS, sensors, etc.) regardless of the manufacturer or model.
• Modular Design for Hardware Components:
HAL is modular, with individual HAL modules for each hardware component (like display, audio,
camera, etc.), allowing each component to be managed separately.
• Enabling Android Framework to Interact with Hardware:
HAL allows the Android Framework and apps to make hardware requests in a standardized way.
For instance, when an app uses the camera, it doesn’t interact directly with the camera hardware.
Instead, it interacts with the camera HAL, which translates the request to work with the specific
hardware.
• Device Compatibility:
HAL ensures compatibility across a wide range of hardware components, making it easier for
Android to run on different devices.

How HAL Works in Android


Each hardware component in Android has a corresponding HAL module, typically written in C or
C++. These HAL modules are specific to each hardware component and contain the functions
necessary to control and interact with that hardware.
For example: Camera HAL: Provides an interface for Android’s camera service to access and
control the camera hardware.

3. Android Runtime (ART)


Android Runtime (ART) is the managed runtime environment used by the Android operating
system to execute applications. ART is responsible for running and managing applications written
in Java (and Kotlin, which compiles to Java bytecode). It replaced the earlier Dalvik runtime
starting from Android 5.0 (Lollipop) and brings various performance and efficiency
improvements.
Key Features and Components of Android Runtime (ART)
• Ahead-of-Time (AOT) Compilation:
ART compiles app bytecode (Java Virtual Machine bytecode) into native machine code during app
installation. This is known as Ahead-of-Time (AOT) compilation.
By compiling the code at install time, ART can execute applications faster since there’s no need
for Just-In-Time (JIT) compilation during runtime.
• Just-In-Time (JIT) Compilation:
Although ART primarily relies on AOT compilation, it also supports Just-In-Time (JIT) compilation.
JIT compiles parts of the bytecode that are frequently used during runtime and optimizes them
on-the-fly.
• Garbage Collection (GC):
Garbage Collection is the automatic process of identifying and reclaiming memory used by
objects that are no longer needed, helping prevent memory leaks.
• Improved Debugging and Diagnostic Support:
ART provides more detailed error messages and diagnostic tools, making it easier for developers
to identify and troubleshoot issues in applications.
• Optimized Power and Performance:
ART’s AOT compilation and optimized garbage collection help reduce CPU load and improve
battery life. Less frequent compilation during runtime means fewer demands on system
resources.

4. Native C/C++ Libraries


The native C/C++ libraries in Android are a collection of system-level libraries written in C and
C++. These libraries are part of the Android operating system’s architecture and provide core
functionality, such as graphics rendering, database management, media playback, and more.
They are crucial for high-performance operations, especially in resource-intensive tasks like
multimedia processing and graphics.
These libraries are located between the Android Runtime (ART) and Linux Kernel layers in the
Android architecture, and they are accessed by the Android Framework and system components
to provide essential services for applications.

Key Native C/C++ Libraries in Android


• Bionic C Library (libc):
Bionic is Android’s own implementation of the standard C library (libc), adapted specifically for
Android to meet its needs.
It provides standard C library functions like memory allocation, threading, and file operations.
• Media Framework:
The media framework provides essential functions for handling audio and video playback,
recording, and media processing.
Components :
OpenMAX AL (Open Media Acceleration Layer): Used for audio, video, and image decoding and
encoding.
Stagefright: Android’s native multimedia library for media playback, supporting formats like
MP4, AVI, and MP3.
• Surface Manager:
Manages the display and compositing of 2D and 3D graphics for apps.
• OpenGL ES:
Provides APIs for 2D and 3D graphics rendering.
• SQLite:
A lightweight, embedded database engine for storing relational data.
• WebKit:
Provides the foundation for web content rendering in Android.
• SSL/TLS Library (BoringSSL):
Provides secure connections over networks by handling encryption and decryption protocols.
• Libc++ (C++ Standard Library):
Implements the C++ standard library, providing essential C++ functionalities like containers,
algorithms, and I/O operations.

Importance of Native C/C++ Libraries in Android


• Optimized Performance for Mobile: Native C/C++ libraries are highly optimized and are
designed for the performance constraints of mobile devices.
• High-Level Abstraction for Developers: While these libraries perform low-level tasks,
Android’s Java API provides high-level abstractions, making it easier for app developers
to use these functions without diving into C/C++ code.
• Security and Reliability: Core system operations (like network security, storage, and
graphics rendering) rely on these libraries, making them essential to Android’s stability
and security.
• Power Efficiency: By handling resource-intensive tasks more efficiently, these libraries
contribute to better battery life and smoother user experiences on mobile devices.

5. Java API Framework


The Java API Framework in Android is a set of Java classes and interfaces that provide core
functionalities for Android app development. This framework abstracts complex tasks and gives
developers a high-level, unified interface to interact with the underlying system components,
hardware, and services without having to directly manage low-level or hardware-specific details.
It includes various APIs for essential tasks like UI design, file access, network communication,
notifications, and hardware interaction.
The framework is part of the Android architecture and sits above the Android Runtime (ART) and
native libraries. This enables app developers to interact with system services, hardware, and
other system components in a simplified, consistent manner.

Key Components of the Java API Framework

• Application Components (Activities, Services, Broadcast Receivers, Content Providers):


Activities: Provide the UI and handle user interaction. Each screen in an Android app is typically
managed by an activity.
Services: Background components that handle long-running operations without a user interface
(e.g., music playback, data sync).
Broadcast Receivers: Handle system-wide broadcast messages, such as system events (battery
level changes, Wi-Fi status updates).
Content Providers: Manage access to structured data (such as contacts or files) within and across
applications.

• User Interface (UI) Framework:


Provides various UI elements (like buttons, text fields, lists) and a flexible layout system to build
the app’s user interface.
• Resource Manager:
Handles access to non-code resources like images, strings, colors, and layouts, allowing
developers to manage resources separately from code.
• Location and Sensor Services:
Location Services: Provides APIs for getting the device’s geographic location and managing
location updates, allowing for GPS and network-based location tracking.
Sensor Framework: Gives access to hardware sensors (e.g., accelerometer, gyroscope, proximity
sensor) to enable features like motion tracking and orientation detection.
• Data Storage and Database Access:
Shared Preferences: Provides a lightweight storage solution for key-value pairs, ideal for app
settings and user preferences.
SQLite Database: Enables structured data storage using SQL queries. It’s useful for managing
relational data in local storage.
File System Access: Allows apps to read and write files on internal and external storage.

• Notification Manager:
Manages app notifications that can appear in the system status bar, alerting users to events even
if the app is in the background.
• Network and Internet APIs:
HTTP/HTTPS Communication, WebView, Media and Camera Framework
• Package Manager:
Handles app installation, updates, and permissions management.
• Bluetooth and NFC APIs:
Bluetooth API, NFC API: Enables Near Field Communication, useful for mobile payments, data
exchange, and device pairing over NFC.
• Telephony and SMS Services:
Allows apps to access telephony services like phone calls and SMS messages.
• Security and Permissions Framework:
Manages app permissions to enforce user privacy and security.

6. System Applications
System applications in Android are apps pre-installed by the device manufacturer or operating
system, providing core functionalities essential for the device to function smoothly. These apps
are part of the operating system’s essential software suite and are usually installed in the /system
partition, which is separate from the user’s data partition. System apps often have elevated
permissions and access to protected system resources, enabling them to perform tasks that
regular third-party apps cannot.

Key Characteristics of System Applications

• Pre-installed and Integral to Device Functionality:


System applications come pre-installed on the device when you buy it. Examples include the
Phone app, Contacts, Settings, Messages, and Camera apps.They provide essential functionality
that allows the device to operate and meet basic user expectations.
• Special Permissions and Elevated Privileges:
Unlike regular apps, system apps have elevated permissions that allow them to access restricted
system resources and settings.
• Protected System Partition:
System applications are stored in the /system partition of the device’s internal storage, which is
generally read-only. This protects them from being modified or deleted by users or third-party
apps.
• Direct Integration with System Services and Hardware:
System applications are tightly integrated with Android system services, making them more
efficient and responsive. For instance, the Phone app is directly tied to telephony services.
• Automatic Updates via OTA (Over-The-Air) or Play Store:
System applications can be updated by the device manufacturer through Over-The-Air (OTA)
updates. In newer versions of Android, some system apps may also be updated via the Google
Play Store.
• Cannot Be Uninstalled (Non-rooted Devices):
On non-rooted devices, users generally cannot uninstall system apps, though they may disable
them if not required (e.g., disabling a pre-installed browser).
Examples of Common System Applications
Phone, Messaging, Settings, Camera, Contacts, Calendar, File Manager.

Types of System Applications


• Core System Apps:
These are fundamental applications required for basic device functionality, such as the Phone,
Settings, Contacts, and Messages apps.
• System Utility Apps:
These apps provide additional but non-essential functionality, like Calculator, Clock, and File
Manager.
• Pre-installed Apps from OEMs or Carriers:
Often, OEMs (Original Equipment Manufacturers) and network carriers pre-install their apps on
devices, such as a custom gallery app, email client, or even third-party partner apps.
Diagram of Android Architecture

Here’s a simplified textual representation of the diagram:


The Activity Lifecycle
The Activity Lifecycle in Android OS defines how activities (screens or interfaces) are created,
managed, and destroyed as users interact with them. Each activity goes through a sequence of
states from launch to termination, handled by the Android system. This lifecycle ensures the app
responds properly to user actions and system events like low memory or configuration changes.
Here's an overview of the key lifecycle methods and the transitions between them:

1. onCreate()
- Purpose: Initializes the activity. Called only once when the activity is created.
- Common Actions: Set up UI elements, initialize variables, and configure components like
RecyclerViews, buttons, etc.
2. onStart()
- Purpose: Marks the activity as visible to the user.
- Common Actions: Start animations or resources needed for the visible activity. This is the last
call before the activity is visible but not yet interacting with the user.
3. onResume()
- Purpose: Makes the activity interactive.
- Common Actions: Start receiving input, resume animations, or start any exclusive resources
like GPS or sensors. This is where the activity is fully on-screen and in the foreground.
4. onPause()
- Purpose: Indicates that the activity is partially obscured (e.g., by a dialog) but still visible.
- Common Actions: Pause ongoing tasks, animations, or sensitive actions. Release resources not
needed while the activity is in a paused state, like sensor listeners.
5. onStop()
- Purpose: Makes the activity fully invisible.
- Common Actions: Stop heavy operations like network calls or resource-intensive tasks. Release
or save data if needed.
6. onDestroy()
- Purpose: Called before the activity is destroyed, either because it’s being closed or due to
configuration changes.
- Common Actions: Clean up resources, cancel background tasks, or save any persistent state.
7. onRestart()
- Purpose: Called if the activity is being restarted after being stopped.
- Common Actions: Reload resources that were released during `onStop()` and prepare the
activity to be re-started.

Activity Lifecycle Flow


Here’s a general flow of how these methods interact:
- App launch: onCreate() → onStart() → onResume()
- Navigate away: onPause() → onStop()
- Return to activity: onRestart() → onStart() → onResume()
- Close activity: onPause() → onStop() → onDestroy()

Activity Lifecycle Callbacks with System Events


- Configuration Changes (e.g., rotation): onPause() → onStop() → onDestroy(), then restart with
onCreate().
- Memory Constraints: Activities may be destroyed to free memory, transitioning through
onPause(), onStop(), and potentially onDestroy().

Android Application Components


Android application components are the essential building blocks of an Android app. These
components enable developers to handle different types of functionalities in their apps, such as
managing the UI, interacting with the user, handling background processes, and managing inter-
component communication. There are four main types of Android application components:
1. Activities
2. Services
3. Broadcast Receivers
4. Content Providers

1. Activities
An Activity represents a single screen with a user interface. It's the component that manages the
UI and is responsible for user interaction. Activities work in a stack, meaning each new Activity
starts on top of the previous one, creating a back stack that allows the user to navigate backward.
Example: Imagine an e-commerce app. When you open the app, you’re presented with a list of
products—this is managed by a "ProductListActivity." If you click on a product, the app takes you
to a new screen with product details, which is handled by "ProductDetailActivity." Here, each
screen (or "Activity") represents a different task or function in the app, allowing for an organized
flow of user interaction.
Key Characteristics:
• Each activity has its own lifecycle, including states like created, started, resumed, paused,
stopped, and destroyed.
• They are launched using intents, which are messages that request an action.
• Activities can be organized into a task, a series of activities that the user interacts with.

2. Services

A Service is a component that performs operations in the background without a user interface.
Services are used for long-running tasks, such as playing music, downloading files, or syncing
data with a server.

Key Characteristics:

• Services do not have a user interface.


• They can be started and stopped by other components, such as activities or other
services.
• Services can be bound to other components to allow communication and data sharing.

Example: Suppose you’re using a music streaming app like Spotify. When you play a song and
exit the app, the music continues to play in the background. This is possible because of a
Service that keeps running even if the user isn’t actively engaging with the app’s UI. The service
handles the music playback while you perform other tasks on your device.

3. Broadcast Receivers

A Broadcast Receiver is a component that responds to broadcast messages from the system or
other applications. Broadcast messages can be events like system notifications (battery low,
connectivity change) or custom notifications sent by other apps. Broadcast Receivers enable
apps to respond to these events, even when they are not actively running.

Key Characteristics:
• Broadcast receivers do not have a user interface.
• They are registered in the AndroidManifest.xml file and can be declared as either
explicit or implicit.
• They are short-lived and execute only while receiving a broadcast.

Example: Consider a messaging app that notifies you when a new message arrives. When the
device receives a notification of a new message (via a broadcast), a Broadcast Receiver in the
app listens for this broadcast and shows a notification to inform you. Another example is a "low
battery" broadcast, which might prompt an app to reduce its background activity to save
battery.

4. Content Providers

A Content Provider manages access to a structured set of data. It provides an interface for data
sharing between applications. Content Providers are often used to store app data in a way that
allows other apps to securely access it.

Key Characteristics:

• Content providers define a set of APIs that allow other apps to query, insert, update,
and delete data.
• They can be implemented using different data storage mechanisms, such as SQLite
databases or files.

Example: The Contacts app in Android uses a Content Provider to manage your contacts'
information. This allows other apps, like messaging or email apps, to access contact data and
display contact names instead of just phone numbers. For example, if you download a third-
party messaging app, it may request permission to access your contacts through the Contacts
Content Provider to make the messaging experience more seamless.

Android development environment


1. Introduction to Android Development
Android development involves creating applications for Android devices, ranging from phones
and tablets to watches, TVs, and even cars. Here’s a comprehensive guide to Android
development fundamentals, tools, and key concepts:
2: Android Development Basics
• Programming Languages:
• Java: The traditional language for Android development.
• Kotlin: Modern, concise, and now the preferred language for Android
development.
• XML: Used for designing UI layouts.
• Platform: Android development primarily targets Android OS, but cross-platform options
are available.
3: Android Studio: The Official IDE
• What is Android Studio?
It’s an Official Integrated Development Environment (IDE) for Android. It Provides a complete
suite of tools to design, build, test, and debug Android apps efficiently.
• Features:
• Code Editor with intelligent code completion.
• Android Virtual Device (AVD) Manager for emulating devices.
• Built-in profiling tools and APK analyzer.
4: Setting Up the Android Development Environment

• System Requirements:
• Minimum OS: Windows, macOS, or Linux.
• Recommended: At least 8GB RAM and SSD storage.
• Installation:
• Download Android Studio from the official Android Developer website.
• Follow the setup wizard to install necessary SDKs and tools.
• Additional Tools:
• JDK (Java Development Kit): Required for Java/Kotlin development.
• Gradle: Android’s build automation tool.
• Emulators/AVD: Virtual devices for testing apps.

5. Android SDK and SDK Manager


• Android SDK (Software Development Kit):
• Collection of tools, libraries, and APIs required for Android development.
• SDK Manager:
• Manages Android SDKs, system images, and additional libraries.
• Allows downloading different API levels to test compatibility.

6. Build and Dependency Management


• Gradle:
• Build automation tool integrated with Android Studio.
• Manages app building, testing, and dependencies.
• Build Variants:
• Configures multiple versions of an app (e.g., free vs. paid).
• Dependency Management:
• Integrates third-party libraries like Retrofit, Firebase, and more.
7. Testing and Debugging Tools
• Android Emulator:
• Simulates Android devices on your computer.
• Test apps on different screen sizes, API levels, and network conditions.
• Debugging Tools:
• Logcat: Real-time logging tool.
• Android Profiler: Analyzes app performance, memory usage, and battery impact.
• Unit Testing:
• Write unit tests to ensure code reliability.
• Frameworks: JUnit for unit tests, Espresso for UI tests.
8. Project Deployment
• Building an APK:
• APK (Android Package) is the installation file for Android apps.
• Can be generated via the "Build" menu in Android Studio.
• Publishing on Google Play Store:
• Sign APK for release to Google Play.
• Set up a developer account, prepare app metadata, and follow guidelines for
publishing.

You might also like