I'm trying to find out if someone has connected the Android phone (Samsung Note 4) to the PC via USB. Is there a log somewhere on the device showing the timestamp of connection? Preferably without turning on the debug mode?

  • Android version? – Firelord Aug 9 '15 at 1:15
  • Another way is to use adb shell dmesg and look for power connection/disconnection logs there. That's the best source to consider. In Android 4.2.1 you can check kernel logs (if rooted) without ADB by browsing into /data/log_temp/. – Firelord Aug 9 '15 at 4:03

Preferably without turning on the debug mode?

Sorry! I don't have a solution that doesn't require USB debugging as of now. A workaround is to use a rooted device and run ssh server on Wi-Fi.

Anyhow, if the device has been connected to PC using USB, then it must have drawn some power, miniscule and momentarily it may be.

Setup in PC, turn on USB debugging on phone or use the workaround, and enter the command:

  • For Lollipop 5.0.2:

    dumpsys batterystats | grep -A30 "Statistics since last unplugged:"

    or, to get the most relevant details only:

    dumpsys batterystats | grep -A30 "Statistics since last unplugged:" | grep -B30 "Device is currently"

    The output could be like:

    Statistics since last unplugged:
      Time on battery: 23m 13s 868ms (100.0%) realtime, 23m 13s 868ms (100.0%) uptime
      Time on battery screen off: 22m 13s 363ms (95.7%) realtime, 22m 13s 362ms (95.7%) uptime
      Total run time: 23m 13s 868ms realtime, 23m 13s 868ms uptime
      Start clock time: 2015-08-09-06-50-16
      Screen on: 1m 0s 505ms (4.3%) 0x, Interactive: 1m 0s 758ms (4.4%)
      Screen brightnesses:
      dark 1m 0s 505ms (100.0%)
      Total partial wakelock time: 22m 13s 363ms
      Mobile total received: 0B, sent: 0B (packets received 0, sent 0)
      Phone signal levels:
      moderate 22m 35s 311ms (97.2%) 1x
      good 38s 557ms (2.8%) 0x
      Signal scanning time: 0ms
      Radio types:
      none 23m 13s 868ms (100.0%) 0x
      Device is currently unplugged

    I've removed some output denoted by ... since it's not relevant here.

    Now, the latest unplugged detail highlights:

    • Start clock time: 2015-08-09-06-50-16 -- On Aug 9, 2015 at 06:50:16 AM, my device was unplugged from USB
    • Time on battery: 23m 13s 868ms -- time for which the device has been running on battery since last unplugged

    You can do the calculation now, based on your case.

    Note that this info has nothing to do with full charge details. It simply tells us the details for the event when the device was connected to a source that supplied it power.

  • For Android 4.4.2:

    dumpsys batterystats | grep -A30 "Statistics since last unplugged:" | grep -B30 "Device is currently*"
  • For Android 4.2.1:

    dumpsys batteryinfo | grep -A30 "Statistics since last unplugged" | grep -B30 "Device is currently*"

Note: In the last two cases, Start clock time isn't available but Time on battery among other things.

All of this info would be helpful if only you have not plugged the device into charger or PC since the above battery-stats doesn't differentiate between the two.

Nonetheless, it is still a good lead!

| improve this answer | |
  • This answer by Matthew Read also deals with the same thing. – Firelord Aug 9 '15 at 5:26
  • I see. This is a good lead... I think the battery graph in control panel shows a similar output... but I've since charged my phone several times so it's not possible to trace back to the time my phone was in someone else's hand. So Android doesn't log USB plug/unplug at all? – ytk Aug 9 '15 at 16:27
  • It does log, the kernel logs precisely speaking has those plug/unplug entries. It's in the output of adb shell dmesg. I can't seem to find where does Android 4.4+ and 5.x stores these kernel logs which dmesg outputs. – Firelord Aug 9 '15 at 18:20

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.