SlideShare a Scribd company logo
1 of 11
Download to read offline
Android Framework
Development
T.V.R.PRASAD
Contents
• Android Framework Design Categories
• Java Framework Components
• Callbacks On Binder
• Native C++ Services
• Binder Callbacks From Native Service
• Ashmem And MemoryFile
• Native Daemon Interacting With Java Framework on Local Sockets
Android Framework Design Categories
Android framework components can be designed and implemented in 3 major categories.
1. Manager class and the corresponding framework service are implemented in Java.
2. Manager class in Java and the framework service is implemented in native layer(C++).
3. Native daemon written in C++ talks to the manager component implemented in Java using
local Sockets.
4. Manager class acts as mere proxy( in cases 1,2) ,checking permissions and delegating the
actual work to the framework service.
Java Framework Components
• Manager is a java class acting as a proxy for the framework service also implemented in Java.
• Listeners/callbacks from the framework can be implemented using binder as the application is a
separate process and the framework service runs in a separate process(probably system server).
• Framework Services can talk to devices using JNI in this method.(Bluedroid source code can be
referred for additional details).
• When using JNI the invocation happens in the same process and doesn’t require Binder.
Callbacks On Binder
Native C++ Services
Services are implemented in the native layer in the
following cases:
• Interaction with hardware device is more.
• Huge data exchange from hardware.
• Have restrictions in using JNI
Reference: AudioFlinger/SurfaceFlinger are implemented
as native services , and can be used as reference.
Following snippet of code represents the main
function of a Native (C++) Service :
//get service manager instance to register the native
service
sp<IServiceManager> sm =
defaultServiceManager();
//Register a service with the SERVICE_NAME
sm->addService(String16(SERVICE_NAME),new
demo_api::DemoAPI());
//Start Service and Loop waiting for requests
ProcessState::self()->startThreadPool();
IPCThreadState::self()->joinThreadPool();
Binder Callbacks From Native Service
• The application can receive callbacks from native services ,in the same way as java services.
• Referring to the aidl file, add Binder transaction numbers for the listeners in sequential order
starting from FIRST_CALL_TRANSACTION in the native service header file.
• Call transact method of the binder object with the binder transaction numbers and the magic
happens ,invoking the corresponding callback in Java layer.
Native Binder Sample
IDummyListener.h
Const int transactionConstant = = IBinder::FIRST_CALL_TRANSACTION;
enum {
ON_PRESSURE_CHANGED = transactionConstant ,
ON_TEMP_CHANGED = transactionConstant + 1,
ON_XXX_VALUE_CHANGED = transactionConstant + 2,
};
IDummyListener.aidl
oneway interface IDummyListener {
void onPressureChanged(int Value);
void onTempChanged(int Value);
void onXXXValueChanged(int State);
}
IDummyListener.cpp
virtual void onPressureChanged(int Value) {
Parcel data, reply;
data.writeInterfaceToken(IDummyListener::getInterfaceDescriptor());
data.writeInt32(Value);
remote()->transact(ON_PRESSURE_CHANGED, data, &reply, IBinder::FLAG_ONEWAY);
}
Ashmem And MemoryFile
• Ashmem, MemoryFile combination helps to avoid memory copies from Java to C++ layer and vice versa.
• Create Ashmem region in the Native C++ daemon
• Pass the file descriptor of the Ashmem region to the framework component running in the Java layer in a
callback.
• Using the file descriptor received create a MemoryFile object and by the Magic of Ashmem ,the data can be
read just like normal stream.
• Saves the “per application” heap(48 MB/64 MB) from growing beyond the limit as data is shared and not
copied into application heap.
Reference:
https://vec.io/posts/andriod-ipc-shared-memory-with-ashmem-memoryfile-and-binder
Native Daemon Interacting With Java
Framework on Local Sockets
• Native daemon written in C++ acts as a Local Server
• Framework component from Java layer connects to the Local Server
• Data and control commands are transferred using the connected socket.
• RILD daemon in Android is a typical example of this type of implementation.
RIL (JAVA)
Rild
(C++)
Sockets
Thank You!

More Related Content

What's hot

Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)fefe7270
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Opersys inc.
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia FrameworkOpersys inc.
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with PieOpersys inc.
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALOpersys inc.
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android WorkshopOpersys inc.
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux DevelopersOpersys inc.
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System ServerOpersys inc.
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting SequenceJayanta Ghoshal
 

What's hot (20)

Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)Embedded Android : System Development - Part IV (Android System Services)
Embedded Android : System Development - Part IV (Android System Services)
 
Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)Embedded Android : System Development - Part II (HAL)
Embedded Android : System Development - Part II (HAL)
 
Explore Android Internals
Explore Android InternalsExplore Android Internals
Explore Android Internals
 
Low Level View of Android System Architecture
Low Level View of Android System ArchitectureLow Level View of Android System Architecture
Low Level View of Android System Architecture
 
Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)Android audio system(audio_hardwareinterace)
Android audio system(audio_hardwareinterace)
 
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
Native Android Userspace part of the Embedded Android Workshop at Linaro Conn...
 
Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Android IPC Mechanism
Android IPC MechanismAndroid IPC Mechanism
Android IPC Mechanism
 
Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)Embedded Android : System Development - Part II (Linux device drivers)
Embedded Android : System Development - Part II (Linux device drivers)
 
