Monday, May 16, 2011

 

Looting Android's log files

Hello, my faithful droogsreaders. Been awhile since I've posted here, because I've been super-busy, mostly writing code. But I'm off travelling for a couple of months shortly (Ethiopia, France, Ladakh) so I thought I'd leave you with a little Android/Bluetooth tidbit before I go:

In theory, any Android 2.1-or-later device can open serial port protocols to any Bluetooth device. In practice, though, a bunch of handset manufacturers have, for reasons known to them alone, crippled their Bluetooth stack so that they can't Discover (a word with a loaded meaning in Bluetooth) any device with a generic (ie set to 0) Bluetooth class.

How annoying, no? However, it turns out that - even on those devices - you can pair with and connect to those devices, if you know their address. "But Jon," you say, "how can I get their address, if the Discovery process has been crippled?"

Well. It turns out that the Qualcomm drivers in question, when they ignore the generic Bluetooth devices, do write to the Android log file the fact that they are ignoring it. So all you need to do is mine your log files for the address. How do you do that? So glad you asked.

First, add to your AndroidManifest:

<uses-permission android:name="android.permission.READ_LOGS" />


Second, use this method:

private Set checkLogs() {
HashSet devices = new HashSet();
if (mAdapter==null)
return devices;

//check the logs
Log.i(""+this, "Log check...");
try {
Process process = Runtime.getRuntime().exec("logcat -d *:e");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
String deviceAddress=null;
while ((line = bufferedReader.readLine()) != null) {
if (line.indexOf("0x00 - skip it") > 0) {
int end = line.indexOf("] class");
int start = line.indexOf("Device [");
if (start>=0)
start=start+"Device [".length();
deviceAddress = line.substring(start, end);
Log.i(""+this, "Found "+deviceAddress+" in log");
BluetoothDevice device = mAdapter.getRemoteDevice(deviceAddress) ;
devices.add(device);
//String deviceName = device.getName()==null ? device.getAddress() : device.getName();
//Util.DoToast(Main.this, "Discovered device "+deviceName);
}
}
bufferedReader.close();
process.destroy();
return devices;
}
catch(IOException ex) {
Log.e(""+this, "Error checking logs - "+ex);
ex.printStackTrace();
return null;
}
}


...and finally, just connect to the device explicitly:


btSocket = device.createRfcommSocketToServiceRecord(GatewayManagerConversation.uuid);
btSocket.connect();


...and that should trigger the pairing process, and after pairing, you can connect to the device (which will be in your local cache of paired devices, as normal.)

Hope that helps!

Labels: , ,


Comments:
I took the same log file approach, but I have written an AsyncTask that kicks of discovery, and they retrieves just those devices that were 'skipped' during that discovery. This will avoid finding multiple devices, and won't require the user to kick of a discovery in the phone settings first :)

You can find it here.
 

anks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.

Agile team facilitation

ICP ATF
 
Thanks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.
Team facilitator Agile

Agile facilitator
 
Thanks for sharing this informative content.,
Leanpitch provides online training in Agile team facilitation during this lockdown period everyone can use it wisely.
Team facilitator in Agile

ICAGILE ATF

 
Excellent content ,Thanks for sharing this .,
Scrum master certification online
CSM certification online

 
Nice Blog. Thanks for sharing with us. Such amazing information.

Main causes for failure in digital marketing strategy
 
I never heard about this method. I will try this but first I have to complete some projects of Hrm Dissertation Editing Services Uk. Then I will definitely give it a try and give my opinion on this method.
 
Well, you shared outstanding information about the android log files. I never heard anything about android log files, but I am sure this information might be helpful for Android users. I will share this post with my younger brother, and he will try this method of looting android log files.
Best Assignment Writing Services
 
토토
사설토토


I really like it when folks come together and share opinions.
Great website, keep it up!
 
스포츠토토티비
스포츠토토


This really is such a awesome write-up. I’ve been looking for this information for quite a while now and then finally stumbled upon your internet site. Thanks so much for posting this, this has helped me out tremendously. By the way I love the style of the blog, looks good, did you create it all by yourself?

 
토토사이트
프로토


Wow! After all I got a web site from where I can actually get valuable information regarding my study and knowledge.|
 
Such a very nice post. Top assignment help

 
Great Blog! I have go through all the content of this blog.This is really helpful and informative for me and all the readers.We are offering an online business management research topics ideas for those students,who have interested to avail this service at a cheap price.

 
This is very nice guys! I would love to recommend you a beautiful service for homework! If you need some help, just text to them personal statement professional and be ready for help! They rally know how to it!
 
Thank you for this informational post. I really like your content. Keep Posting. If your Roadrunner Email Not Working with Outlook and looking for technical help. Please contact us.
 
Most students who only have one lesson at a time use research paper writers to free up their time by writing any kind of written paper on it for a small fee.I am glad that I found a site where I can easily order various essays.
 

Post a Comment

Subscribe to Post Comments [Atom]





<< Home

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]