1 /* 2 * Copyright 2009, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.bluetoothdebug; 18 19 import android.bluetooth.BluetoothA2dp; 20 import android.bluetooth.BluetoothAdapter; 21 import android.bluetooth.BluetoothClass; 22 import android.bluetooth.BluetoothDevice; 23 import android.bluetooth.BluetoothDevicePicker; 24 import android.bluetooth.BluetoothHeadset; 25 import android.content.BroadcastReceiver; 26 import android.content.Context; 27 import android.content.Intent; 28 import android.os.Bundle; 29 import android.util.Log; 30 31 /** 32 * Prints Bluetooth intents to logcat. For example: 33 * BTDEBUG : a.b.device.a.FOUND 34 * BTDEBUG : a.b.device.e.DEVICE = 00:18:13:F2:CC:33 35 * BTDEBUG : a.b.device.e.RSSI = -35 36 * BTDEBUG : a.b.device.e.CLASS = 200404 37 * BTDEBUG : a.b.adapter.a.DISCOVERY_FINISHED 38 * BTDEBUG : a.b.device.a.BOND_STATE_CHANGED 39 * BTDEBUG : a.b.device.e.DEVICE = 00:18:13:F2:CC:33 40 * BTDEBUG : a.b.device.e.BOND_STATE = 11 41 * BTDEBUG : a.b.device.e.PREVIOUS_BOND_STATE = 10 42 */ 43 public class DebugReceiver extends BroadcastReceiver { 44 private static final String TAG = "BTDEBUG"; 45 46 public void onReceive(Context context, Intent intent) { 47 Log.d(TAG, shorten(intent.getAction())); 48 49 Bundle bundle = intent.getExtras(); 50 if (bundle == null) return; 51 for (String extra : bundle.keySet()) { 52 Log.d(TAG, "\t" + shorten(extra) + " = " + bundle.get(extra)); 53 } 54 } 55 56 // shorten string to shorthand 57 // android.bluetooth.device.extra.DEVICE -> a.b.device.e.DEVICE 58 private static String shorten(String action) { 59 return action.replace("android", "a") 60 .replace("bluetooth", "b") 61 .replace("extra", "e") 62 .replace("action", "a"); 63 } 64 65 } 66