OSDN Git Service

Add dumpsys support for bluetooth
authorMike Lockwood <lockwood@google.com>
Tue, 28 Oct 2014 21:07:00 +0000 (14:07 -0700)
committerMike Lockwood <lockwood@google.com>
Tue, 28 Oct 2014 21:07:00 +0000 (14:07 -0700)
Bug: 18159457
Change-Id: I807a7d921b6e5baf111d0f0e3e182c6633a93b7c

17 files changed:
src/com/android/bluetooth/a2dp/A2dpService.java
src/com/android/bluetooth/a2dp/A2dpSinkService.java
src/com/android/bluetooth/a2dp/A2dpSinkStateMachine.java
src/com/android/bluetooth/a2dp/A2dpStateMachine.java
src/com/android/bluetooth/avrcp/Avrcp.java
src/com/android/bluetooth/avrcp/AvrcpControllerService.java
src/com/android/bluetooth/btservice/AdapterService.java
src/com/android/bluetooth/btservice/ProfileService.java
src/com/android/bluetooth/gatt/GattService.java
src/com/android/bluetooth/hdp/HealthService.java
src/com/android/bluetooth/hfp/HeadsetService.java
src/com/android/bluetooth/hfp/HeadsetStateMachine.java
src/com/android/bluetooth/hfpclient/HeadsetClientService.java
src/com/android/bluetooth/hfpclient/HeadsetClientStateMachine.java
src/com/android/bluetooth/hid/HidService.java
src/com/android/bluetooth/map/BluetoothMapService.java
src/com/android/bluetooth/pan/PanService.java

index 808ec98..bae6373 100755 (executable)
@@ -297,4 +297,15 @@ public class A2dpService extends ProfileService {
             return service.isA2dpPlaying(device);
         }
     };
+
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        if (mStateMachine != null) {
+            mStateMachine.dump(sb);
+        }
+        if (mAvrcp != null) {
+            mAvrcp.dump(sb);
+        }
+    }
 }
index bd27952..5dcec73 100644 (file)
@@ -210,4 +210,12 @@ public class A2dpSinkService extends ProfileService {
             return service.getAudioConfig(device);
         }
     };
+
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        if (mStateMachine != null) {
+            mStateMachine.dump(sb);
+        }
+    }
 }
index 929676f..d57a0ca 100644 (file)
@@ -156,7 +156,14 @@ final class A2dpSinkStateMachine extends StateMachine {
         mAudioConfigs.clear();
     }
 
