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 my app detect if the phone was previously in safe mode. Then it could maybe alert the parent or accountability partner?

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

  • 2
    I'm very much hoping that there's no way to do this. – R R Jul 18 '12 at 19:44
  • 4
    I think this shouldn't be closed. Developers are not the only ones who could be interested in this. – R R Jul 18 '12 at 21:01
  • I agree with @Richard. This isn't specifically a coding question, but about how Android works. – ale Jul 19 '12 at 13:02

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, only core Android applications are available. This ensures that the user can boot their phone into an environment that is free of third-party software.

Keywords is free of third-party software


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:


Source: system/core/logcat/logcat.cpp

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

|improve this answer|||||
  • 2
    You didn't really answer the question you just restated what he knew, that his app can't monitor during safe mode. Add something about the safe mode logs or alternatives and then +1 – Peanut Jul 18 '12 at 20:21
  • 1
    @Peanut, Android will still log the logcat, but only the core services, nothing else! There's no alternative to that! And there is no way for third party apps to recognize that there was a safe mode activated because, next time coming out of safe mode i.e. reboot normally,third party apps "think" nothing has happened as in "nothing to see here... move along" – t0mm13b Jul 18 '12 at 20:22
  • 1
    Sorry I edited my comment before seeing your comment, but as I said you didn't really answer his question. So an alternative would be to check if the logcat was running when his app wasn't? Obviously this would require the person to start it up not in safe mode at some point but at least it's a realistic solution. – Peanut Jul 18 '12 at 20:25
  • The logcat contents... are flushed out to /dev/null upon reboot as like "business as usual"... just saying.. :) And thanks for the downvote! – t0mm13b Jul 18 '12 at 20:28
  • Ah, I wasn't aware of that ^^ I'll up vote since you offer an answer to his question here :) I think you should add the stuff about the logs to your actual answer though. edit: Oh, I can't actually upvote till you edit the answer :p – Peanut Jul 18 '12 at 20:32

Not the best answer but maybe the information will be some what useful.

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 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.

|improve this answer|||||
  • 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? – jws121295 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. – Evan Langlois 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

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.