20

I'm making a parental control/accountability app for Android. It consists of a monitoring service that runs in the background and starts when the phone is booted.

Unfortunately, I have found that when Android is started in "Safe Mode", services are not started automatically, and because of this, my app has a serious flaw. While in safe mode, the web and other apps can be started without my monitoring service running.

I thought that if it isn't possible to monitor app activity while in safe mode, maybe I could at least have a way to detect if the phone was previously in safe mode.

Does Android keep any log of this? Or any boot log in general? I'm very open to suggestions and alternatives.

0
13

I think you have caught yourself out, in short, nothing you can do!

Have a look at this source that explains why, specifically in this section:

System Partition and Safe Mode

The system partition contains Android's kernel as well as the operating system libraries, application runtime, application framework, and applications. This partition is set to read-only. When a user boots the device into Safe Mode, third-party applications may be launched manually by the device owner but are not launched by default.

Keywords is third-party applications [...] are not launched by default.


When Android boots up, it keeps a cache of the logcat, in a temporary buffer that is reserved found in /dev/log. That buffer gets recycled when it hits the threshold, obviously, the bigger the threshold, the slower Android gets with the continual spamming into the logcat buffer hence kept to minimum - IIRC, its around 64K:

#define DEFAULT_LOG_ROTATE_SIZE_KBYTES 16
#define DEFAULT_MAX_ROTATED_LOGS 4

Source: system/core/logcat/logcat.cpp

Do not ask how many lines that can be, as to each and to every app, it's different. Not alone that, the logcat disappears upon reboot!

0
6

The only method I'm aware of that contains a log produced by the system after a reboot is /proc/last_kmsg. Whether or not the kernel keeps this log file after a reboot depends on the settings provided during kernel compilation.

My experience has shown that some stock devices (HTC) have this logging enabled and others do not. I haven't seen a consistent pattern.

3
  • Thank you! Where did you learn about this log? Do you have any suggestions as to how I can learn about more of these logs? Is there a reference somewhere?
    – ferm10n
    Aug 10 '12 at 11:53
  • In case anyone wanders in like I did, the log is now in /sys/fs/pstore/console_ramoops. It's not a full log like dmesg, but basically just has information about the last kernel panic and what led up to it. Aug 1 '17 at 11:41
  • adb shell cp /sys/fs/pstore/console-ramoops /data/media/0/console-ramoops.`date "+%Y_%m_%d_%H_%M_%S"`.log works with TWRP on OP3 with Android 8-based LineageOS
    – beppe9000
    Jun 30 '19 at 17:38
0

If you're rooted, I would just open Termux and do:

sudo cat /proc/bootloader_log | less

Or you could use the app "LiveBoot" and it will show you all your boot processes every time you turn your phone on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.