SlideShare a Scribd company logo
1 of 24
Aayush Gupta
Writing OS Updater App for
Android
Agenda
OS updates & updater app
• Legacy system updates
• Seamless updates
• Writing an OS updater app
Legacy System Updates
Non-A/B devices
• Devices launched before Android
8.0 are known as non-A/B
devices
• Recovery handles the installation
of updates, while cache and
misc partitions store commands
and logs
Legacy system updates
boot
system
vendor
recovery
userdata
cache
misc
Legacy system updates (contd.)
• Device checks and downloads update (either in cache or userdata)
• Update’s signature is verified with system
• Device reboots into recovery mode while loading commands stored in cache
• Recovery (binary) verifies signature of update and installs it
• Device reboots, system updates recovery partition with new image if required
Issues with legacy system updates
• Updater app needs to handle storage space issues
• User is unable to use the device while updating
• After update, rebooting takes longer compared to normal boot
• On update failure, device is affected and user needs to visit service centre in
most cases
Seamless Updates
Seamless updates
A/B devices
• New way to update OS on device since Android 8.0+
• Ensures device has a working bootable system in case of update failure
• Updates are installed in background without affecting device usability
• Storage space issues can be avoided with streaming updates
• A/B system updates contains
two set of partitions for running
system
• Partitions are also known as
slots (slot_a, slot_b)
• System runs on current slot
while other slot remains unused
• Updates are installed by Updater
app in unused slot
Seamless updates (contd.)
userdata
boot_a
system_a
vendor_a
system_b
vendor_b
boot_b
• A/B updates uses a background
daemon called update_engine
• update_engine is responsible for
streaming/installing the update
• update_engine can either install
update from a local file or stream
it directly from remote server
• Once update is installed in unused
slot, update_engine marks it as
active
• System switches to active slot on
reboot
Seamless updates (contd.)
Writing an OS Updater App
• Exists in AOSP’s
bootable/recovery repository
• Showcases basic APIs usage
• Provides python script to
generate update config
• Not compatible with Gradle build
system
• Written in Java and last updated
4+ years ago
AOSP sample app
• Updater needs to connect with
remote server for downloading
and installing updates
• Periodic automatic updates
check and install is required
• Need to handle different kind of
errors
Real world use-case
• Written in Kotlin and Material3
• UI shows different elements
based on status code emitted in
a StateFlow
• Codes emitted in flow contains
both custom and update_engine
codes to accommodate
operations in different stages
CalyxOS’s SystemUpdater
Update stages
IDLE Checking for updates Update Available Preparing to update
Downloading
Verification & Finalising
Updated, needs reboot
Error
Suspended
Update status (API & App)
/**
* Possible status of the Update
*
* This enum holds a combination of both status supplied by update_engine and
* custom ones required for this app. Status from update_engine are followed by custom.
*/
// Keep in sync with: system/update_engine/client_library/include/update_engine/update_status.h
enum class UpdateStatus {
IDLE, // 0
CHECKING_FOR_UPDATE, // 1
UPDATE_AVAILABLE, // 2
DOWNLOADING, // 3
VERIFYING, // 4
FINALIZING, // 5
UPDATED_NEED_REBOOT, // 6
REPORTING_ERROR_EVENT, // 7
ATTEMPTING_ROLLBACK, // 8
DISABLED, // 9
NEED_PERMISSION_TO_UPDATE, // 10
CLEANUP_PREVIOUS_UPDATE, // 11
SUSPENDED, // custom: event when update is suspended
PREPARING_TO_UPDATE, // custom: event sent during payload verification, fetching props
FAILED_PREPARING_UPDATE // custom: event when payload verification or fetching props
fails
}
Listening callbacks (API)
/**
* Callback function for UpdateEngine. Used to keep the caller up to date
* with progress, so the UI (if any) can be updated.
*/
@SystemApi
public abstract class UpdateEngineCallback {
/**
* Invoked when anything changes. The value of {@code status} will
* be one of the values from {@link UpdateEngine.UpdateStatusConstants},
* and {@code percent} will be valid [TODO: in which cases?].
*/
public abstract void onStatusUpdate(int status, float percent);
/**
* Invoked when the payload has been applied, whether successfully or
* unsuccessfully. The value of {@code errorCode} will be one of the
* values from {@link UpdateEngine.ErrorCodeConstants}.
*/
public abstract void onPayloadApplicationComplete(
@UpdateEngine.ErrorCode int errorCode);
}
Listening callbacks (contd.)
init {
// restore last update status to properly reflect the status
restoreLastUpdate()
// handle status updates from update_engine
updateEngine.bind(this)
GlobalScope.launch {
updateStatus.onEach {
when (it) {
UpdateStatus.CHECKING_FOR_UPDATE -> {}
else -> {
sharedPreferences.edit(true) { putString(UPDATE_STATUS, it.name) }
}
}
}.collect()
updateProgress.collect()
}
}
Checking for updates
class UpdateWorker @AssistedInject constructor(
@Assisted val appContext: Context,
@Assisted workerParams: WorkerParameters,
) : CoroutineWorker(appContext, workerParams) {
companion object {
const val WORK_NAME = "UpdateWork"
}
override suspend fun doWork(): Result {
Intent(appContext, SystemUpdaterService::class.java).also {
it.action = SystemUpdaterService.CHECK_AND_APPLY_UPDATES
appContext.startService(it)
}
return Result.success()
}
}
Preparing to update (Verifying metadata)
metadataFile.createNewFile()
val connection = URL(url).openConnection() as HttpsURLConnection
// Request a specific range to avoid skipping through load of data
// Also do a [-1] to the range end to adjust the file size
connection.setRequestProperty(
"Range",
"bytes=${packageFile.offset}-${packageFile.offset + packageFile.size - 1}"
)
connection.inputStream.use { input ->
metadataFile.outputStream().use { input.copyTo(it) }
}
if (!updateEngine.verifyPayloadMetadata(metadataFile.absolutePath)) {
_updateStatus.value = UpdateStatus.FAILED_PREPARING_UPDATE
return@withContext Result.failure(Exception("Failed verifying metadata!"))
}
return@withContext Result.success(true)
Downloading
val propertiesFile = updateConfig.find { it.filename == payloadProperties }
val payloadFile = updateConfig.find { it.filename == payloadBinary }
if (propertiesFile != null && payloadFile != null) {
val properties = fetchPayloadProperties(updateConfig.url, propertiesFile)
if (properties.isSuccess) {
_updateStatus.value = UpdateStatus.DOWNLOADING
updateEngine.applyPayload(
updateConfig.url,
payloadFile.offset,
payloadFile.size,
properties.getOrDefault(emptyArray())
)
}
}
Suspending & resuming
fun suspendUpdate() {
updateEngine.suspend()
_updateStatus.value = UpdateStatus.SUSPENDED
}
fun resumeUpdate() {
restoreLastUpdate()
updateEngine.resume()
}
Errors
• Common errors that can occur are usually related to permissions
• Ensure the OS uses proper CA certificates
• Write SELinux rules for update_engine and app
• Verify metadata and other files have proper rw permissions
• Allow updater app to run in background for proper operations
Thank You!

