3

I have Fairphone 2 running Fairphone Open OS, and I'm making a quixotic effort to avoid installing non-free (as in freedom) software on it and to optimize privacy.

I want swipe input, but I don't want to install Google Keyboard, (LatimeImeGoogle.apk) By default, the OS has AOSP keyboard. I've also installed the wonderfully code-friendly AnySoftKeyboard (which also has awesome themes) and Hacker's Keyboard from F-Droid, but though they are useful to me, they don't have swipe input.

I've read this post which makes me think I have to get the source and compile the keyboard. I don't know how to do this at the moment, but I'm prepared to learn. I tried just replacing the library (by cheating and taking the correct library from the Google apk) mentioned in the post, and nothing changed (if I delete the library the keyboard stops working completely, so clearly I am making a system change by replacing it - it just doesn't do what I want).

I would like any of the following, in order of preference

  1. a nice code-friendly FOSS keyboard with gesture input
  2. a simple* way to enable gesture input for AOSP
  3. confirmation that I do, in fact, need to build AOSP myself to do what I want
  4. any other relevant advice(!)

Obviously, I have root :)

*I have an Ubuntu system to play with on my laptop if it helps...

10
  • Installing Google keyboard won't affect your privacy, unless you enable the sync features.
    – xangua
    Jul 9, 2016 at 16:33
  • Here's a FOSS keyboard: github.com/AnySoftKeyboard/AnySoftKeyboard Oct 13, 2016 at 23:02
  • You should be able to import that into Android Studio without too much of an ordeal. Oct 13, 2016 at 23:03
  • @AndroidDev that's the one I use - it's great and has beautiful themes in the add-on, but no gesture input
    – Zanna
    Oct 13, 2016 at 23:03
  • @Zanna - Oh geez... completely missed that in your question. Lol. In that case, yeah, you'll probably have to build from AOSP source. Oct 13, 2016 at 23:05

3 Answers 3

4

The problem

The default AOSP keyboard does not ship with swipe. It will not appear in the settings. The easy (but awkward) reason is that Google considered this feature to be too "secret" or so to release it in the open source code and thus they ship it in a proprietary library.

The solution

If you want, you can push that library to your device after the ROM installation (and each update!). It is named libjni_latinimegoogle.so and needs to be put in /system/lib.

For me (Android 7.1, ARM) this lib was a really small (944 kB) and oldish (updated 2008) thing. (sha256sum: 442a2a8bfcb25489564bc9433a916fa4dc0dba9000fe6f6f03f5939b985091e6)

Detailed guide

  1. Download the correct Google Apps from http://opengapps.org/. (although I guess the lib may be the same for some versions, but well… just download the correct one)
  2. Now get into the ZIP, respectively extract it. In the Optional dir you'll find another archive swypelibs-lib-arm.tar.lz. Extract that and you'll get the libjni_latinimegoogle.so file.
  3. Now have your phone/device ready in recovery mode. Make sure to mount the /system partition in a writable way. In TWRP you have to go to "Mount" -> (if needed, uncheck) "mount /system in read-only" and then mount it by checking the box for "/system".
  4. Now just push to file to your phone (adb push /path/to/libjni_latinimegoogle.so /system/lib) and restart.

It should work!

OTA survival

I said you need to do this for each update. You can, however, also create a small OTA survival script, which backs up the file when the system is updated.

Here is my (currently, experimental) proposal:

#!/sbin/sh
# 
# /system/addon.d/95-latinimegoogle.sh
# During an OS upgrade, this script backs up /system/lib/libjni_latinimegoogle.so,
# /system is formatted and reinstalled, then the file is restored.
#

. /tmp/backuptool.functions

list_files() {
cat <<EOF
lib/libjni_latinimegoogle.so
EOF
}

case "$1" in
  backup)
    list_files | while read FILE DUMMY; do
      backup_file $S/"$FILE"
    done
  ;;
  restore)
    list_files | while read FILE REPLACEMENT; do
      R=""
      [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT"
      [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R"
    done
  ;;
  pre-backup)
    # Stub
  ;;
  post-backup)
    # Stub
  ;;
  pre-restore)
    # Stub
  ;;
  post-restore)
    # Stub
  ;;
esac

Also available on GitHub: https://gist.github.com/rugk/a4c9fa11c5c031faf45602d6bf922a1c

  1. Just save that file, push it your device into the /system/addon.d dir (adb push 95-latinimegoogle.sh /system/addon.d). (Yet again, you have to make sure /system is mounted.)
  2. And make it executable: adb shell into your device, go to the dir via cd /system/addon.d and: chmod +x 95-latinimegoogle.sh.
