Installing Android after Ubuntu Touch: Fix sensors issue
-
Hi there,
if you ever want to install an Android-based distro after Ubuntu Touch was installed, you will notice that no sensors work anymore. The root cause was already identified by guys on the Fairphone forum some time ago description is more to the end of the thread, so be patient and read it in full - but here in UT side nobody of course noticed that, as sensors keep working correctly in UT

What happens is that the necessary Android selinux contexts are being somehow removed from the sensor folder in the persist partition. We would need to analyze why this happens, but probably the files are being rewritten from the Android container in UT and as UT does not use selinux, they are set to unlabeled, like so:
./sensors/registry/registry: total 668 drwxr-xr-x 2 system system u:object_r:vendor_persist_sensors_file:s0 12288 2023-11-21 22:10 . drwxr-xr-x 3 system system u:object_r:vendor_persist_sensors_file:s0 4096 2023-11-21 22:10 .. -rw------- 1 system system u:object_r:unlabeled:s0 78 2023-11-21 22:10 ak0991x_0 -rw------- 1 system system u:object_r:unlabeled:s0 131 2023-11-21 22:10 ak0991x_0.mag -rw------- 1 system system u:object_r:unlabeled:s0 233 2023-11-21 22:10 ak0991x_0.mag.config -rw------- 1 system system u:object_r:unlabeled:s0 181 2023-11-21 22:10 ak0991x_0.mag.config_2 -rw------- 1 system system u:object_r:unlabeled:s0 222 2023-11-21 22:10 ak0991x_0_platform -rw------- 1 system system u:object_r:unlabeled:s0 866 2023-11-21 22:10 ak0991x_0_platform.config -rw------- 1 system system u:object_r:unlabeled:s0 142 2023-11-21 22:10 ak0991x_0_platform.mag -rw------- 1 system system u:object_r:unlabeled:s0 146 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal -rw------- 1 system system u:object_r:unlabeled:s0 204 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal.bias -rw------- 1 system system u:object_r:unlabeled:s0 508 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal.corr_mat -rw------- 1 system system u:object_r:unlabeled:s0 148 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal_2 -rw------- 1 system system u:object_r:unlabeled:s0 206 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal_2.bias -rw------- 1 system system u:object_r:unlabeled:s0 510 2023-11-21 22:10 ak0991x_0_platform.mag.fac_cal_2.corr_mat -rw------- 1 system system u:object_r:unlabeled:s0 176 2023-11-21 22:10 ak0991x_0_platform.orient -rw------- 1 system system u:object_r:unlabeled:s0 622 2023-11-21 22:10 ak0991x_0_platform.placementUnfortunately the solution to this is, as described in the Fairphone forum thread, a bit cumbersome:
- The bootloader needs to be unlocked. If you happen to have all your data already in this Android installation and you have locked the bootloader again, you will loose all your data during this process.
- You have to install Magisk. Depending on the Android version this involves patching the boot.img file or creating a custom recovery
- With Magisk you can obtain a root shell and the execute the necessary restorecon command
It would be awesome to find out if we can avoid this situation somehow. Unfortunately I just dont have the time for the moment, but I can confirm the fix worked as described over there.
BR Florian
-
@flohack Hello,
Last year I had to reinstall Android for some months and I used LineageOS. This Android version allows you to run the selinux commands without the need of Magisk. It allows you to run adb shell commands as root with a simple checkbox in the developper settings.
I was happy to discover this possibility with LineageOS as I had already restored my data on the phone

-
I had to install back a second time Android on my Fairphone 4, this time I've took some notes shared below.
TLDR: LineageOS developer options pane allows you to enable
Rooted debugging. This allows you to use theadb rootcommand which start a rooted debugging session. Then you can useadb shellto open a console on the device and runrestorecon -FR /mnt/vendor/persistto restore the SELinux permissions.
From Ubuntu Touch, the easiest way to go to the fastboot mode, is to open the terminal application and run:
sudo reboot -f bootloaderThen, I used the Android 11 factory reset image provided by Fairphone (but don't do like me, see below).
Then, I wanted to install LineageOS and they require to have Android 13/15.
So, I opened Android 11, go to phone information in the settings application, repeatedly touch the build number until the developer mode is enabled.
Go, to the system panel in the settings application, open the developer mode and enable the ADB debugging.
On my computer, I go back to the fastboot mode with:
adb reboot bootloaderI've installed Android 13 factory reset image provided by Fairphone as I already have downloaded it for another experiment.
Then I boot Android 13 and enabled usb debugging with same steps than Android 11 (see above).
Then I've followed LineageOS instructions to install it step by step:
https://wiki.lineageos.org/devices/FP4/install/
Then, with LineageOS, you can enable developer options with same procedure.
The LineageOS developer options have two options:
USB debuggingandRooted debugging, you need the last one to be able to run commands to reset correctly permissions on the hardware drivers.Then, on my computer I was able to run,
adb rootto start rooted debugging, open a shell on the phone withadb shelland run in this shellrestorecon -FR /mnt/vendor/persist:$ adb root restarting adbd as root $ adb shell FP4:/ # restorecon -FR /mnt/vendor/persist SELinux: Loaded file context from: /system/etc/selinux/plat_file_contexts /system_ext/etc/selinux/system_ext_file_contexts /product/etc/selinux/product_file_contexts /vendor/etc/selinux/vendor_file_contexts /odm/etc/selinux/odm_file_contexts FP4:/ #Then you need to reboot and you can check this worked by enabling the automatic rotation feature: open an application and rotate your phone, the application should follow the movement

Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register Login