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

Commit 8cb24b2d authored by Yiyi Shen's avatar Yiyi Shen Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] Avoid MetricsFeatureProvider#action with taggedData" into main

parents 2da2cf8f 4995aa21
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -544,22 +544,19 @@ public class AudioSharingCallAudioPreferenceController extends AudioSharingBaseP
                                                    : ChangeCallAudioType.CONNECTED_EARLIER;
                                }
                            }
                            Pair<Integer, Object>[] eventData =
                                    new Pair[] {
                            ImmutableList<Pair<Integer, Object>> eventData =
                                    ImmutableList.of(
                                            Pair.create(
                                                    METRIC_KEY_DEVICE_CONNECTION_TYPE.getId(),
                                                    type.getName()),
                                            Pair.create(
                                                    METRIC_KEY_DEVICE_IS_TEMP_BOND.getId(),
                                                    BluetoothUtils.isTemporaryBondDevice(
                                                                target.getDevice())
                                                        ? 1
                                                        : 0)
                                    };
                                                            target.getDevice())));
                            mMetricsFeatureProvider.action(
                                    mContext,
                                    SettingsEnums.ACTION_AUDIO_SHARING_CHANGE_CALL_AUDIO,
                                    eventData);
                                    eventData.toString());
                        });
    }
}
+12 −7
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.bluetooth.BluetoothLeBroadcastMetadataExt;
import com.android.settingslib.bluetooth.BluetoothUtils;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;

import java.nio.charset.StandardCharsets;
@@ -74,7 +75,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
    }

    @Nullable private static DialogEventListener sListener;
    private static Pair<Integer, Object>[] sEventData = new Pair[0];
    private static ImmutableList<Pair<Integer, Object>> sEventData = ImmutableList.of();
    @Nullable private static Fragment sHost;

    AudioSharingFeatureProvider audioSharingFeatureProvider =
