Hacking Gaia with Firefox OS Simulator (Updated)
Published on March 29, 2014.
Almost a year ago Salvador de la Puente GonzΓ‘lez wrote a post (under CC-BY) about hacking Firefox OS default user applications (named Gaia) using the browser Simulator.
This is a updated version of Salvador’s post with parts of Salvador’s original.
Step 0: set-up
Install the nightly version of Firefox. You will find the files needed at Nightly build page. After install the nightly version start it.
{width=“25%”}
In the menu bar (you need to press “Alt” to show it) go to “Tools” -> “Web Developer” -> “App Manager” or enter “about:app-manager” in the URL bar.
{width=“25%”}
In the bottom of the page you will find a “Start Simulator”, click on it.
{width=“25%”}
Click on “Add”.
{width=“25%”}
Click on “Install Simulator”.
{width=“25%”}
Click on the Simulator version that you want to install (you can choose the 1.3 since it will soon became the stable one). It will download the Simulator and install it (this step can take some minutes depending of your internet connection).
After install the Simulator goes back to App Manager.
{width=“25%”}
Select the Simulator version that you want to use. A new windows will appear with Firefox OS (running under the Simulator).
{width=“25%”}
On the left of the App Manager there are some tabs. Select the “Device” one.
{width=“25%”}
This is a list of all the webapps available in your Simulator.
For now you can close the window with Firefox OS. We will come back to it in the last step.
Step 1: build Gaia
The source code of Gaia is available at GitHub. Let’s download it:
$ git clone https://github.com/mozilla-b2g/gaia.git
And move inside gaia directory:
$ cd gaia
To build Gaia:
$ make
After finishing, youβll end with a new folder called profile. The profile in Firefox OS is the same as in Firefox, it holds the extensions (nope, you can not develop extensions for Firefox OS), user preferences and, in this case, the webapps pre-installed in the device.
So you have Nightly, Firefox OS Simulator and latest Gaia with a working profile. The concept is simple: the Simulator uses a static Gaia profile to run the simulation. The Simulator profile has a webapps folder inside with all Gaiaβs applications. We are going to replace some of these application by those in our profile.
Step 2: hacking the keyboard
Open apps/keyboard/js/keboard.js with your favorite editor. Search for
“Normal key” and goes to some text like:
// Normal key
- default:
- if (target.dataset.compositekey) {
// Keys with this attribute set send more than a single character // Like “.com” or “2nd” or (in Catalan) “lΒ·l”. var compositeKey = target.dataset.compositekey; for (var i = 0; i < compositeKey.length; i++) { inputMethod.click(compositeKey.charCodeAt(i)); }
} else { inputMethod.click(keyCode); } break;
}
}
Below the default keyword, add:
console.log('Key pressed: ' + keyCode);
Save and close your editor. Regenerate the profile with:
$ make
$ tree -L 1 profile
profile
+ββ defaults
+ββ extensions
+ββ settings.json
+ββ user.js
+ββ webapps
3 directories, 2 files
$ tree -L 1 profile/webapps
profile/webapps
+ββ {27c3437c-8608-49f5-ad4a-9706600fa6d4}
+ββ {8301cfeb-0dff-4d20-98ae-d33967b7e9ca}
+ββ bluetooth.gaiamobile.org
+ββ browser.gaiamobile.org
+ββ calendar.gaiamobile.org
+ββ camera.gaiamobile.org
+ββ clock.gaiamobile.org
+ββ communications.gaiamobile.org
+ββ costcontrol.gaiamobile.org
+ββ {d6caaa1c-64b6-449e-bc70-70990eb94553}
+ββ demo-keyboard.gaiamobile.org
+ββ ds-test.gaiamobile.org
+ββ email.gaiamobile.org
+ββ emergency-call.gaiamobile.org
+ββ fl.gaiamobile.org
+ββ fm.gaiamobile.org
+ββ gallery.gaiamobile.org
+ββ geoloc.gaiamobile.org
+ββ homescreen.gaiamobile.org
+ββ keyboard.gaiamobile.org
+ββ marketplace.firefox.com
+ββ membuster.gaiamobile.org
+ββ music2.gaiamobile.org
+ββ music.gaiamobile.org
+ββ pdfjs.gaiamobile.org
+ββ ringtones.gaiamobile.org
+ββ search.gaiamobile.org
+ββ setringtone.gaiamobile.org
+ββ settings.gaiamobile.org
+ββ share-receiver.gaiamobile.org
+ββ sheet-app-1.gaiamobile.org
+ββ sheet-app-2.gaiamobile.org
+ββ sheet-app-3.gaiamobile.org
+ββ sms.gaiamobile.org
+ββ system.gaiamobile.org
+ββ template.gaiamobile.org
+ββ test-agent.gaiamobile.org
+ββ test-container.gaiamobile.org
+ββ test-fxa-client.gaiamobile.org
+ββ test-ime.gaiamobile.org
+ββ test-keyboard-app.gaiamobile.org
+ββ test-otasp.gaiamobile.org
+ββ test-receiver-1.gaiamobile.org
+ββ test-receiver-2.gaiamobile.org
+ββ test-receiver-inline.gaiamobile.org
+ββ test-wappush.gaiamobile.org
+ββ uitest.gaiamobile.org
+ββ uitest-privileged.gaiamobile.org
+ββ video.gaiamobile.org
+ββ wallpaper.gaiamobile.org
+ββ wappush.gaiamobile.org
+ββ webapps.json
51 directories, 1 file
Step 3: replacing the keyboard application in the Simulator
Now we need to find where is the webapps directory of the Simulator.
In Linux it is normally inside:
~/.mozilla/firefox/YOUR_FIREFOX_PROFILE/extensions/fxos_X_Y_simulator@mozilla.org/profile
where YOUR_FIREFOX_PROFILE is your Firefox profile (if you don’t know
what I’m talking about, use the directory that has default on its
name) and X_Y is the version of the Simulator (if you install 1.3 it
will be 1_3).
Warning
You probably want to backup the webapps directory before continue.
Once you locate the webapps directory of the Simulator, copy our build
of the keyboard to replace the current one at the Simulator:
$ cp -r profile/webapps/keyboard.gaiamobile.org \
~/.mozilla/firefox/YOUR_FIREFOX_PROFILE/extensions/fxos_X_Y_simulator@mozilla.org/profile/webapps/
Note
If you prefer, you can also use a symbolic link to avoid to copy the webapps every time you make some changes.
Step 4: debugging
How do we know we are using our keyboard? More important, how to debug our code!? Did you remember we added a log instruction in step 1? Letβs show how to see these traces. First, run Firefox OS Simulator.
{width=“25%”}
At the “Device” tab of App Manager, search for “Built-in Keyboard” and next to it you will see “Debug”, click on it.
{width=“25%”}
A debugging tab for Keyboard will be create. This tab is very similar to Firefox debug tool.
{width=“25%”}
Now at Firefox OS window, select the Messages app (it’s the second icon at the bottom).
{width=“25%”}
Create a new message (the icon just after “Messages” at the top of the screen) and type one key of the keyboard.
{width=“25%”}
Now go back to App Manager.
{width=“25%”}
You will find something similar to :
"Key pressed: 101"
at the console of the Debug tab.
Further hacking …
Now you want to continue hacking Gaia or its components. It is as easy
as repeat steps from 2 to 4. Not forget to regenerate the profile by
launching make each time you modify a Gaia application (and to copy
the new build of your webapps if you aren’t using symbolic links)!!
Hope it helps!
Tags: