Upload
jan-jongboom
View
502
Download
0
Embed Size (px)
DESCRIPTION
Internals of Firefox OS. Process isolation, difference between Gonk/Gecko/Gaia. Tracing a call to the SMS service from the UI back to the RIL.
Citation preview
From HTML5 to hardware
@janjongboomSimonyi Conference, Budapest, April 15
Tuesday, April 15, 14
@janjongboomTuesday, April 15, 14
I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.
@janjongboomTuesday, April 15, 14
I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.
@janjongboomTuesday, April 15, 14
I’m Jan, live in Amsterdam. Work for Telenor on Mozilla products. Firefox OS contributor & keyboard peer. I write code for Gaia and Gecko.
Tuesday, April 15, 14
Internet is normal for western world, but big part of the world doesnt have it.
Click Only 2.5 billion people out of 7.
4,500,000,000
Tuesday, April 15, 14
Internet is normal for western world, but big part of the world doesnt have it.
Click Only 2.5 billion people out of 7.
The web has everythingInformation does not like to be locked down
Tuesday, April 15, 14
We want people to access the web, not the closed silo’s that Android / iOS are, because thats not where the information is
Affordable device to access the internet
Tuesday, April 15, 14
So goal: affordable device that people can use to get on the internet
Tuesday, April 15, 14
Meet Firefox OS
19,000 HUF
Tuesday, April 15, 14
First generation came out last year. Goes for about 19000 HUF here in Hungary (65 eur)
Tuesday, April 15, 14
Next generation is going to be lower. System requirements are four times as low as Android.
Great performance on cheap hardware?
Tuesday, April 15, 14
So if we want to get great performance out of cheap hardware, how do we do it?
Tuesday, April 15, 14
Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)
Dalvik .NET V8
Tuesday, April 15, 14
Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)
Dalvik .NET V8
Apps Apps Apps
Tuesday, April 15, 14
Traditional model: Application -> VM (f.e. Dalvik on Android; .NET on Windows Phone, JavaScript in V8)
Most mobile OS’es
App
Tuesday, April 15, 14
VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.
Most mobile OS’es
App VM
Tuesday, April 15, 14
VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.
Most mobile OS’es
App VM OS
Tuesday, April 15, 14
VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.
Most mobile OS’es
App VM OS Kernel
Tuesday, April 15, 14
VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.
Most mobile OS’es
App VM OS Kernel Hardware
Tuesday, April 15, 14
VM on top of OS. Kernel is hardware dependent. But always two layers between App and Kernel.
Firefox OS
App
JS VM
Browser
Kernel Hardware
Tuesday, April 15, 14
Firefox OS only has one intermediate layer. The browser. Everything has to go through there. No exceptions like proprietary APIs (ok, well a few)
One application runtimeBrowser runs directly on top of the kernel
Tuesday, April 15, 14
So browser directly on top of the kernel. No overhead.
Everything runs in browserSMS, Payments, Marketplace
Tuesday, April 15, 14
System itself can’t take shortcuts. Everything is browser. Also system apps.
Small Kernel
• Small Linux kernel
• Based on Android Open Source Project
• Contains Hardware Abstraction Layer
• Porting target
• Boot straight into Gecko
Tuesday, April 15, 14
All runs on top of a very small kernel. Based on Android OSP. Contains HAL and boots straight into Gecko. Gecko is browser engine.
WindowsTuesday, April 15, 14
Makes it easier and light weight. Windows: 998 lines of calls to Win32 API on clipboard code.
Firefox OSTuesday, April 15, 14
Firefox OS: 200 lines, just have a var that holds the clipboard. Other stuff is IPC.
Application runtime
Tuesday, April 15, 14
Application runtime is done through iframes. Every application is iframe.
Window Manager
• Boot into HTML app (system)• System is the window manager• Applications are loaded in iframe• iframes can be ran out of process
Tuesday, April 15, 14
The window manager is called the system app. It creates the iframes on demand. There is automatic process isolation in place. For example Here maps.
remote=true
Tuesday, April 15, 14
It’s an iframe that points to a special URL that maps to a location on disk. But it has remote=true.
Tuesday, April 15, 14
Automatic process isolation, and automatic user isolation. Security ftw.
Tuesday, April 15, 14
Automatic process isolation, and automatic user isolation. Security ftw.
Tracing down a SMS messageFrom HTML to the RIL
Tuesday, April 15, 14
All cool, but now let’s talk about some actual code. How does it look like if you make a call from HTML to the RIL.
I NEED AN ADULT!Tuesday, April 15, 14
No clue what the RIL is? I’ll walk you through it.
Tuesday, April 15, 14
We’ll walk over what happens if you click Send, up until the moment it reaches the cell tower.
Gaia
Gecko
Gonk
User Interface
Browser engine
Kernel
Tuesday, April 15, 14
FFOS consists of three layers. Gaia, Gecko, Gonk
Gaia• Frontend• github.com/mozilla-b2g/gaia• All system applications• HTML/CSS/JS• SMS app code under /apps/sms
(that easy!)
Tuesday, April 15, 14
Gaia, open source frontend. Not limited to only run on Gecko (but at the moment it is).
index.html
Tuesday, April 15, 14
SMS app index.html has the button
thread_ui.js
Tuesday, April 15, 14
Button has click handler that goes to MessageManager. There is also a callback involved.
thread_ui.js
Tuesday, April 15, 14
Button has click handler that goes to MessageManager. There is also a callback involved.
thread_ui.js
Tuesday, April 15, 14
Button has click handler that goes to MessageManager. There is also a callback involved.
thread_ui.js
Tuesday, April 15, 14
Button has click handler that goes to MessageManager. There is also a callback involved.
thread_ui.js
Tuesday, April 15, 14
Button has click handler that goes to MessageManager. There is also a callback involved.
message_manager.js
Tuesday, April 15, 14
MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.
message_manager.jsGecko!
Tuesday, April 15, 14
MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.
message_manager.jsGecko!
Tuesday, April 15, 14
MessageManager makes a call to Gecko (under navigator object). Returns a DOMRequest. Like a promise.
We need to go deeper!Tuesday, April 15, 14
So let’s go into Gecko.
Gecko
• Browser engine• Same as Firefox for Desktop / Android / etc.• Runs directly on kernel (B2G)
Tuesday, April 15, 14
Browser engine
nsIDOMMobileMessageManager.idl(yeah, that’s long)
Tuesday, April 15, 14
Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)
nsIDOMMobileMessageManager.idl(yeah, that’s long)
addEventListener
Tuesday, April 15, 14
Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)
nsIDOMMobileMessageManager.idl(yeah, that’s long)
Tuesday, April 15, 14
Gecko has IDL files. These are shared by browser vendors so eveyrone implements the same API. Can be implemented in C++ or JSM (variant of JS)
MobileMessageManager.cppCould also be .jsm
Tuesday, April 15, 14
Inheritance chain. This is written in CPP.
MobileMessageManager.cppCould also be .jsm
Tuesday, April 15, 14
Inheritance chain. This is written in CPP.
MobileMessageManager.cpp
Tuesday, April 15, 14
JS values get boxed automatically. We create a new DOMRequest. See the gaia code.
MobileMessageManager.cpp
Tuesday, April 15, 14
JS values get boxed automatically. We create a new DOMRequest. See the gaia code.
MobileMessageManager.cpp
Tuesday, April 15, 14
JS values get boxed automatically. We create a new DOMRequest. See the gaia code.
MobileMessageManager.cpp
Tuesday, April 15, 14
JS values get boxed automatically. We create a new DOMRequest. See the gaia code.
MobileMessageManager.cpp
Tuesday, April 15, 14
Then in the same function we make a call to the SMS Service. This is platform specific. Android does different than FFOS.
MobileMessageManager.cpp
Services are platform speci!c
Tuesday, April 15, 14
Then in the same function we make a call to the SMS Service. This is platform specific. Android does different than FFOS.
moz.buildService injection at compile time
Tuesday, April 15, 14
This is the service injection in moz.build. Happens at compile time. In android we need Android SMS database access. FFOS we don’t.
moz.buildService injection at compile time
Tuesday, April 15, 14
This is the service injection in moz.build. Happens at compile time. In android we need Android SMS database access. FFOS we don’t.
Tuesday, April 15, 14
Time to go DEEPER
Gonk
• Kernel• Hardware Abstraction• Think of the clipboard example• Android code calls back to Android• We can go straight to the RIL
Tuesday, April 15, 14
Gonk is the kernel. If you have platform dependent code it’s not in Gecko but in Gonk. Target for Gecko.
SmsService.cpp
Tuesday, April 15, 14
Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.
SmsService.cpp
Tuesday, April 15, 14
Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.
SmsService.cpp
Tuesday, April 15, 14
Get the radio interface layer. It’s the API to the chipset in the phone. And send SMS.
dom/system folder
Tuesday, April 15, 14
There are a bunch of platforms, they implement the services. In this case the RIL service is implemented by Gonk.
nsIRadioInterfaceLayer.idl
Tuesday, April 15, 14
Also has IDL definitions.
nsIRadioInterfaceLayer.idl
Tuesday, April 15, 14
Also has IDL definitions.
nsIRadioInterfaceLayer.idl
Tuesday, April 15, 14
Also has IDL definitions.
RadioInterfaceLayer.jsCould also be .cpp
Tuesday, April 15, 14
RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you
RadioInterfaceLayer.jsCould also be .cpp
Tuesday, April 15, 14
RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you
RadioInterfaceLayer.jsCould also be .cpp
Tuesday, April 15, 14
RIL code has been written in javascript in this case. It does stuff like normalizing phone numbers, because the chipset won’t do that for you
RadioInterfaceLayer.js
Tuesday, April 15, 14
Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.
RadioInterfaceLayer.js
Tuesday, April 15, 14
Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.
RadioInterfaceLayer.js
Tuesday, April 15, 14
Now dispatch to a worker. JS single-threaded. Can’t wait for the response from hardware. Response codes are RIL data. Use these to feed back into the DOMRequest.
Tuesday, April 15, 14
rilMessageToken is used to get the callbacks.
Tuesday, April 15, 14
rilMessageToken is used to get the callbacks.
Tuesday, April 15, 14
Something in between to shake up the audience.
ril_worker.js
Tuesday, April 15, 14
Now ril_worker talks to the actual hardware. Pretty simple stuff. Some options.
Mindig írni byte az én RIL!
Tuesday, April 15, 14
I always write bytes to the RIL. RIL doesn’t understand JS or CPP. Only understands bytes.
ril_worker.js
Tuesday, April 15, 14
So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.
ril_worker.js
Tuesday, April 15, 14
So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.
ril_worker.js
Tuesday, April 15, 14
So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.
ril_worker.js
Tuesday, April 15, 14
So now depending on protocol we talk, we dump bytes. SEND_SMS is 25, then some options. Send the parcel and now it’s on the actual RIL.
Radio Interface Layer• Proprietary• Comes with chipset• Trade secret• Delivered to RIL? Done!• See how it looks like?
https://github.com/mozilla-b2g/b2g/
Tuesday, April 15, 14
And that’s where our job is done. RIL is proprietary and comes with chipset. RIL calls back with the token, we bubble it up back to Gecko and eventually Gaia, and show user the feedback. This happens in under a second. There is ref implementtion from Mozilla if you want to look at it.
OMGAWESOMEPlay around? I have devices with me.
Tuesday, April 15, 14
OMG AWESOME SHIT. All open source. I have some devices, including the 25$ phone with me.
Thank you!
slideshare.net/janjongboomTuesday, April 15, 14
Thanks!
slideshare.net/janjongboom
Questions?
Tuesday, April 15, 14
Thanks!