@@ -99,7 +100,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
            @NonNull List<AudioSharingDeviceItem> deviceItems,
            @Nullable BluetoothLeBroadcastMetadata metadata,
            @NonNull DialogEventListener listener,
            @NonNull Pair<Integer, Object>[] eventData) {
            @NonNull ImmutableList<Pair<Integer, Object>> eventData) {
        if (host == null) {
            Log.d(TAG, "Fail to show dialog, host is null");
            return;
@@ -145,7 +146,7 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {
    /** Test only: get the event data passed to the dialog. */
    @VisibleForTesting
    @NonNull
    Pair<Integer, Object>[] getEventData() {
    ImmutableList<Pair<Integer, Object>> getEventData() {
        return sEventData;
    }

@@ -289,15 +290,19 @@ public class AudioSharingDialogFragment extends InstrumentedDialogFragment {

    private void logDialogPositiveBtnClick() {
        mMetricsFeatureProvider.action(
                getContext(),
                getMetricsCategory(),
                SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_POSITIVE_BTN_CLICKED,
                sEventData);
                getMetricsCategory(),
                sEventData.toString(),
                /* changedPreferenceIntValue= */ 0);
    }

    private void logDialogNegativeBtnClick() {
        mMetricsFeatureProvider.action(
                getContext(),
                getMetricsCategory(),
                SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED,
                sEventData);
                getMetricsCategory(),
                sEventData.toString(),
                /* changedPreferenceIntValue= */ 0);
    }
}
+29 −16
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.connecteddevice.audiosharing;

import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.MetricKey.METRIC_KEY_DEVICE_IS_PRIMARY;
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.MetricKey.METRIC_KEY_DEVICE_IS_TEMP_BOND;
import static com.android.settings.connecteddevice.audiosharing.AudioSharingUtils.MetricKey.METRIC_KEY_VALUE;
import static com.android.settingslib.bluetooth.LocalBluetoothLeBroadcast.EXTRA_START_LE_AUDIO_SHARING;

import android.app.settings.SettingsEnums;
@@ -255,7 +256,7 @@ public class AudioSharingDialogHandler {
                        mIsStoppingBroadcast = true;
                        AudioSharingUtils.stopBroadcasting(mLocalBtManager);
                    };
            Pair<Integer, Object>[] eventData =
            ImmutableList<Pair<Integer, Object>> eventData =
                    AudioSharingUtils.buildAudioSharingDialogEventData(
                            mHostMetricsCategory,
                            SettingsEnums.DIALOG_STOP_AUDIO_SHARING,
@@ -299,10 +300,13 @@ public class AudioSharingDialogHandler {
                Log.d(TAG, "Auto add sink with the same group to the sharing: " + deviceAddress);
                if (mAssistant != null && mBroadcast != null) {
                    mMetricsFeatureProvider.action(
                            mContext,
                            mHostMetricsCategory,
                            SettingsEnums.ACTION_AUDIO_SHARING_ADD_SOURCE,
                            mHostMetricsCategory,
                            AudioSharingUtils.buildAddSourceEventData(
                                    mHostMetricsCategory, /* userTriggered= */ false));
                                            mHostMetricsCategory, /* userTriggered= */ false)
                                    .toString(),
                            /* changedPreferenceIntValue= */ 0);
                    mAssistant.addSource(
                            btDevice,
                            mBroadcast.getLatestBluetoothLeBroadcastMetadata(),
@@ -331,7 +335,7 @@ public class AudioSharingDialogHandler {
                                            SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE,
                                            userTriggered));
                        };
                Pair<Integer, Object>[] eventData =
                ImmutableList<Pair<Integer, Object>> eventData =
                        AudioSharingUtils.buildAudioSharingDialogEventData(
                                mHostMetricsCategory,
                                SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_DEVICE,
@@ -364,7 +368,7 @@ public class AudioSharingDialogHandler {
                            @Override
                            public void onCancelClick() {}
                        };
                Pair<Integer, Object>[] eventData =
                ImmutableList<Pair<Integer, Object>> eventData =
                        AudioSharingUtils.buildAudioSharingDialogEventData(
                                mHostMetricsCategory,
                                SettingsEnums.DIALOG_AUDIO_SHARING_ADD_DEVICE,
@@ -420,7 +424,7 @@ public class AudioSharingDialogHandler {
                            }
                        };

                Pair<Integer, Object>[] eventData =
                ImmutableList<Pair<Integer, Object>> eventData =
                        AudioSharingUtils.buildAudioSharingDialogEventData(
                                mHostMetricsCategory,
                                SettingsEnums.DIALOG_START_AUDIO_SHARING,
@@ -566,19 +570,22 @@ public class AudioSharingDialogHandler {
                        == BluetoothUtils.getPrimaryGroupIdForBroadcast(
                                mContext.getContentResolver(), mLocalBtManager);
        boolean isTempBond = devices.stream().anyMatch(BluetoothUtils::isTemporaryBondDevice);
        Pair<Integer, Object>[] eventData =
                new Pair[] {
                    Pair.create(METRIC_KEY_DEVICE_IS_PRIMARY.getId(), isPrimary ? 1 : 0),
                    Pair.create(METRIC_KEY_DEVICE_IS_TEMP_BOND.getId(), isTempBond ? 1 : 0)
                };
        ImmutableList<Pair<Integer, Object>> eventData =
                ImmutableList.of(
                        Pair.create(METRIC_KEY_DEVICE_IS_PRIMARY.getId(), isPrimary),
                        Pair.create(METRIC_KEY_DEVICE_IS_TEMP_BOND.getId(), isTempBond));
        mMetricsFeatureProvider.action(
                mContext, SettingsEnums.ACTION_AUDIO_SHARING_REMOVE_SOURCE, eventData);
                mHostMetricsCategory,
                SettingsEnums.ACTION_AUDIO_SHARING_REMOVE_SOURCE,
                mHostMetricsCategory,
                eventData.toString(),
                /* changedPreferenceIntValue= */ 0);
    }

    private void addSourceForGroup(
            int groupId,
            Map<Integer, List<BluetoothDevice>> groupedDevices,
            Pair<Integer, Object>[] eventData) {
            ImmutableList<Pair<Integer, Object>> eventData) {
        if (mBroadcast == null || mAssistant == null) {
            Log.d(TAG, "Fail to add source due to null profiles, group = " + groupId);
            return;
@@ -595,7 +602,11 @@ public class AudioSharingDialogHandler {
                                        mBroadcast.getLatestBluetoothLeBroadcastMetadata(),
                                        /* isGroupOp= */ false));
        mMetricsFeatureProvider.action(
                mContext, SettingsEnums.ACTION_AUDIO_SHARING_ADD_SOURCE, eventData);
                mHostMetricsCategory,
                SettingsEnums.ACTION_AUDIO_SHARING_ADD_SOURCE,
                mHostMetricsCategory,
                eventData.toString(),
                /* changedPreferenceIntValue= */ 0);
    }

    private boolean isBroadcasting() {
@@ -621,9 +632,11 @@ public class AudioSharingDialogHandler {
                                                .getMetricsCategory();
                            }
                            mMetricsFeatureProvider.action(
                                    mContext,
                                    mHostMetricsCategory,
                                    SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_AUTO_DISMISS,
                                    pageId);
                                    mHostMetricsCategory,
                                    /* changedPreferenceKey= */ METRIC_KEY_VALUE.toString(),
                                    /* changedPreferenceIntValue= */ pageId);
                        });
    }
}
+11 −7
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag

    @Nullable private static DialogEventListener sListener;
    @Nullable private static CachedBluetoothDevice sNewDevice;
    private static Pair<Integer, Object>[] sEventData = new Pair[0];
    private static ImmutableList<Pair<Integer, Object>> sEventData = ImmutableList.of();

    @Override
    public int getMetricsCategory() {
@@ -86,7 +86,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
            @NonNull List<AudioSharingDeviceItem> deviceItems,
            @NonNull CachedBluetoothDevice newDevice,
            @NonNull DialogEventListener listener,
            @NonNull Pair<Integer, Object>[] eventData) {
            @NonNull ImmutableList<Pair<Integer, Object>> eventData) {
        if (host == null) {
            Log.d(TAG, "Fail to show dialog, host is null");
            return false;
@@ -151,7 +151,7 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
    /** Test only: get the event data passed to the dialog. */
    @VisibleForTesting
    @NonNull
    Pair<Integer, Object>[] getEventData() {
    ImmutableList<Pair<Integer, Object>> getEventData() {
        return sEventData;
    }

@@ -164,9 +164,11 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
        View.OnClickListener onNegativeBtnClicked =
                v -> {
                    mMetricsFeatureProvider.action(
                            getContext(),
                            getMetricsCategory(),
                            SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED,
                            sEventData);
                            getMetricsCategory(),
                            sEventData.toString(),
                            /* changedPreferenceIntValue= */ 0);
                    dismiss();
                };
        AudioSharingDialogFactory.DialogBuilder builder =
@@ -186,9 +188,11 @@ public class AudioSharingDisconnectDialogFragment extends InstrumentedDialogFrag
                    if (sListener != null) {
                        sListener.onItemClick(item);
                        mMetricsFeatureProvider.action(
                                getContext(),
                                getMetricsCategory(),
                                SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_POSITIVE_BTN_CLICKED,
                                sEventData);
                                getMetricsCategory(),
                                sEventData.toString(),
                                /* changedPreferenceIntValue= */ 0);
                    }
                    dismiss();
                };