Android JNI
Android JNIAndroid JNI
Android JNI
 
Android Binder: Deep Dive
Android Binder: Deep DiveAndroid Binder: Deep Dive
Android Binder: Deep Dive
 
Embedded Android Workshop with Pie
Embedded Android Workshop with PieEmbedded Android Workshop with Pie
Embedded Android Workshop with Pie
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Android's HIDL: Treble in the HAL
Android's HIDL: Treble in the HALAndroid's HIDL: Treble in the HAL
Android's HIDL: Treble in the HAL
 
Embedded Android Workshop
Embedded Android WorkshopEmbedded Android Workshop
Embedded Android Workshop
 
Android for Embedded Linux Developers
Android for Embedded Linux DevelopersAndroid for Embedded Linux Developers
Android for Embedded Linux Developers
 
Understanding the Android System Server
Understanding the Android System ServerUnderstanding the Android System Server
Understanding the Android System Server
 
Android Booting Sequence
Android Booting SequenceAndroid Booting Sequence
Android Booting Sequence
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 

Viewers also liked

Andromeda: An Android Framework for Sensor-based Applications
Andromeda: An Android Framework for Sensor-based ApplicationsAndromeda: An Android Framework for Sensor-based Applications
Andromeda: An Android Framework for Sensor-based ApplicationsRamon Ribeiro Rabello
 
Port Bluedroid to RTOS
Port Bluedroid to RTOSPort Bluedroid to RTOS
Port Bluedroid to RTOSeggmansan
 
Mobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’sMobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’sAdam Wilson
 
ABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting WalkthroughABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting WalkthroughBenjamin Zores
 
Android Framework
Android FrameworkAndroid Framework
Android FrameworkCodeAndroid
 
まったりAndroid Framework Code Reading #4
まったりAndroid Framework Code Reading #4まったりAndroid Framework Code Reading #4
まったりAndroid Framework Code Reading #4Shinobu Okano
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera ArchitecturePicker Weng
 
Android Bluetooth Introduction
Android Bluetooth IntroductionAndroid Bluetooth Introduction
Android Bluetooth IntroductionErin Yueh
 
The Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on LinuxThe Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on LinuxPicker Weng
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedSlideShare
 

Viewers also liked (11)

Andromeda: An Android Framework for Sensor-based Applications
Andromeda: An Android Framework for Sensor-based ApplicationsAndromeda: An Android Framework for Sensor-based Applications
Andromeda: An Android Framework for Sensor-based Applications
 
Port Bluedroid to RTOS
Port Bluedroid to RTOSPort Bluedroid to RTOS
Port Bluedroid to RTOS
 
Mobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’sMobile Application Development with JUCE and Native API’s
Mobile Application Development with JUCE and Native API’s
 
ABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting WalkthroughABS 2013: Android Jelly Bean Device Porting Walkthrough
ABS 2013: Android Jelly Bean Device Porting Walkthrough
 
Android Framework
Android FrameworkAndroid Framework
Android Framework
 
まったりAndroid Framework Code Reading #4
まったりAndroid Framework Code Reading #4まったりAndroid Framework Code Reading #4
まったりAndroid Framework Code Reading #4
 
Android Camera Architecture
Android Camera ArchitectureAndroid Camera Architecture
Android Camera Architecture
 
Android Bluetooth Introduction
Android Bluetooth IntroductionAndroid Bluetooth Introduction
Android Bluetooth Introduction
 
Resume
ResumeResume
Resume
 
The Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on LinuxThe Theory and Implementation of DVFS on Linux
The Theory and Implementation of DVFS on Linux
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 

Similar to Android framework design and development

Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh Kushwah
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyPeter R. Egli
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17aminmesbahi
 
Server side programming
Server side programming Server side programming
Server side programming javed ahmed
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)LearningTech
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...Andrea Dottor
 
Advanced Server Integration with Data and Direct
Advanced Server Integration with Data and DirectAdvanced Server Integration with Data and Direct
Advanced Server Integration with Data and DirectSencha
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & MiddlewaresSantosh Wadghule
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Sri Prasanna
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB
 

Similar to Android framework design and development (20)

Yogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’sYogesh kumar kushwah represent’s
Yogesh kumar kushwah represent’s
 
Android Whats running in background
Android Whats running in backgroundAndroid Whats running in background
Android Whats running in background
 
Micro-services meetup
Micro-services meetupMicro-services meetup
Micro-services meetup
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Overview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technologyOverview of Microsoft .Net Remoting technology
Overview of Microsoft .Net Remoting technology
 
.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17.NET Core, ASP.NET Core Course, Session 17
.NET Core, ASP.NET Core Course, Session 17
 
Server side programming
Server side programming Server side programming
Server side programming
 
