nobody's blog


UnifiedNLP on LineageOS 16.0/17.1




Michael Riegert29 Oct 2020

michael+blog@eowyn.net- views


Overview
Compatibility
Install
Enable
Uninstall

Update 2021-04-12: I’ve added a compatibility section going over some current issues regarding installing UnifiedNLP on certain devices that have a qualcomm location services blob.

Overview

UnifiedNLP is a part of the microG project intended to replace the proprietary Google location services with an open-source alternative. These services essentially make it so your device’s location can be calculated from cellular towers and Wi-Fi networks, otherwise your device will use GPS which make take longer and use more battery. This isn’t required when using OpenGApps (as this uses Google’s location services) or microG (which has UnifiedNLP baked in).


Compatibility

Some devices have a QC Location proprietary blob which prevents the installation of UnifiedNLP. In order to properly verify which devices still have this blob, I got a list of these devices by cloning the repositories for all LineageOS devices on GitHub and searching them to see if they had the blob. This is a 20 GiB download and took about 40 minutes.

for num in $(seq 23); do curl -s "https://api.github.com/users/LineageOS/repos?page=${num}&per_page=100" | grep \"clone_url\" | awk '{print $2}' | sed -e 's/"//g' -e 's/,//g' | grep "android_device_" | xargs -n1 git clone; done

grep -R "<bool name=\"config_enableNetworkLocationOverlay\" translatable=\"false\">false</bool>" . 2>/dev/null

As of 2021-04-12, these are the devices that have the QC location blob:

Unfortunately for the time being the work around is a little complex, involving modifying a system APK and resigning it yourself (for security purposes). Those steps are provided here by Aqq123.

The other solution is getting the blob removed from the official builds of LineageOS, which has already been done for various other devices. There is currently an open issue for gingko on getting this blob removed, and no currently open issues for the other devices.


Installing UnifiedNLP

Here is how to install UnifiedNLP on LineageOS 16.0 and 17.1 without GApps.

I’ve tested this out on my OnePlus 3 running LineageOS 17.1, as well as my OnePlus 5T running LineageOS 16.0. I have not tested this on A/B devices, so be warned if you have an A/B device. This will also persist across LineageOS updates.

This will require a computer with a working version of ADB (Android Debugging Bridge). I did this using Linux, though the commands should translate to Windows and MacOS.

  1. Enable ABD and ADB root

    This will enable us to install UnifiedNLP without having to root our entire device, and is built into Android. This is also not permanent, and only accessible when using ADB.

    Enable ADB by going to Settings > About phone and tap on Build number 5 times. From here go to Settings > System > Advanced > Developer options and check Android debugging.

    ADB root can be enabled at Settings > System > Advanced > Developer options > Rooted debugging.

  2. Connect device to computer running ADB and authorize it

    After plugging in the phone and running adb devices, the adb server should start and there should be a popup on the device asking to authorize the computer for use with ADB. After agreeing, ensure that the device shows up and doesn’t say ‘unauthorized’ next to it.

     $ adb devices
    
     List of devices attached
    
     ffffffff	device
    
  3. Download the latest version of UnifiedNLP to your computer here

  4. Create a file called privapp-permissions-unifiednlp.xml and add this to it

    <?xml version="1.0" encoding="utf-8"?>
    <permissions>
        <privapp-permissions package="com.google.android.gms">
            <permission name="android.permission.INSTALL_LOCATION_PROVIDER"/>
            <permission name="android.permission.ACCESS_FINE_LOCATION"/>
            <permission name="android.permission.ACCESS_COARSE_LOCATION"/>
            <permission name="android.permission.ACCESS_COARSE_UPDATES"/>
        </privapp-permissions>
    </permissions>
    
  5. Create another file called 50-UnifiedNLP.sh and add this to it. This is the script that will allow UnifiedNLP to survive LineageOS updates

    #!/sbin/sh
    #
    # /system/addon.d/50-UnifiedNLP.sh
    #
    
    . /tmp/backuptool.functions
    
    list_files() {
    cat <<EOF
    priv-app/UnifiedNLP/NetwortkLocation.apk
    etc/permissions/privapp-permissions-unifiednlp.xml
    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
        ;;
    esac
    
  6. Start ADB with root and remount to make the file system read/write. Be careful as running adb root and abd remount can be dangerous if not used properly.

     adb root
    
     adb remount
    
  7. Push the files to device, assuming the files are in the same directory as the current shell

     adb push NetworkLocation.apk /system/priv-app/UnifiedNLP/NetwortkLocation.apk
    
     adb push privapp-permissions-unifiednlp.xml /system/etc/permissions/privapp-permissions-unifiednlp.xml
    
     adb push 50-UnifiedNLP.sh /system/addon.d
    
     adb shell chmod 755 /system/addon.d/50-UnifiedNLP.sh
    
  8. Unroot and restart your device

     adb unroot
    
     adb reboot
    

Enabling UnifiedNLP

Great! You’ve now successfully installed UnifiedNLP. Now here are the steps on how to set it up.

  1. Check the UnifiedNLP settings

    Settings > Location > Advanced > UnifiedNLP Settings, or alternatively there should be a new app icon in your app drawer/home screen.

    Click on Self-Check and enable Permission to access approximate location ... (if this is unable to be checked off, proceed ahead regardless).

    Make sure UnifiedNlp is registered in system is checked.

    Location backend(s) set up is only checked after enabling location backends.

  2. Install location backends from F-Droid

    Some examples:

    MozillaNlpBackend

    LocalGsmNlpBackend

    There are several more listed here:

    https://f-droid.org/en/packages/com.google.android.gms/

  3. Enable backends in UnifiedNLP Settings

    Settings > Location > Advanced > UnifiedNLP Settings

    Click Configure location backends and check off the services you want to use.

  4. Test out a map program to see if it works (such as OsmAnd~)

  5. Disable ADB and ADB root, both in Developer options

And that’s it! You have now installed UnifiedNLP. If you find UnifiedNLP (and by extension microG) useful, please consider donating to its continued development here!


Uninstalling UnifiedNLP

If for some reason it’s not working correctly, or you’re just not happy with it, here are the steps to uninstall UnifiedNLP.

  1. Enable ABD and ADB root (same as above) and connect your phone to a computer with a working version of ADB

    Make sure it’s connected by running

     $ adb devices
    
     List of devices attached
    
     ffffffff	device
    
  2. Start ADB with root and remount

     adb root
    
     adb remount
    
  3. Remove the installed files

    Make sure to type the command exactly as shown below as changes made here are permanent.

     adb shell rm /system/priv-app/UnifiedNLP/NetwortkLocation.apk
    
     adb shell rm /system/etc/permissions/privapp-permissions-unifiednlp.xml
    
     adb shell rm /system/addon.d/50-UnifiedNLP.sh
    
  4. Unroot and restart your device

     adb unroot
    
     adb reboot
    
  5. Uninstall location backends

Then you’re all set. UnifiedNLP is now successfully removed from your phone.


Source:



© 2021 Michael Riegert
Unless otherwise noted, content is under a CC BY 4.0 license.