Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 95df56ea authored by Jakub Tyszkowski's avatar Jakub Tyszkowski Committed by Gerrit Code Review
Browse files

Merge "AudioUtils: Extract a generic event logger"

parents ff9fedcf 78ba78c9
Loading
Loading
Loading
Loading
+22 −8
Original line number Diff line number Diff line
@@ -14,17 +14,14 @@
 * limitations under the License.
 */

package com.android.bluetooth.audio_util;
package com.android.bluetooth;

import android.util.Log;

import com.android.bluetooth.Utils;

import com.google.common.collect.EvictingQueue;


// This class is to store logs for Audio for given size.
public class BTAudioEventLogger {
/** This class is to store logs for given size. */
public class BluetoothEventLogger {
    private final String mTitle;
    private final EvictingQueue<Event> mEvents;

@@ -44,25 +41,29 @@ public class BTAudioEventLogger {
        }
    }

    public BTAudioEventLogger(int size, String title) {
    public BluetoothEventLogger(int size, String title) {
        mEvents = EvictingQueue.create(size);
        mTitle = title;
    }

    /** Add the event record */
    public synchronized void add(String msg) {
        Event event = new Event(msg);
        mEvents.add(event);
    }

    /** Add the event record and log message */
    public synchronized void logv(String tag, String msg) {
        add(msg);
        Log.v(tag, msg);
    }

    /** Add the event record and log debug message */
    public synchronized void logd(String tag, String msg) {
        logd(true, tag, msg);
    }

    /** Add the event record and log debug message */
    public synchronized void logd(boolean debug, String tag, String msg) {
        add(msg);
        if (debug) {
@@ -70,8 +71,21 @@ public class BTAudioEventLogger {
        }
    }

    /** Add the event record and log warning message */
    public synchronized void logw(String tag, String msg) {
        add(msg);
        Log.w(tag, msg);
    }

    /** Add the event record and log error message */
    public synchronized void loge(String tag, String msg) {
        add(msg);
        Log.e(tag, msg);
    }

    /** Dump all the events */
    public synchronized void dump(StringBuilder sb) {
        sb.append("BTAudio ").append(mTitle).append(":\n");
        sb.append(mTitle).append(":\n");
        for (Event event : mEvents) {
            sb.append("  ").append(event.toString()).append("\n");
        }
+9 −6
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;

import com.android.bluetooth.BluetoothEventLogger;
import com.android.bluetooth.Utils;
import com.android.internal.annotations.VisibleForTesting;

@@ -71,9 +72,10 @@ public class MediaPlayerList {
    private static final int BLUETOOTH_PLAYER_ID = 0;
    private static final String BLUETOOTH_PLAYER_NAME = "Bluetooth Player";
    private static final int ACTIVE_PLAYER_LOGGER_SIZE = 5;
    private static final String ACTIVE_PLAYER_LOGGER_TITLE = "Active Player Events";
    private static final String ACTIVE_PLAYER_LOGGER_TITLE = "BTAudio Active Player Events";
    private static final int AUDIO_PLAYBACK_STATE_LOGGER_SIZE = 15;
    private static final String AUDIO_PLAYBACK_STATE_LOGGER_TITLE = "Audio Playback State Events";
    private static final String AUDIO_PLAYBACK_STATE_LOGGER_TITLE =
            "BTAudio Audio Playback State Events";

    // mediaId's for the now playing list will be in the form of "NowPlayingId[XX]" where [XX]
    // is the Queue ID for the requested item.
@@ -90,9 +92,10 @@ public class MediaPlayerList {
    private MediaData mCurrMediaData = null;
    private final AudioManager mAudioManager;

    private final BTAudioEventLogger mActivePlayerLogger = new BTAudioEventLogger(
        ACTIVE_PLAYER_LOGGER_SIZE, ACTIVE_PLAYER_LOGGER_TITLE);
    private final BTAudioEventLogger mAudioPlaybackStateLogger = new BTAudioEventLogger(
    private final BluetoothEventLogger mActivePlayerLogger =
            new BluetoothEventLogger(ACTIVE_PLAYER_LOGGER_SIZE, ACTIVE_PLAYER_LOGGER_TITLE);
    private final BluetoothEventLogger mAudioPlaybackStateLogger =
            new BluetoothEventLogger(
                    AUDIO_PLAYBACK_STATE_LOGGER_SIZE, AUDIO_PLAYBACK_STATE_LOGGER_TITLE);

    private Map<Integer, MediaPlayerWrapper> mMediaPlayers =
+7 −4
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Looper;
import android.os.Message;
import android.util.Log;

import com.android.bluetooth.BluetoothEventLogger;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;

@@ -45,13 +46,13 @@ public class MediaPlayerWrapper {
    static boolean sTesting = false;
    private static final int PLAYBACK_STATE_CHANGE_EVENT_LOGGER_SIZE = 5;
    private static final String PLAYBACK_STATE_CHANGE_LOGGER_EVENT_TITLE =
            "Playback State change Event";
            "BTAudio Playback State change Event";

    final Context mContext;
    private MediaController mMediaController;
    private String mPackageName;
    private Looper mLooper;
    private final BTAudioEventLogger mPlaybackStateChangeEventLogger;
    private final BluetoothEventLogger mPlaybackStateChangeEventLogger;

    private MediaData mCurrentData;

@@ -88,8 +89,10 @@ public class MediaPlayerWrapper {
        mMediaController = controller;
        mPackageName = controller.getPackageName();
        mLooper = looper;
        mPlaybackStateChangeEventLogger = new BTAudioEventLogger(
                PLAYBACK_STATE_CHANGE_EVENT_LOGGER_SIZE, PLAYBACK_STATE_CHANGE_LOGGER_EVENT_TITLE);
        mPlaybackStateChangeEventLogger =
                new BluetoothEventLogger(
                        PLAYBACK_STATE_CHANGE_EVENT_LOGGER_SIZE,
                        PLAYBACK_STATE_CHANGE_LOGGER_EVENT_TITLE);

        mCurrentData = new MediaData(null, null, null);
        mCurrentData.queue = Util.toMetadataList(mContext, getQueue());
+4 −4
Original line number Diff line number Diff line
@@ -32,11 +32,11 @@ import android.sysprop.BluetoothProperties;
import android.text.TextUtils;
import android.util.Log;

import com.android.bluetooth.BluetoothEventLogger;
import com.android.bluetooth.BluetoothMetricsProto;
import com.android.bluetooth.R;
import com.android.bluetooth.Utils;
import com.android.bluetooth.a2dp.A2dpService;
import com.android.bluetooth.audio_util.BTAudioEventLogger;
import com.android.bluetooth.audio_util.MediaData;
import com.android.bluetooth.audio_util.MediaPlayerList;
import com.android.bluetooth.audio_util.MediaPlayerWrapper;
@@ -63,10 +63,10 @@ public class AvrcpTargetService extends ProfileService {

    private static final int AVRCP_MAX_VOL = 127;
    private static final int MEDIA_KEY_EVENT_LOGGER_SIZE = 20;
    private static final String MEDIA_KEY_EVENT_LOGGER_TITLE = "Media Key Events";
    private static final String MEDIA_KEY_EVENT_LOGGER_TITLE = "BTAudio Media Key Events";
    private static int sDeviceMaxVolume = 0;
    private final BTAudioEventLogger mMediaKeyEventLogger = new BTAudioEventLogger(
            MEDIA_KEY_EVENT_LOGGER_SIZE, MEDIA_KEY_EVENT_LOGGER_TITLE);
    private final BluetoothEventLogger mMediaKeyEventLogger =
            new BluetoothEventLogger(MEDIA_KEY_EVENT_LOGGER_SIZE, MEDIA_KEY_EVENT_LOGGER_TITLE);

    private AvrcpVersion mAvrcpVersion;
    private MediaPlayerList mMediaPlayerList;
+4 −4
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import android.media.AudioDeviceInfo;
import android.media.AudioManager;
import android.util.Log;

import com.android.bluetooth.audio_util.BTAudioEventLogger;
import com.android.bluetooth.BluetoothEventLogger;
import com.android.internal.annotations.VisibleForTesting;

import java.util.HashMap;
@@ -42,7 +42,7 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
    // All volumes are stored at system volume values, not AVRCP values
    private static final String VOLUME_MAP = "bluetooth_volume_map";
    private static final String VOLUME_REJECTLIST = "absolute_volume_rejectlist";
    private static final String VOLUME_CHANGE_LOG_TITLE = "Volume Events";
    private static final String VOLUME_CHANGE_LOG_TITLE = "BTAudio Volume Events";

    @VisibleForTesting
    static final int AVRCP_MAX_VOL = 127;
@@ -50,8 +50,8 @@ class AvrcpVolumeManager extends AudioDeviceCallback {
    private static final int VOLUME_CHANGE_LOGGER_SIZE = 30;
    private static int sDeviceMaxVolume = 0;
    private static int sNewDeviceVolume = 0;
    private final BTAudioEventLogger mVolumeEventLogger = new BTAudioEventLogger(
            VOLUME_CHANGE_LOGGER_SIZE, VOLUME_CHANGE_LOG_TITLE);
    private final BluetoothEventLogger mVolumeEventLogger =
            new BluetoothEventLogger(VOLUME_CHANGE_LOGGER_SIZE, VOLUME_CHANGE_LOG_TITLE);

    Context mContext;
    AudioManager mAudioManager;