Loading android/app/src/com/android/bluetooth/a2dp/A2dpService.java +3 −0 Original line number Diff line number Diff line Loading @@ -35,10 +35,12 @@ import android.support.annotation.GuardedBy; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.avrcp.Avrcp; import com.android.bluetooth.avrcp.AvrcpTargetService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import java.util.ArrayList; Loading Loading @@ -906,6 +908,7 @@ public class A2dpService extends ProfileService { // codecs (perhaps it's had a firmware update, etc.) and save that state if // it differs from what we had saved before. updateOptionalCodecsSupport(device); MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP); } // Set the active device if only one connected device is supported and it was connected if (toState == BluetoothProfile.STATE_CONNECTED && (mMaxConnectedAudioDevices == 1)) { Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +5 −0 Original line number Diff line number Diff line Loading @@ -44,9 +44,11 @@ import android.os.ParcelUuid; import android.os.PowerManager; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.avrcpcontroller.AvrcpControllerService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.internal.util.IState; import com.android.internal.util.State; Loading Loading @@ -807,6 +809,9 @@ public class A2dpSinkStateMachine extends StateMachine { private class IntentBroadcastHandler extends Handler { private void onConnectionStateChanged(BluetoothDevice device, int prevState, int state) { if (prevState != state && state == BluetoothProfile.STATE_CONNECTED) { MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP_SINK); } Intent intent = new Intent(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, state); Loading android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +4 −0 Original line number Diff line number Diff line Loading @@ -33,8 +33,10 @@ import android.os.Bundle; import android.os.Message; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading Loading @@ -189,6 +191,8 @@ class AvrcpControllerStateMachine extends StateMachine { mAddressedPlayer = new AvrcpPlayer(); mIsConnected = true; } MetricsLogger.logProfileConnectionEvent( BluetoothMetricsProto.ProfileId.AVRCP_CONTROLLER); Intent intent = new Intent( BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, Loading android/app/src/com/android/bluetooth/btservice/AdapterService.java +1 −0 Original line number Diff line number Diff line Loading @@ -2478,6 +2478,7 @@ public class AdapterService extends Service { } } metricsBuilder.setNumBondedDevices(getBondedDevices().length); MetricsLogger.dumpProto(metricsBuilder); for (ProfileService profile : mRegisteredProfiles) { profile.dumpProto(metricsBuilder); } Loading android/app/src/com/android/bluetooth/btservice/MetricsLogger.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.btservice; import com.android.bluetooth.BluetoothMetricsProto.BluetoothLog; import com.android.bluetooth.BluetoothMetricsProto.ProfileConnectionStats; import com.android.bluetooth.BluetoothMetricsProto.ProfileId; import java.util.HashMap; /** * Class with static methods for logging metrics data */ public class MetricsLogger { private static final HashMap<ProfileId, Integer> sProfileConnectionCounts = new HashMap<>(); /** * Log profile connection event by incrementing an internal counter for that profile. * This log persists over adapter enable/disable and only get cleared when metrics are * dumped or when Bluetooth process is killed. * * @param profileId Bluetooth profile that is connected at this event */ public static void logProfileConnectionEvent(ProfileId profileId) { synchronized (sProfileConnectionCounts) { sProfileConnectionCounts.merge(profileId, 1, Integer::sum); } } /** * Dump collected metrics into proto using a builder. * Clean up internal data after the dump. * * @param metricsBuilder proto builder for {@link BluetoothLog} */ public static void dumpProto(BluetoothLog.Builder metricsBuilder) { synchronized (sProfileConnectionCounts) { sProfileConnectionCounts.forEach( (key, value) -> metricsBuilder.addProfileConnectionStats( ProfileConnectionStats.newBuilder() .setProfileId(key) .setNumTimesConnected(value) .build())); sProfileConnectionCounts.clear(); } } } Loading
android/app/src/com/android/bluetooth/a2dp/A2dpService.java +3 −0 Original line number Diff line number Diff line Loading @@ -35,10 +35,12 @@ import android.support.annotation.GuardedBy; import android.support.annotation.VisibleForTesting; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.avrcp.Avrcp; import com.android.bluetooth.avrcp.AvrcpTargetService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import java.util.ArrayList; Loading Loading @@ -906,6 +908,7 @@ public class A2dpService extends ProfileService { // codecs (perhaps it's had a firmware update, etc.) and save that state if // it differs from what we had saved before. updateOptionalCodecsSupport(device); MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP); } // Set the active device if only one connected device is supported and it was connected if (toState == BluetoothProfile.STATE_CONNECTED && (mMaxConnectedAudioDevices == 1)) { Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStateMachine.java +5 −0 Original line number Diff line number Diff line Loading @@ -44,9 +44,11 @@ import android.os.ParcelUuid; import android.os.PowerManager; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.avrcpcontroller.AvrcpControllerService; import com.android.bluetooth.btservice.AdapterService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.internal.util.IState; import com.android.internal.util.State; Loading Loading @@ -807,6 +809,9 @@ public class A2dpSinkStateMachine extends StateMachine { private class IntentBroadcastHandler extends Handler { private void onConnectionStateChanged(BluetoothDevice device, int prevState, int state) { if (prevState != state && state == BluetoothProfile.STATE_CONNECTED) { MetricsLogger.logProfileConnectionEvent(BluetoothMetricsProto.ProfileId.A2DP_SINK); } Intent intent = new Intent(BluetoothA2dpSink.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, prevState); intent.putExtra(BluetoothProfile.EXTRA_STATE, state); Loading
android/app/src/com/android/bluetooth/avrcpcontroller/AvrcpControllerStateMachine.java +4 −0 Original line number Diff line number Diff line Loading @@ -33,8 +33,10 @@ import android.os.Bundle; import android.os.Message; import android.util.Log; import com.android.bluetooth.BluetoothMetricsProto; import com.android.bluetooth.Utils; import com.android.bluetooth.a2dpsink.A2dpSinkService; import com.android.bluetooth.btservice.MetricsLogger; import com.android.bluetooth.btservice.ProfileService; import com.android.internal.util.State; import com.android.internal.util.StateMachine; Loading Loading @@ -189,6 +191,8 @@ class AvrcpControllerStateMachine extends StateMachine { mAddressedPlayer = new AvrcpPlayer(); mIsConnected = true; } MetricsLogger.logProfileConnectionEvent( BluetoothMetricsProto.ProfileId.AVRCP_CONTROLLER); Intent intent = new Intent( BluetoothAvrcpController.ACTION_CONNECTION_STATE_CHANGED); intent.putExtra(BluetoothProfile.EXTRA_PREVIOUS_STATE, Loading
android/app/src/com/android/bluetooth/btservice/AdapterService.java +1 −0 Original line number Diff line number Diff line Loading @@ -2478,6 +2478,7 @@ public class AdapterService extends Service { } } metricsBuilder.setNumBondedDevices(getBondedDevices().length); MetricsLogger.dumpProto(metricsBuilder); for (ProfileService profile : mRegisteredProfiles) { profile.dumpProto(metricsBuilder); } Loading
android/app/src/com/android/bluetooth/btservice/MetricsLogger.java 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * Copyright 2018 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.bluetooth.btservice; import com.android.bluetooth.BluetoothMetricsProto.BluetoothLog; import com.android.bluetooth.BluetoothMetricsProto.ProfileConnectionStats; import com.android.bluetooth.BluetoothMetricsProto.ProfileId; import java.util.HashMap; /** * Class with static methods for logging metrics data */ public class MetricsLogger { private static final HashMap<ProfileId, Integer> sProfileConnectionCounts = new HashMap<>(); /** * Log profile connection event by incrementing an internal counter for that profile. * This log persists over adapter enable/disable and only get cleared when metrics are * dumped or when Bluetooth process is killed. * * @param profileId Bluetooth profile that is connected at this event */ public static void logProfileConnectionEvent(ProfileId profileId) { synchronized (sProfileConnectionCounts) { sProfileConnectionCounts.merge(profileId, 1, Integer::sum); } } /** * Dump collected metrics into proto using a builder. * Clean up internal data after the dump. * * @param metricsBuilder proto builder for {@link BluetoothLog} */ public static void dumpProto(BluetoothLog.Builder metricsBuilder) { synchronized (sProfileConnectionCounts) { sProfileConnectionCounts.forEach( (key, value) -> metricsBuilder.addProfileConnectionStats( ProfileConnectionStats.newBuilder() .setProfileId(key) .setNumTimesConnected(value) .build())); sProfileConnectionCounts.clear(); } } }