+13 −7
Original line number Diff line number Diff line
@@ -39,6 +39,8 @@ import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.flags.Flags;

import com.google.common.collect.ImmutableList;

import java.util.List;

public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
@@ -59,7 +61,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {

    @Nullable private static DialogEventListener sListener;
    @Nullable private static CachedBluetoothDevice sNewDevice;
    private static Pair<Integer, Object>[] sEventData = new Pair[0];
    private static ImmutableList<Pair<Integer, Object>> sEventData = ImmutableList.of();

    @Override
    public int getMetricsCategory() {
@@ -85,7 +87,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
            @NonNull List<AudioSharingDeviceItem> deviceItems,
            @NonNull CachedBluetoothDevice newDevice,
            @NonNull DialogEventListener listener,
            @NonNull Pair<Integer, Object>[] eventData) {
            @NonNull ImmutableList<Pair<Integer, Object>> eventData) {
        if (host == null) {
            Log.d(TAG, "Fail to show dialog, host is null");
            return false;
@@ -150,7 +152,7 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
    /** Test only: get the event data passed to the dialog. */
    @VisibleForTesting
    @NonNull
    Pair<Integer, Object>[] getEventData() {
    ImmutableList<Pair<Integer, Object>> getEventData() {
        return sEventData;
    }

@@ -166,9 +168,11 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
                    if (sListener != null) {
                        sListener.onShareClick();
                        mMetricsFeatureProvider.action(
                                getContext(),
                                getMetricsCategory(),
                                SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_POSITIVE_BTN_CLICKED,
                                sEventData);
                                getMetricsCategory(),
                                sEventData.toString(),
                                /* changedPreferenceIntValue= */ 0);
                    }
                    dismiss();
                };
@@ -177,9 +181,11 @@ public class AudioSharingJoinDialogFragment extends InstrumentedDialogFragment {
                    if (sListener != null) {
                        sListener.onCancelClick();
                        mMetricsFeatureProvider.action(
                                getContext(),
                                getMetricsCategory(),
                                SettingsEnums.ACTION_AUDIO_SHARING_DIALOG_NEGATIVE_BTN_CLICKED,
                                sEventData);
                                getMetricsCategory(),
                                sEventData.toString(),
                                /* changedPreferenceIntValue= */ 0);
                    }
                    dismiss();
                };
Loading