Android concurrency
Android concurrencyAndroid concurrency
Android concurrency
 
Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)Auto fac mvc以及進階應用(一)
Auto fac mvc以及進階應用(一)
 
Remoting and serialization
Remoting and serializationRemoting and serialization
Remoting and serialization
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Advanced Server Integration with Data and Direct
Advanced Server Integration with Data and DirectAdvanced Server Integration with Data and Direct
Advanced Server Integration with Data and Direct
 
Rails Request & Middlewares
Rails Request & MiddlewaresRails Request & Middlewares
Rails Request & Middlewares
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Servlet.pptx
Servlet.pptxServlet.pptx
Servlet.pptx
 
Windows 8 Apps and the Outside World
Windows 8 Apps and the Outside WorldWindows 8 Apps and the Outside World
Windows 8 Apps and the Outside World
 
RMI (Remote Method Invocation)
RMI (Remote Method Invocation)RMI (Remote Method Invocation)
RMI (Remote Method Invocation)
 
Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)Rpc Case Studies (Distributed computing)
Rpc Case Studies (Distributed computing)
 
MongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDBMongoDB.local Atlanta: Introduction to Serverless MongoDB
MongoDB.local Atlanta: Introduction to Serverless MongoDB
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 

Android framework design and development

  • 2. Contents • Android Framework Design Categories • Java Framework Components • Callbacks On Binder • Native C++ Services • Binder Callbacks From Native Service • Ashmem And MemoryFile • Native Daemon Interacting With Java Framework on Local Sockets
  • 3. Android Framework Design Categories Android framework components can be designed and implemented in 3 major categories. 1. Manager class and the corresponding framework service are implemented in Java. 2. Manager class in Java and the framework service is implemented in native layer(C++). 3. Native daemon written in C++ talks to the manager component implemented in Java using local Sockets. 4. Manager class acts as mere proxy( in cases 1,2) ,checking permissions and delegating the actual work to the framework service.
  • 4. Java Framework Components • Manager is a java class acting as a proxy for the framework service also implemented in Java. • Listeners/callbacks from the framework can be implemented using binder as the application is a separate process and the framework service runs in a separate process(probably system server). • Framework Services can talk to devices using JNI in this method.(Bluedroid source code can be referred for additional details). • When using JNI the invocation happens in the same process and doesn’t require Binder.
  • 6. Native C++ Services Services are implemented in the native layer in the following cases: • Interaction with hardware device is more. • Huge data exchange from hardware. • Have restrictions in using JNI Reference: AudioFlinger/SurfaceFlinger are implemented as native services , and can be used as reference. Following snippet of code represents the main function of a Native (C++) Service : //get service manager instance to register the native service sp<IServiceManager> sm = defaultServiceManager(); //Register a service with the SERVICE_NAME sm->addService(String16(SERVICE_NAME),new demo_api::DemoAPI()); //Start Service and Loop waiting for requests ProcessState::self()->startThreadPool(); IPCThreadState::self()->joinThreadPool();
  • 7. Binder Callbacks From Native Service • The application can receive callbacks from native services ,in the same way as java services. • Referring to the aidl file, add Binder transaction numbers for the listeners in sequential order starting from FIRST_CALL_TRANSACTION in the native service header file. • Call transact method of the binder object with the binder transaction numbers and the magic happens ,invoking the corresponding callback in Java layer.
  • 8. Native Binder Sample IDummyListener.h Const int transactionConstant = = IBinder::FIRST_CALL_TRANSACTION; enum { ON_PRESSURE_CHANGED = transactionConstant , ON_TEMP_CHANGED = transactionConstant + 1, ON_XXX_VALUE_CHANGED = transactionConstant + 2, }; IDummyListener.aidl oneway interface IDummyListener { void onPressureChanged(int Value); void onTempChanged(int Value); void onXXXValueChanged(int State); } IDummyListener.cpp virtual void onPressureChanged(int Value) { Parcel data, reply; data.writeInterfaceToken(IDummyListener::getInterfaceDescriptor()); data.writeInt32(Value); remote()->transact(ON_PRESSURE_CHANGED, data, &reply, IBinder::FLAG_ONEWAY); }
  • 9. Ashmem And MemoryFile • Ashmem, MemoryFile combination helps to avoid memory copies from Java to C++ layer and vice versa. • Create Ashmem region in the Native C++ daemon • Pass the file descriptor of the Ashmem region to the framework component running in the Java layer in a callback. • Using the file descriptor received create a MemoryFile object and by the Magic of Ashmem ,the data can be read just like normal stream. • Saves the “per application” heap(48 MB/64 MB) from growing beyond the limit as data is shared and not copied into application heap. Reference: https://vec.io/posts/andriod-ipc-shared-memory-with-ashmem-memoryfile-and-binder
  • 10. Native Daemon Interacting With Java Framework on Local Sockets • Native daemon written in C++ acts as a Local Server • Framework component from Java layer connects to the Local Server • Data and control commands are transferred using the connected socket. • RILD daemon in Android is a typical example of this type of implementation. RIL (JAVA) Rild (C++) Sockets