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).
kb_nature

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:

  1. 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

  2. Download the Twemoji project from the link provided above

  3. 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

  4. 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

  5. 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
2
adb pull /system/framework/framework-res.apk
adb pull /system/framework/SemcGenericUxpRes/SemcGenericUxpRes.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):

uni9_crawler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import BeautifulSoup
import urllib2
import Queue
import threading
categories = ['unicode-9.0']
before = '<Cell semc:label="'
after = '" />'
baseurl = 'http://emojipedia.org'
hdr = {'User-Agent':'Mozilla/5.0'}
def worker():
while True:
item = q.get()
req = urllib2.Request(baseurl+item,headers=hdr)
l.append({'name':item, 'source':urllib2.urlopen(req).read()})
q.task_done()
print 'done '+item[1:-1]
for k in categories:
print k
f = open(k+'.txt','w')
url = baseurl+'/'+k
req = urllib2.Request(url,headers=hdr)
get = urllib2.urlopen(req).read()
dom = BeautifulSoup.BeautifulSoup(get)
data = dom.find('div',{'class':'content'}).findAll('ul')
emojis = data[1].findAll('a');
q = Queue.Queue()
l = []
for e in emojis:
q.put(e['href'])
for i in range(6):
t = threading.Thread(target=worker)
t.daemon = True
t. start()
q.join()
print 'writing file'
for p in l:
dom = BeautifulSoup.BeautifulSoup(p['source'])
h2 = dom.find(text="Codepoints")
ul = h2.parent.findNextSibling('ul')
codes = ul.findAll('li')
f.write('<!--'+p['name'][1:-1]+'-->\n')
complete = before
for i in codes:
complete += '\\\\'
c = i.find('a').text.split(' ')[1]
complete += c
complete += ';'
complete += after
print complete
f.write(complete+'\n')
f.close()

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
2
keytool -genkey -v -keystore my-release-key.keystore -alias mykey -keyalg RSA -keysize 2048 -validity 10000
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore my-release-key.keystore xperia-keyboard-uni9.apk mykey

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. kb_faces