0

I want to detect whether any debug tool is attached to a android device. I want this feature so that no one can see logs when app is released to people.

Regards.

PS:

I want to write log even in Production environment as they'll help me fine tune my app but don't want anyone else to see them.

KhanZeeshan
  • 1,410
  • 5
  • 23
  • 36
  • please note that one can read the logcat output, even without attaching a debugger. For example, one could you download and use the aLogcat app. – Scott W Jul 28 '12 at 17:13
  • In short, I should just stop traditional logging and write everything I need somewhere else, like Google docs... – KhanZeeshan Jul 28 '12 at 17:17

1 Answers1

0

you can't detect if USB debugging is connected or enabled without being a system application. however, we can talk about how to solve your problem. if you don't want your app to log on your official market release, there's a couple of acceptable ways to go about it,

conditionally log. wrap all your log messages like this,

if (DEBUG) Log.d(...);

before you build your official market APK, set DEBUG to false in your code. a slightly nicer way of doing this is to add a wrapper method or class around android's logger. e.g., write a method like this,

void d(String msg) {
  if (DEBUG) Log.d(msg);
}

use proguard. proguard is a tool that manipulates bytecode after compilation. you can use it to remove all logging from your code (among other things). there's quiet a learning curve to get going with proguard, but it's very powerful.

here's another post that gives the topic some in-depth discussion.

How do I enable/disable log levels in Android?

Community
  • 1
  • 1
Jeffrey Blattman
  • 22,176
  • 9
  • 79
  • 134
  • Not really true... there are a number of ways to detect it an adb session, as there's not real intent to hide that one is happening. But doing so it pointless, as it could be connected afterwards to read logs that have already been written when it was not connected. – Chris Stratton Jul 28 '12 at 18:08
  • well don't keep us in suspense, what are they? – Jeffrey Blattman Jul 29 '12 at 02:35