Unicode 9 emoticons on Xperia
Unicode is the standard regulation of graphic characters used in all the digital text. Each character or sign is encoded with a number in an unique way. Unicode Consortium is the organization that maintains all the rules: many symbols are added regularly, so there exist many versions of Unicode standards. Also emoticons are part of this standard and with each revision, the Consortium inserts new symbols in the encoding rules.
The latest version has been released on June 21, 2016, and many emoticons have been added. The update then has to be received by the producers of software: new graphics are created to match the symbols described by the Consortium. Rarely, the process is inverted and the Consortium adds symbols which are already introduced by big software houses. In this project, the freely provided emoticons by Twitter are used to build a font for Android, then the Xperia keyboard is modified to allow the insertion of the new emoticons in the text areas.
This process requires root privileges for at least one reason: the font used for emoticons is located in a system folder, thus is impossible to replace without root permissions. Another possible reason is that the custom Xperia Keyboard cannot be installed on a stock Xperia system (unrooted) because the package has to be replaced with one having a different signature. Moreover, it is necessary to specify that the keyboard will not fully support the Unicode standard as the Fitzpatrick modifiers are not yet implemented (more work has to be done).
The font
To embed the new emoticons in the system, a specific font file, NotoColorEmoji.ttf, has to be replaced (under /system/fonts). Many choices are available: for example it is possible to use a font derived from Apple’s emoji font or the Android N font (actually, it is the latest version of NotoColorEmoji.ttf), which includes all the Unicode 9 emoticons. For this project a new font has been built from the sources of Noto emoji font.
Building
The main passages of the process are the following:
-
Set up the folder where the project has to be compiled, download the sources of noto-emoji from the previous link and install all the dependencies
-
Download the Twemoji project from the link provided above
-
Export the emoticons in PNG format from the svg folder. For example, the following code will export a SVG file to a PNG file with a width of 128px, which is enough for to make the font (play with bash to automate the process):
1 | rsvg-convert -w 128 -a inputfile.svg -o outputfile.png |
- Copy all the PNG files into a directory in the noto-emoji project folder and rename accordingly to noto-emoji PNGs in the folder png/128
- Change the makefile to exclude the generation of the flags (example).
Installing
The build process generates a file named NotoColorEmoji.ttf (here it is my compiled font), which has to be copied in the Android system in the folder /system/fonts. Root privileges are required to do so and system partition should be remounted as r/w-able. It is necessary that the permissions of the files are rw-r–r-- (644). This allows Android to use Twemoji instead of original Google emoticons system-wide.
The keyboard
Xperia system includes a good keyboard, but the emoticons coverage depends on the version of the system. By analyzing the apk, it can be found that there are many XML files (under res/xml) responsible for the emoticon list. The modification of these files leads to show the new emoticons in the keyboard.
Decompiling
The APK file can be found on many mirrors (for example here). The process of decompilation requires the use of apktool, which has to be set up: it is required to install the Xperia framework files framework-res.apk (from /system/framework) and SemcGenericUxpRes.apk (from /system/framework/SemcGenericUxpRes/). These files can be exported from an existing Xperia device with Marshmallow version (API 23), because the keyboard application had been compiled with such libraries. Here it is an example with ADB:
1 | adb pull /system/framework/framework-res.apk |
Libraries can be installed in apktool with the commands apktool if framework-res.apk -t sony_m
and apktool if SemcGenericUxpRes.apk -t sony_m
. Then, the decompilation takes place:
1 | apktool d xperia-keyboard.apk -t sony_m -o xperia-keyboard |
Tweaking
The decompilation produces a folder (xperia-keyboard) containing all the resources of the original application. XML files of emoticons panels are res/xml/page_emoji*. Each emoticon is defined by a Cell tag such as the following one:
1 | <Cell semc:label="\\U+1f600;" /> |
It is only necessary to add the rows of the new emoticons. The list of codepoints (e.g. U+1f600) can be obtained through Emojipedia. In this case a web crawler can be written to build a TXT file with all the new codes. This is one written in Python (requires BeautifulSoup):
1 | import BeautifulSoup |
With some work of copy-pasting these codes can be embedded in original XML files.
Recompiling
Recompilation takes place with apktool:
1 | apktool b xperia-keyboard -t sony_m -o xperia-keyboard-uni9.apk |
The package can not be installed yet because it lacks the signature, neverthless for personal and debugging purposes it is very easy to produce a certificate and sign the APK. Here follow the commands necessary to do so:
1 | keytool -genkey -v -keystore my-release-key.keystore -alias mykey -keyalg RSA -keysize 2048 -validity 10000 |
Installing
Once the APK is signed it can be installed through ADB (adb install -r xperia-keyboard-uni9.apk
) or copied to the device and then installed through Android’s package manager GUI.
The process will work only if the original package is not installed, otherwise the different signature will prevent the replacement of the application.