3
  • 2
    The destination folder needs to be /system/lib64 if you‘re running on a ARM64. Took me a while to figure out since there‘s still a /system/lib around. Of course, the path has to be adjusted in the OTA survival script, too.
    – undko
    May 11, 2018 at 22:15
  • 1
    Your instructions unfortunately don't seem to work when Magisk is installed: after a reboot, the file is gone again. Solution: after copying the file to your SD card, boot into recovery (TWRP), mount /system, and then use e.g. the built-in file manager (Aroma) to copy the file. After rebooting again, gesture typing is available.
    – Izzy
    Oct 6, 2018 at 20:51
  • 1
    PS: "oldish (updated 2008) thing" – don't be fooled by that. The one for 8.1 has the same timestamp, but is larger (1.1M instead of 944k). Seems like the timestamp is always set to the fictive "birthdate" of Android. // "Download the correct Google Apps" – seems like the smalles package (pico) is sufficient for that.
    – Izzy
    Apr 19, 2019 at 14:43
4
  1. The OTA survival script/configuration fragment hack stopped working on the OnePlus 3T after the last OEM firmware update from OnePlus. (Even though the final OEM firmware update for the OnePlus 3T was relased by OnePlus in July 2019, I feel compelled to still write this because I have not seen anyone mention this so far.) I think this is because the LineageOS maintainers of oneplus3 started using digest files and this verifies system components against some set of signing keys, which will always cause the phone to vanish the custom OTA survival script. So, this means you are limited to the "top" half of the solution from rugk. So, according to my experience with the phones I have, I think the "bottom" part of the solution only works on either: older 32-bit Android devices (such as the OnePlus One/bacon) or any 64-bit Android devices with LOS builds that do not use digest file checking. (I do not know how to check for this on arbitrary LOS-available devices.)

  2. The libjni_latinimegoogle.so hack requires TWRP as your custom recovery to work. Since LOS 17.1-18.1, Lineage Recovery has been offered for any device with LOS builds. However, do not use Lineage Recovery if you use this libjni_latinimegoogle.so hack. For some reason, if you have Lineage Recovery, the /system/lib64 directory simply does not exist, even when you mount the device storage via Lineage Recovery. This was observed on a OnePlus 3T/oneplus3.

  3. Based on what I have read, I infer that this libjni_latinimegoogle.so hack will simply not work on any custom ROM that properly implements verified boot via relocking the bootloader. As of May 2021, CalyxOS and GrapheneOS are 2 ROMs which use verified boot. So, dropping libjni_latinimegoogle.so among system files will probably be prohibited. Even if this gesture typing library hack was hypothetically possible, I feel like that would be an extremely bad security practice/move. Instead, if your use case/threat model allows for open source third-party keyboards, I would recommend FlorisBoard, which has recently implemented what it calls "glide" typing and is available on F-Droid. (Just to be clear, I am not affiliated with CalyxOS, GrapheneOS, or FlorisBoard.) AnySoftKeyboard promised some sort of glide/gesture typing, but that was back in 2018 and ASK never fully implemented this feature, back when I tired ASK once in 2020, IIRC.

1

Update for Lineage OS 17.1 (Android 10.0)

Based on this Reddit, step 4 of rugk’s detailed guide differs as follows (using TWRP since pushing the file with adb didn't work):

  • transfer libjni_latinimegoogle.so onto your phone (/sdcard)
  • start TWRP, check under "Mount" that system is mounted and "read-only" is not checked
  • launch the command line under "Advanced » Terminal" and enter the following commands:
  • mv /sdcard/libjni_latinimegoogle /system/product/lib/
  • chmod 644 /system/product/lib/libjni_latinimegoogle
  • cd /system/product/app/LatinIME/lib/arm/
  • rm libjni_latinime.so
  • ln -s /system/product/lib/libjni_latinimegoogle.so libjni_latinime.so

The above solution works like a charm with a Samsung S5 Neo (s5neolte/SM-G903F) and Lineage OS 17.1 (Android 10).

As mentioned above, you can extract libjni_latinimegoogle.so from Open GApps. Concerning the download options, it doesn't matter that much which Android version you choose. It seems the file hasn't been changed at least since Android 7.1. I used the following settings:

  • Platform: arm
  • Android: 10.0
  • Variant: nano

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .