Suddenly all Apps Crashing on Every Boot

Hi everybody,
I need some help in tracking down a problem with my phone no longer being usable.

I’ve been unsing /e/ happily for months on my Sony Xperia XA2. Until today, it suddenly rebooted while is was browsing the web (nothing special, just doing research in an online shop).
What happened then and now every time after rebooting, entering my SIM PIN and unlocking the phone, is that a lot of apps instantly crash without any interaction, including the launcher, migroG, and obviously every app that auto-starts with the system. (Lots of the small dialog windows reading the the app was closed, allowing to mute further notifications until restart.) The only thing I can do is drag down the status bar and access the settings. When I try to access the SD card storage in the settings, the MTP host crashes (but if I remove the SD card and reboot the problem persists, so I assume that’s not the cause).

I cannot even connect the phone to adb in order to inspect the logs (adb keeps waiting for a device). The only hint I get is from my launcher (OpenLauncher) which is nice enough to give me a meaningful error message: it says it could not connect to the SQLite databasae. (btw: switching back to Bliss Launcher didn’t help, too)

Any ideas what’s going wrong, or how I could resolve the issue or at least gain more insights? I know I could do a factory reset, but I’d prefer not to.

Thanks in advance

Can you try and clear the storage and data cache for OpenLauncher - i also use the same launcher :slight_smile:
Settings >> Apps & notification >> See all apps >> OpenLauncher / Bliss Launcher >> Storage

Clear Storage + Clear Cache

and check if that makes any difference. Any launcher settings you have may be removed.

Thanks for your quick response. I tried clearing storage and cache for both OpenLauncher and Bliss Launcher, but the problem remains the same.

But I have just figured out why I have not been able to connect via adb - my phone has no longer been in developer mode, I do not know how and when this happened (but I am 100% sure I didn’t do this manually). So, I have been grooming the adb logcat a little and see that several apps are crashing while trying to access SQLite, e.g. OpenLauncher, Bliss Launcher, K9, F-Droid - the message is always the same:

android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database

F-Droid obviously tries to write a crash report and then throws another exception because it cannot access the file system

E ACRA    : An error occurred while writing the report file...
E ACRA    : java.io.FileNotFoundException: /data/user/0/org.fdroid.fdroid/app_ACRA-unapproved/2020-06-07T09:02:48.424+02:00-IS_SILENT.stacktrace (Permission denied)

It seems as if all apps suddenly have lost access to my user data :confused:

Update:
my /data directory has drwxrwx--x system system, not sure whether that’s okay (most other directories are owned by root/root) :thinking:
My phone does not seem to be rooted, because I can neither adb root nor su.

I’d be happy for any hints how to proceed further.

Hej @jkl,
/e/ OS standard installation and useing doesn’t require root

adbonly

Root access via ADB only can be set in the developer options.

adb root (restarts adb with root permissions)

1 Like

wow @archje, thanks a million :star_struck: - I did not know I could set ADB-only root access in there, nice :+1:

This makes me pretty confident I’ll be able to sort this out without wiping the phone :smile:

Is there something like a reference describing what file system permissions should look like? How can I found out which user is trying to access /data when using an app?

Just did some more logfile grooming - the very first issue after unlocking is setting an attribute on /data/user/0

06-07 13:41:42.564  1201  1913 V UserDataPreparer: Found /data/user/0 with serial number -1
06-07 13:41:42.564  1201  1913 D UserDataPreparer: Serial number missing on /data/user/0; assuming current is valid
06-07 13:41:42.565  1201  1913 W UserDataPreparer: Failed to set serial number on /data/user/0
06-07 13:41:42.565  1201  1913 W UserDataPreparer: java.io.IOException: setxattr failed: EACCES (Permission denied)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserDataPreparer.setSerialNumber(UserDataPreparer.java:303)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserDataPreparer.enforceSerialNumber(UserDataPreparer.java:282)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserDataPreparer.prepareUserDataLI(UserDataPreparer.java:92)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserDataPreparer.prepareUserData(UserDataPreparer.java:72)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserManagerService.onBeforeUnlockUser(UserManagerService.java:3177)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.am.UserController.finishUserUnlocking(UserController.java:331)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.am.UserController.unlockUserCleared(UserController.java:1048)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.am.UserController.unlockUser(UserController.java:996)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.am.ActivityManagerService.unlockUser(ActivityManagerService.java:23735)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.locksettings.LockSettingsService.unlockUser(LockSettingsService.java:1142)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.locksettings.LockSettingsService.spBasedDoVerifyCredential(LockSettingsService.java:2198)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.locksettings.LockSettingsService.doVerifyCredential(LockSettingsService.java:1608)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.locksettings.LockSettingsService.checkCredential(LockSettingsService.java:1576)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.internal.widget.ILockSettings$Stub.onTransact(ILockSettings.java:164)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at android.os.Binder.execTransact(Binder.java:697)
06-07 13:41:42.565  1201  1913 W UserDataPreparer: Caused by: android.system.ErrnoException: setxattr failed: EACCES (Permission denied)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at libcore.io.Linux.setxattr(Native Method)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at libcore.io.BlockGuardOs.setxattr(BlockGuardOs.java:384)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at android.system.Os.setxattr(Os.java:531)
06-07 13:41:42.565  1201  1913 W UserDataPreparer:      at com.android.server.pm.UserDataPreparer.setSerialNumber(UserDataPreparer.java:301)

… followed by loads of error message from processes trying to access the filesystem under /data/data/ and /data/user/0 (also containing failing accesses to SQLite databases).

Quite an issue there. Can’t say what may have caused the sudden change. /data owned by system.system is okay but permissions further down could’ve gotten borked. Or an issue with SELinux. Hard to say.
Also make sure /data/media is owned by media_rw.media_rw.

Researching the symptom ( SQLiteCantOpenDatabaseException) produces a lot of hits, making it hard to narrow anything down.
Possible fix is to run restorecon on the /data partition to fix things up. On a couple of my devices where I multi boot I wind up having to do that on occasion. But there’s a button for that in MultiROM-TWRP for secondary ROMs. For everyone else it’s done via the command line. TWRP terminal or adb shell I guess. Something like…

restorecon -FR /data/
or
restorecon -FR /data/media/

The Android version of restorecon may have the -n option. It’ll show what restorecon is doing without it actually doing anything.
restorecon -nFR for instance.

Warning. Not saying you should do this but if you do, have a backup ready, just in case.

Thanks a lot @marcdw, I’ll have a closer look at restorecon.

FWIW, I looked up the permissions and ownership of directories that seem relevant to me:

/data: drwxrwx--x  48 system    system
/data/data: drwxrwx--x  8 system   system
/data/user: drwx--x--x  2 system   system
/data/user/0: lrwxrwxrwx  1 root   root  -> /data/data
/data/media: drwxrwx---  4 media_rw media_rw

Okay, I tried to restorecon -DFRv and it re-labeled quite some files in the /data dir, but it got neither better nor worse - logcat still filled with FileNotFoundExceptions and SQLiteCantOpenDatabaseExceptions :man_shrugging:

Well, at least I tried, and learned something new. If no one has another idea, I think I’ll just have to wipe and re-install… bad luck.

Thanks anyway for taking the time to help, I really appreciate that :slight_smile:

it got neither better nor worse

Small correction: under the hood it actually got worse. Àfter using restorecon as described above and rebooting, my /data/data was gone, and also the backup tar I had saved to /mnt/sdcard/ (not sure how that happened :astonished: ).

I am pretty sure this is not restorecons fault, but rather happened due to a fatal state deep inside in my system (which was there before and probably has caused the crashes in the first place).

I am writing this just as a warning for anyone else finding themselves in a similar situation and stumbling across this thread: Be careful, and pull your backup to your computer, just to be sure.

Going to wipe and reinstall. Thanks again for anyone who tried to help me in getting this fixed :+1:

Ah dang. Sincerely so sorry to hear that. :pensive:

I was surprised to see you used the -D option to restorecon. Not an option normally mentioned. Did you first try just -FR and it didn’t work?

Never mind :man_shrugging:

I tried restorecon -FRn, but the only output was SELinux: Loaded file_contexts.

restorecon --help told me about the -D option:

-D apply to /data/data too

Seemed reasonable to me, because that’s the path I have had issues with, and in fact it found about 50 items to re-label. That said, the fact that there is an extra switch to opt-in for that specific directory should have made me even more cautious than I already was. Didn’t expect my backup to disappear from the SD card though, and still have no idea how that could happen.