-        private class Disconnected extends State {
+    public void dump(StringBuilder sb) {
+        ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
+        ProfileService.println(sb, "mTargetDevice: " + mTargetDevice);
+        ProfileService.println(sb, "mIncomingDevice: " + mIncomingDevice);
+        ProfileService.println(sb, "StateMachine: " + this.toString());
+    }
+
+    private class Disconnected extends State {
         @Override
         public void enter() {
             log("Enter Disconnected: " + getCurrentMessage().what);
index 94cc391..19d4ebd 100755 (executable)
@@ -134,7 +134,6 @@ final class A2dpStateMachine extends StateMachine {
         mIntentBroadcastHandler = new IntentBroadcastHandler();
 
         mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
-
     }
 
     static A2dpStateMachine make(A2dpService svc, Context context) {
@@ -753,6 +752,13 @@ final class A2dpStateMachine extends StateMachine {
         }
     }
 
+    public void dump(StringBuilder sb) {
+        ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
+        ProfileService.println(sb, "mTargetDevice: " + mTargetDevice);
+        ProfileService.println(sb, "mIncomingDevice: " + mIncomingDevice);
+        ProfileService.println(sb, "mPlayingA2dpDevice: " + mPlayingA2dpDevice);
+        ProfileService.println(sb, "StateMachine: " + this.toString());
+    }
 
     // Event types for STACK_EVENT message
     final private static int EVENT_TYPE_NONE = 0;
index 618ff8f..f514b6c 100755 (executable)
@@ -832,6 +832,33 @@ public final class Avrcp {
         mHandler.sendMessage(msg);
     }
 
+    public void dump(StringBuilder sb) {
+        sb.append("AVRCP:\n");
+        ProfileService.println(sb, "mMetadata: " + mMetadata);
+        ProfileService.println(sb, "mTransportControlFlags: " + mTransportControlFlags);
+        ProfileService.println(sb, "mCurrentPlayState: " + mCurrentPlayState);
+        ProfileService.println(sb, "mPlayStatusChangedNT: " + mPlayStatusChangedNT);
+        ProfileService.println(sb, "mTrackChangedNT: " + mTrackChangedNT);
+        ProfileService.println(sb, "mTrackNumber: " + mTrackNumber);
+        ProfileService.println(sb, "mCurrentPosMs: " + mCurrentPosMs);
+        ProfileService.println(sb, "mPlayStartTimeMs: " + mPlayStartTimeMs);
+        ProfileService.println(sb, "mSongLengthMs: " + mSongLengthMs);
+        ProfileService.println(sb, "mPlaybackIntervalMs: " + mPlaybackIntervalMs);
+        ProfileService.println(sb, "mPlayPosChangedNT: " + mPlayPosChangedNT);
+        ProfileService.println(sb, "mNextPosMs: " + mNextPosMs);
+        ProfileService.println(sb, "mPrevPosMs: " + mPrevPosMs);
+        ProfileService.println(sb, "mSkipStartTime: " + mSkipStartTime);
+        ProfileService.println(sb, "mFeatures: " + mFeatures);
+        ProfileService.println(sb, "mAbsoluteVolume: " + mAbsoluteVolume);
+        ProfileService.println(sb, "mLastSetVolume: " + mLastSetVolume);
+        ProfileService.println(sb, "mLastDirection: " + mLastDirection);
+        ProfileService.println(sb, "mVolumeStep: " + mVolumeStep);
+        ProfileService.println(sb, "mAudioStreamMax: " + mAudioStreamMax);
+        ProfileService.println(sb, "mVolCmdInProgress: " + mVolCmdInProgress);
+        ProfileService.println(sb, "mAbsVolRetryTimes: " + mAbsVolRetryTimes);
+        ProfileService.println(sb, "mSkipAmount: " + mSkipAmount);
+    }
+
     // Do not modify without updating the HAL bt_rc.h files.
 
     // match up with btrc_play_status_t enum of bt_rc.h
index b7275d6..0c7e0b6 100644 (file)
@@ -265,6 +265,11 @@ public class AvrcpControllerService extends ProfileService {
         return Utils.getBytesFromAddress(device.getAddress());
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+    }
+
     private native static void classInitNative();
     private native void initNative();
     private native void cleanupNative();
index 9141d3e..ca2ff19 100644 (file)
@@ -93,6 +93,8 @@ public class AdapterService extends Service {
     private int mIdleTimeTotalMs;
     private int mEnergyUsedTotalVoltAmpSecMicro;
 
+    private final ArrayList<ProfileService> mProfiles = new ArrayList<ProfileService>();
+
     public static final String ACTION_LOAD_ADAPTER_PROPERTIES =
         "com.android.bluetooth.btservice.action.LOAD_ADAPTER_PROPERTIES";
     public static final String ACTION_SERVICE_STATE_CHANGED =
@@ -257,6 +259,18 @@ public class AdapterService extends Service {
         }
     }
 
+    public void addProfile(ProfileService profile) {
+        synchronized (mProfiles) {
+            mProfiles.add(profile);
+        }
+    }
+
+    public void removeProfile(ProfileService profile) {
+        synchronized (mProfiles) {
+            mProfiles.remove(profile);
+        }
+    }
+
     public void onProfileServiceStateChanged(String serviceName, int state) {
         Message m = mHandler.obtainMessage(MESSAGE_PROFILE_SERVICE_STATE_CHANGED);
         m.obj=serviceName;
@@ -1114,6 +1128,14 @@ public class AdapterService extends Service {
              if (service == null) return null;
              return service.reportActivityInfo();
          }
+
+         public String dump() {
+            AdapterService service = getService();
+            if (service == null) {
+                return "AdapterService is null";
+            }
+            return service.dump();
+         }
     };
 
 
@@ -1696,6 +1718,16 @@ public class AdapterService extends Service {
         return info;
     }
 
+    private String dump() {
+        StringBuilder sb = new StringBuilder();
+        synchronized (mProfiles) {
+            for (ProfileService profile : mProfiles) {
+                profile.dump(sb);
+            }
+        }
+        return sb.toString();
+    }
+
     private static int convertScanModeToHal(int mode) {
         switch (mode) {
             case BluetoothAdapter.SCAN_MODE_NONE:
index 0c1b70e..1dcb7fb 100644 (file)
@@ -53,6 +53,8 @@ public abstract class ProfileService extends Service {
     protected boolean mStartError=false;
     private boolean mCleaningUp = false;
 
+    private AdapterService mAdapterService;
+
     protected String getName() {
         return getClass().getSimpleName();
     }
@@ -105,6 +107,8 @@ public abstract class ProfileService extends Service {
         super.onCreate();
         mAdapter = BluetoothAdapter.getDefaultAdapter();
         mBinder = initBinder();
+        mAdapterService = AdapterService.getAdapterService();
+        mAdapterService.addProfile(this);
     }
 
     public int onStartCommand(Intent intent, int flags, int startId) {
@@ -149,9 +153,22 @@ public abstract class ProfileService extends Service {
         return super.onUnbind(intent);
     }
 
+    // for dumpsys support
+    public void dump(StringBuilder sb) {
+        sb.append("Profile: " + mName + "\n");
+    }
+
+    // with indenting for subclasses
+    public static void println(StringBuilder sb, String s) {
+        sb.append("  ");
+        sb.append(s);
+        sb.append("\n");
+    }
+
     @Override
     public void onDestroy() {
         if (DBG) log("Destroying service.");
+        mAdapterService.removeProfile(this);
         if (mCleaningUp) {
             if (DBG) log("Cleanup already started... Skipping cleanup()...");
         } else {
@@ -194,17 +211,15 @@ public abstract class ProfileService extends Service {
 
     protected void notifyProfileServiceStateChanged(int state) {
         //Notify adapter service
-        AdapterService sAdapter = AdapterService.getAdapterService();
-        if (sAdapter!= null) {
-            sAdapter.onProfileServiceStateChanged(getClass().getName(), state);
+        if (mAdapterService != null) {
+            mAdapterService.onProfileServiceStateChanged(getClass().getName(), state);
         }
     }
 
     public void notifyProfileConnectionStateChanged(BluetoothDevice device,
             int profileId, int newState, int prevState) {
-        AdapterService svc = AdapterService.getAdapterService();
-        if (svc != null) {
-            svc.onProfileConnectionStateChanged(device, profileId, newState, prevState);
+        if (mAdapterService != null) {
+            mAdapterService.onProfileConnectionStateChanged(device, profileId, newState, prevState);
         }
     }
 
index b2bccb5..ce257d6 100644 (file)
@@ -2180,6 +2180,24 @@ public class GattService extends ProfileService {
         return uuids;
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        println(sb, "mAdvertisingServiceUuids:");
+        for (UUID uuid : mAdvertisingServiceUuids) {
+            println(sb, "  " + uuid);
+        }
+        println(sb, "mOnFoundResults:");
+        for (ScanResult result : mOnFoundResults.values()) {
+            println(sb, "  " + result);
+        }
+        println(sb, "mOnFoundResults:");
+        for (ServiceDeclaration declaration : mServiceDeclarations) {
+            println(sb, "  " + declaration);
+        }
+        println(sb, "mMaxScanFilters: " + mMaxScanFilters);
+    }
+
     /**************************************************************************
      * GATT Test functions
      *************************************************************************/
index 21846c6..8d8eff7 100644 (file)
@@ -788,6 +788,23 @@ public class HealthService extends ProfileService {
         return healthDevices;
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        println(sb, "mHealthChannels:");
+        for (HealthChannel channel : mHealthChannels) {
+            println(sb, "  " + channel);
+        }
+        println(sb, "mApps:");
+        for (BluetoothHealthAppConfiguration conf : mApps.keySet()) {
+            println(sb, "  " + conf + " : " + mApps.get(conf));
+        }
+        println(sb, "mHealthDevices:");
+        for (BluetoothDevice device : mHealthDevices.keySet()) {
+            println(sb, "  " + device + " : " + mHealthDevices.get(device));
+        }
+    }
+
     private static class AppInfo {
         private IBluetoothHealthCallback mCallback;
         private BluetoothHealthDeathRecipient mRcpObj;
index ae2954e..0755c35 100755 (executable)
@@ -557,4 +557,11 @@ public class HeadsetService extends ProfileService {
         return true;
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        if (mStateMachine != null) {
+            mStateMachine.dump(sb);
+        }
+    }
 }
index c7c2fcd..ba8f80a 100644 (file)
@@ -58,6 +58,7 @@ import android.telephony.PhoneNumberUtils;
 import android.util.Log;
 import com.android.bluetooth.Utils;
 import com.android.bluetooth.btservice.AdapterService;
+import com.android.bluetooth.btservice.ProfileService;
 import com.android.internal.util.IState;
 import com.android.internal.util.State;
 import com.android.internal.util.StateMachine;
@@ -297,6 +298,20 @@ final class HeadsetStateMachine extends StateMachine {
         }
     }
 
+    public void dump(StringBuilder sb) {
+        ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
+        ProfileService.println(sb, "mTargetDevice: " + mTargetDevice);
+        ProfileService.println(sb, "mIncomingDevice: " + mIncomingDevice);
+        ProfileService.println(sb, "mActiveScoDevice: " + mActiveScoDevice);
+        ProfileService.println(sb, "mMultiDisconnectDevice: " + mMultiDisconnectDevice);
+        ProfileService.println(sb, "mVirtualCallStarted: " + mVirtualCallStarted);
+        ProfileService.println(sb, "mVoiceRecognitionStarted: " + mVoiceRecognitionStarted);
+        ProfileService.println(sb, "mWaitingForVoiceRecognition: " + mWaitingForVoiceRecognition);
+        ProfileService.println(sb, "StateMachine: " + this.toString());
+        ProfileService.println(sb, "mPhoneState: " + mPhoneState);
+        ProfileService.println(sb, "mAudioState: " + mAudioState);
+    }
+
     private class Disconnected extends State {
         @Override
         public void enter() {
index aaf7156..d7eb12d 100644 (file)
@@ -734,4 +734,12 @@ public class HeadsetClientService extends ProfileService {
         }
         return mStateMachine.getCurrentAgFeatures();
     }
+
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        if (mStateMachine != null) {
+            mStateMachine.dump(sb);
+        }
+    }
 }
index d50602a..b3e4b0a 100644 (file)
@@ -158,6 +158,35 @@ final class HeadsetClientStateMachine extends StateMachine {
         classInitNative();
     }
 
+    public void dump(StringBuilder sb) {
+        ProfileService.println(sb, "mCurrentDevice: " + mCurrentDevice);
+        ProfileService.println(sb, "mAudioOn: " + mAudioOn);
+        ProfileService.println(sb, "mAudioState: " + mAudioState);
+        ProfileService.println(sb, "mAudioWbs: " + mAudioWbs);
+        ProfileService.println(sb, "mIndicatorNetworkState: " + mIndicatorNetworkState);
+        ProfileService.println(sb, "mIndicatorNetworkType: " + mIndicatorNetworkType);
+        ProfileService.println(sb, "mIndicatorNetworkSignal: " + mIndicatorNetworkSignal);
+        ProfileService.println(sb, "mIndicatorBatteryLevel: " + mIndicatorBatteryLevel);
+        ProfileService.println(sb, "mIndicatorCall: " + mIndicatorCall);
+        ProfileService.println(sb, "mIndicatorCallSetup: " + mIndicatorCallSetup);
+        ProfileService.println(sb, "mIndicatorCallHeld: " + mIndicatorCallHeld);
+        ProfileService.println(sb, "mVgsFromStack: " + mVgsFromStack);
+        ProfileService.println(sb, "mVgmFromStack: " + mVgmFromStack);
+        ProfileService.println(sb, "mRingtone: " + mRingtone);
+        ProfileService.println(sb, "mOperatorName: " + mOperatorName);
+        ProfileService.println(sb, "mSubscriberInfo: " + mSubscriberInfo);
+        ProfileService.println(sb, "mVoiceRecognitionActive: " + mVoiceRecognitionActive);
+        ProfileService.println(sb, "mInBandRingtone: " + mInBandRingtone);
+        ProfileService.println(sb, "mCalls:");
+        for (BluetoothHeadsetClientCall call : mCalls.values()) {
+            ProfileService.println(sb, "  " + call);
+        }
+        ProfileService.println(sb, "mCallsUpdate:");
+        for (BluetoothHeadsetClientCall call : mCallsUpdate.values()) {
+            ProfileService.println(sb, "  " + call);
+        }
+    }
+
     private void clearPendingAction() {
         mPendingAction = new Pair<Integer, Object>(NO_ACTION, 0);
     }
index 219332e..418c13b 100755 (executable)
@@ -680,6 +680,16 @@ public class HidService extends ProfileService {
         }
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        println(sb, "mTargetDevice: " + mTargetDevice);
+        println(sb, "mInputDevices:");
+        for (BluetoothDevice device : mInputDevices.keySet()) {
+            println(sb, "  " + device + " : " + mInputDevices.get(device));
+        }
+    }
+
     // Constants matching Hal header file bt_hh.h
     // bthh_connection_state_t
     private final static int CONN_STATE_CONNECTED = 0;
index f016fb1..e407bbf 100755 (executable)
@@ -1084,4 +1084,26 @@ public class BluetoothMapService extends ProfileService {
             return service.getPriority(device);
         }
     }
+
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        println(sb, "mRemoteDevice: " + mRemoteDevice);
+        println(sb, "sRemoteDeviceName: " + sRemoteDeviceName);
+        println(sb, "mState: " + mState);
+        println(sb, "mAppObserver: " + mAppObserver);
+        println(sb, "mIsWaitingAuthorization: " + mIsWaitingAuthorization);
+        println(sb, "mRemoveTimeoutMsg: " + mRemoveTimeoutMsg);
+        println(sb, "mPermission: " + mPermission);
+        println(sb, "mAccountChanged: " + mAccountChanged);
+        println(sb, "mBluetoothMnsObexClient: " + mBluetoothMnsObexClient);
+        println(sb, "mMasInstanceMap:");
+        for (BluetoothMapEmailSettingsItem key : mMasInstanceMap.keySet()) {
+            println(sb, "  " + key + " : " + mMasInstanceMap.get(key));
+        }
+        println(sb, "mEnabledAccounts:");
+        for (BluetoothMapEmailSettingsItem account : mEnabledAccounts) {
+            println(sb, "  " + account);
+        }
+    }
 }
index 5d1bc30..3b48428 100755 (executable)
@@ -576,6 +576,22 @@ public class PanService extends ProfileService {
         return panDevice.mState;
     }
 
+    @Override
+    public void dump(StringBuilder sb) {
+        super.dump(sb);
+        println(sb, "mMaxPanDevices: " + mMaxPanDevices);
+        println(sb, "mPanIfName: " + mPanIfName);
+        println(sb, "mTetherOn: " + mTetherOn);
+        println(sb, "mPanDevices:");
+        for (BluetoothDevice device : mPanDevices.keySet()) {
+            println(sb, "  " + device + " : " + mPanDevices.get(device));
+        }
+        println(sb, "mBluetoothIfaceAddresses:");
+        for (String address : mBluetoothIfaceAddresses) {
+            println(sb, "  " + address);
+        }
+    }
+
     private class BluetoothPanDevice {
         private int mState;
         private String mIfaceAddr;