More Related Content

What's hot

Use case diagrams 2014
Use case diagrams 2014Use case diagrams 2014
Use case diagrams 2014Inge Powell
 
Structured systems analysis and design methodology
Structured systems analysis and design methodologyStructured systems analysis and design methodology
Structured systems analysis and design methodologyVatsana Technologies Pte Ltd
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine DiagramNiloy Rocker
 
Giới thiệu phần mềm tự do (FTA: An Introduction to Open Source
Giới thiệu phần mềm tự do (FTA: An Introduction to Open SourceGiới thiệu phần mềm tự do (FTA: An Introduction to Open Source
Giới thiệu phần mềm tự do (FTA: An Introduction to Open SourceVu Hung Nguyen
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagramsbarney92
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Modelsohailsaif
 
Mô hình hóa yêu cầu
Mô hình hóa yêu cầuMô hình hóa yêu cầu
Mô hình hóa yêu cầuNguyen Tran
 
Analysis modeling in software engineering
Analysis modeling in software engineeringAnalysis modeling in software engineering
Analysis modeling in software engineeringMuhammadTalha436
 
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPT
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPTBài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPT
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPTMasterCode.vn
 
07 interaction diagrams
07 interaction diagrams07 interaction diagrams
07 interaction diagramsBaskarkncet
 

What's hot (20)

Ooad sequence diagram lecture
Ooad sequence diagram lectureOoad sequence diagram lecture
Ooad sequence diagram lecture
 
Use case diagrams 2014
Use case diagrams 2014Use case diagrams 2014
Use case diagrams 2014
 
Sequence Diagram
Sequence DiagramSequence Diagram
Sequence Diagram
 
Class based modeling
Class based modelingClass based modeling
Class based modeling
 
Structured systems analysis and design methodology
Structured systems analysis and design methodologyStructured systems analysis and design methodology
Structured systems analysis and design methodology
 
State Machine Diagram
State Machine DiagramState Machine Diagram
State Machine Diagram
 
Giới thiệu phần mềm tự do (FTA: An Introduction to Open Source
Giới thiệu phần mềm tự do (FTA: An Introduction to Open SourceGiới thiệu phần mềm tự do (FTA: An Introduction to Open Source
Giới thiệu phần mềm tự do (FTA: An Introduction to Open Source
 
Uml sequence diagrams
Uml sequence diagramsUml sequence diagrams
Uml sequence diagrams
 
Patterns
PatternsPatterns
Patterns
 
Uml diagrams
Uml diagramsUml diagrams
Uml diagrams
 
Major and Minor Elements of Object Model
Major and Minor Elements of Object ModelMajor and Minor Elements of Object Model
Major and Minor Elements of Object Model
 
Mô hình hóa yêu cầu
Mô hình hóa yêu cầuMô hình hóa yêu cầu
Mô hình hóa yêu cầu
 
Model based development(MBD)
Model based development(MBD) Model based development(MBD)
Model based development(MBD)
 
Analysis modeling in software engineering
Analysis modeling in software engineeringAnalysis modeling in software engineering
Analysis modeling in software engineering
 
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPT
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPTBài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPT
Bài 2: Các khái niệm trong CSDL quan hệ - Giáo trình FPT
 
07 interaction diagrams
07 interaction diagrams07 interaction diagrams
07 interaction diagrams
 
Unified Modeling Language
Unified Modeling LanguageUnified Modeling Language
Unified Modeling Language
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Class diagram
Class diagramClass diagram
Class diagram
 
class diagram
class diagramclass diagram
class diagram
 

Similar to Writing OS Updater App for Android

Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updatesGary Bisson
 
Upgrade to IBM z/OS V2.4 technical actions
Upgrade to IBM z/OS V2.4 technical actionsUpgrade to IBM z/OS V2.4 technical actions
Upgrade to IBM z/OS V2.4 technical actionsMarna Walle
 
WMUG NL Tuesday - Latest and greatest in the world of Configuration Manager
WMUG NL Tuesday - Latest and greatest in the world of Configuration ManagerWMUG NL Tuesday - Latest and greatest in the world of Configuration Manager
WMUG NL Tuesday - Latest and greatest in the world of Configuration ManagerTim De Keukelaere
 
Taking your “web” app to places you never expected - Ember Fest 2014
Taking your “web” app to places you never expected - Ember Fest 2014Taking your “web” app to places you never expected - Ember Fest 2014
Taking your “web” app to places you never expected - Ember Fest 2014williamsgarth
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteorSapna Upreti
 
New microsoft office word document (3)
New microsoft office word document (3)New microsoft office word document (3)
New microsoft office word document (3)raghuraj15
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoShedrack Akintayo
 
Steps for Upgrade OutSystems platform.pdf
Steps for Upgrade OutSystems platform.pdfSteps for Upgrade OutSystems platform.pdf
Steps for Upgrade OutSystems platform.pdfRicardoPereira244364
 
Bring and distribute your dekstop applications on the Universal Windows Platf...
Bring and distribute your dekstop applications on the Universal Windows Platf...Bring and distribute your dekstop applications on the Universal Windows Platf...
Bring and distribute your dekstop applications on the Universal Windows Platf...Matteo Pagani
 
Apache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app developmentApache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app developmentwebprogr.com
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
R12 d49656 gc10-apps dba 26
R12 d49656 gc10-apps dba 26R12 d49656 gc10-apps dba 26
R12 d49656 gc10-apps dba 26zeesniper
 
Application engine
Application engineApplication engine
Application engineJAYAARC
 
Xen mobile 8.5_migration_whitepaper
Xen mobile 8.5_migration_whitepaperXen mobile 8.5_migration_whitepaper
Xen mobile 8.5_migration_whitepaperNuno Alves
 
Wally Mead - Upgrading to system center 2012 r2 configuration manager
Wally Mead - Upgrading to system center 2012 r2 configuration managerWally Mead - Upgrading to system center 2012 r2 configuration manager
Wally Mead - Upgrading to system center 2012 r2 configuration managerNordic Infrastructure Conference
 
Odoo shipworks Integration
Odoo shipworks IntegrationOdoo shipworks Integration
Odoo shipworks IntegrationEr. Jay Vora
 
R12 d49656 gc10-apps dba 03
R12 d49656 gc10-apps dba 03R12 d49656 gc10-apps dba 03
R12 d49656 gc10-apps dba 03zeesniper
 
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptx
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptxUiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptx
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptxRohit Radhakrishnan
 

Similar to Writing OS Updater App for Android (20)

Android OTA updates
Android OTA updatesAndroid OTA updates
Android OTA updates
 
Upgrade to IBM z/OS V2.4 technical actions
Upgrade to IBM z/OS V2.4 technical actionsUpgrade to IBM z/OS V2.4 technical actions
Upgrade to IBM z/OS V2.4 technical actions
 
WMUG NL Tuesday - Latest and greatest in the world of Configuration Manager
WMUG NL Tuesday - Latest and greatest in the world of Configuration ManagerWMUG NL Tuesday - Latest and greatest in the world of Configuration Manager
WMUG NL Tuesday - Latest and greatest in the world of Configuration Manager
 
Taking your “web” app to places you never expected - Ember Fest 2014
Taking your “web” app to places you never expected - Ember Fest 2014Taking your “web” app to places you never expected - Ember Fest 2014
Taking your “web” app to places you never expected - Ember Fest 2014
 
Reactive application using meteor
Reactive application using meteorReactive application using meteor
Reactive application using meteor
 
New microsoft office word document (3)
New microsoft office word document (3)New microsoft office word document (3)
New microsoft office word document (3)
 
Optimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayoOptimizing your use of react life cycles by shedrack akintayo
Optimizing your use of react life cycles by shedrack akintayo
 
Steps for Upgrade OutSystems platform.pdf
Steps for Upgrade OutSystems platform.pdfSteps for Upgrade OutSystems platform.pdf
Steps for Upgrade OutSystems platform.pdf
 
Bring and distribute your dekstop applications on the Universal Windows Platf...
Bring and distribute your dekstop applications on the Universal Windows Platf...Bring and distribute your dekstop applications on the Universal Windows Platf...
Bring and distribute your dekstop applications on the Universal Windows Platf...
 
Apache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app developmentApache Cordova phonegap plugins for mobile app development
Apache Cordova phonegap plugins for mobile app development
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Browser_Stack_Intro
Browser_Stack_IntroBrowser_Stack_Intro
Browser_Stack_Intro
 
R12 d49656 gc10-apps dba 26
R12 d49656 gc10-apps dba 26R12 d49656 gc10-apps dba 26
R12 d49656 gc10-apps dba 26
 
Application engine
Application engineApplication engine
Application engine
 
Xen mobile 8.5_migration_whitepaper
Xen mobile 8.5_migration_whitepaperXen mobile 8.5_migration_whitepaper
Xen mobile 8.5_migration_whitepaper
 
Wally Mead - Upgrading to system center 2012 r2 configuration manager
Wally Mead - Upgrading to system center 2012 r2 configuration managerWally Mead - Upgrading to system center 2012 r2 configuration manager
Wally Mead - Upgrading to system center 2012 r2 configuration manager
 
Odoo shipworks Integration
Odoo shipworks IntegrationOdoo shipworks Integration
Odoo shipworks Integration
 
Application slides
Application slidesApplication slides
Application slides
 
R12 d49656 gc10-apps dba 03
R12 d49656 gc10-apps dba 03R12 d49656 gc10-apps dba 03
R12 d49656 gc10-apps dba 03
 
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptx
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptxUiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptx
UiPath_Orchestrtor_Upgrade_IAAS_PAAS.pptx
 

Recently uploaded

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Writing OS Updater App for Android

  • 1. Aayush Gupta Writing OS Updater App for Android
  • 2. Agenda OS updates & updater app • Legacy system updates • Seamless updates • Writing an OS updater app
  • 4. Non-A/B devices • Devices launched before Android 8.0 are known as non-A/B devices • Recovery handles the installation of updates, while cache and misc partitions store commands and logs Legacy system updates boot system vendor recovery userdata cache misc
  • 5. Legacy system updates (contd.) • Device checks and downloads update (either in cache or userdata) • Update’s signature is verified with system • Device reboots into recovery mode while loading commands stored in cache • Recovery (binary) verifies signature of update and installs it • Device reboots, system updates recovery partition with new image if required
  • 6. Issues with legacy system updates • Updater app needs to handle storage space issues • User is unable to use the device while updating • After update, rebooting takes longer compared to normal boot • On update failure, device is affected and user needs to visit service centre in most cases
  • 8. Seamless updates A/B devices • New way to update OS on device since Android 8.0+ • Ensures device has a working bootable system in case of update failure • Updates are installed in background without affecting device usability • Storage space issues can be avoided with streaming updates
  • 9. • A/B system updates contains two set of partitions for running system • Partitions are also known as slots (slot_a, slot_b) • System runs on current slot while other slot remains unused • Updates are installed by Updater app in unused slot Seamless updates (contd.) userdata boot_a system_a vendor_a system_b vendor_b boot_b
  • 10. • A/B updates uses a background daemon called update_engine • update_engine is responsible for streaming/installing the update • update_engine can either install update from a local file or stream it directly from remote server • Once update is installed in unused slot, update_engine marks it as active • System switches to active slot on reboot Seamless updates (contd.)
  • 11. Writing an OS Updater App
  • 12. • Exists in AOSP’s bootable/recovery repository • Showcases basic APIs usage • Provides python script to generate update config • Not compatible with Gradle build system • Written in Java and last updated 4+ years ago AOSP sample app
  • 13. • Updater needs to connect with remote server for downloading and installing updates • Periodic automatic updates check and install is required • Need to handle different kind of errors Real world use-case
  • 14. • Written in Kotlin and Material3 • UI shows different elements based on status code emitted in a StateFlow • Codes emitted in flow contains both custom and update_engine codes to accommodate operations in different stages CalyxOS’s SystemUpdater
  • 15. Update stages IDLE Checking for updates Update Available Preparing to update Downloading Verification & Finalising Updated, needs reboot Error Suspended
  • 16. Update status (API & App) /** * Possible status of the Update * * This enum holds a combination of both status supplied by update_engine and * custom ones required for this app. Status from update_engine are followed by custom. */ // Keep in sync with: system/update_engine/client_library/include/update_engine/update_status.h enum class UpdateStatus { IDLE, // 0 CHECKING_FOR_UPDATE, // 1 UPDATE_AVAILABLE, // 2 DOWNLOADING, // 3 VERIFYING, // 4 FINALIZING, // 5 UPDATED_NEED_REBOOT, // 6 REPORTING_ERROR_EVENT, // 7 ATTEMPTING_ROLLBACK, // 8 DISABLED, // 9 NEED_PERMISSION_TO_UPDATE, // 10 CLEANUP_PREVIOUS_UPDATE, // 11 SUSPENDED, // custom: event when update is suspended PREPARING_TO_UPDATE, // custom: event sent during payload verification, fetching props FAILED_PREPARING_UPDATE // custom: event when payload verification or fetching props fails }
  • 17. Listening callbacks (API) /** * Callback function for UpdateEngine. Used to keep the caller up to date * with progress, so the UI (if any) can be updated. */ @SystemApi public abstract class UpdateEngineCallback { /** * Invoked when anything changes. The value of {@code status} will * be one of the values from {@link UpdateEngine.UpdateStatusConstants}, * and {@code percent} will be valid [TODO: in which cases?]. */ public abstract void onStatusUpdate(int status, float percent); /** * Invoked when the payload has been applied, whether successfully or * unsuccessfully. The value of {@code errorCode} will be one of the * values from {@link UpdateEngine.ErrorCodeConstants}. */ public abstract void onPayloadApplicationComplete( @UpdateEngine.ErrorCode int errorCode); }
  • 18. Listening callbacks (contd.) init { // restore last update status to properly reflect the status restoreLastUpdate() // handle status updates from update_engine updateEngine.bind(this) GlobalScope.launch { updateStatus.onEach { when (it) { UpdateStatus.CHECKING_FOR_UPDATE -> {} else -> { sharedPreferences.edit(true) { putString(UPDATE_STATUS, it.name) } } } }.collect() updateProgress.collect() } }
  • 19. Checking for updates class UpdateWorker @AssistedInject constructor( @Assisted val appContext: Context, @Assisted workerParams: WorkerParameters, ) : CoroutineWorker(appContext, workerParams) { companion object { const val WORK_NAME = "UpdateWork" } override suspend fun doWork(): Result { Intent(appContext, SystemUpdaterService::class.java).also { it.action = SystemUpdaterService.CHECK_AND_APPLY_UPDATES appContext.startService(it) } return Result.success() } }
  • 20. Preparing to update (Verifying metadata) metadataFile.createNewFile() val connection = URL(url).openConnection() as HttpsURLConnection // Request a specific range to avoid skipping through load of data // Also do a [-1] to the range end to adjust the file size connection.setRequestProperty( "Range", "bytes=${packageFile.offset}-${packageFile.offset + packageFile.size - 1}" ) connection.inputStream.use { input -> metadataFile.outputStream().use { input.copyTo(it) } } if (!updateEngine.verifyPayloadMetadata(metadataFile.absolutePath)) { _updateStatus.value = UpdateStatus.FAILED_PREPARING_UPDATE return@withContext Result.failure(Exception("Failed verifying metadata!")) } return@withContext Result.success(true)
  • 21. Downloading val propertiesFile = updateConfig.find { it.filename == payloadProperties } val payloadFile = updateConfig.find { it.filename == payloadBinary } if (propertiesFile != null && payloadFile != null) { val properties = fetchPayloadProperties(updateConfig.url, propertiesFile) if (properties.isSuccess) { _updateStatus.value = UpdateStatus.DOWNLOADING updateEngine.applyPayload( updateConfig.url, payloadFile.offset, payloadFile.size, properties.getOrDefault(emptyArray()) ) } }
  • 22. Suspending & resuming fun suspendUpdate() { updateEngine.suspend() _updateStatus.value = UpdateStatus.SUSPENDED } fun resumeUpdate() { restoreLastUpdate() updateEngine.resume() }
  • 23. Errors • Common errors that can occur are usually related to permissions • Ensure the OS uses proper CA certificates • Write SELinux rules for update_engine and app • Verify metadata and other files have proper rw permissions • Allow updater app to run in background for proper operations