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

Commit 027baad9 authored by Angela Wang's avatar Angela Wang
Browse files

Add launch source for hearing device dialog logs

By knowing where the dialog is launched can help us better improve the
user flow.

Flag: EXEMPT simple log added
Bug: 354606934
Test: manually check on go/atomviewer
Test: atest HearingDevicesTileTest HearingDevicesDialogDelegateTest HearingDevicesDialogManagerTest
Change-Id: Id99af22024dca5ab93bcd07552d567cf4973cdb5
parent 31b47abb
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package com.android.systemui.accessibility.hearingaid;

import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.bluetooth.BluetoothDevice;
import android.testing.TestableLooper;

import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -51,6 +51,8 @@ public class HearingDevicesDialogManagerTest extends SysuiTestCase {
    @Rule
    public MockitoRule mockito = MockitoJUnit.rule();

    private static final int TEST_LAUNCH_SOURCE_ID = 1;

    private final FakeExecutor mMainExecutor = new FakeExecutor(new FakeSystemClock());
    private final FakeExecutor mBackgroundExecutor = new FakeExecutor(new FakeSystemClock());
    @Mock
@@ -70,7 +72,7 @@ public class HearingDevicesDialogManagerTest extends SysuiTestCase {

    @Before
    public void setUp() {
        when(mDialogFactory.create(anyBoolean())).thenReturn(mDialogDelegate);
        when(mDialogFactory.create(anyBoolean(), anyInt())).thenReturn(mDialogDelegate);
        when(mDialogDelegate.createDialog()).thenReturn(mDialog);

        mManager = new HearingDevicesDialogManager(
@@ -86,21 +88,22 @@ public class HearingDevicesDialogManagerTest extends SysuiTestCase {
    public void showDialog_existHearingDevice_showPairNewDeviceFalse() {
        when(mDevicesChecker.isAnyPairedHearingDevice()).thenReturn(true);

        mManager.showDialog(mExpandable);
        mManager.showDialog(mExpandable, TEST_LAUNCH_SOURCE_ID);
        mBackgroundExecutor.runAllReady();
        mMainExecutor.runAllReady();

        verify(mDialogFactory).create(eq(/* showPairNewDevice= */ false));
        verify(mDialogFactory).create(eq(/* showPairNewDevice= */ false),
                eq(TEST_LAUNCH_SOURCE_ID));
    }

    @Test
    public void showDialog_noHearingDevice_showPairNewDeviceTrue() {
        when(mDevicesChecker.isAnyPairedHearingDevice()).thenReturn(false);

        mManager.showDialog(mExpandable);
        mManager.showDialog(mExpandable, TEST_LAUNCH_SOURCE_ID);
        mBackgroundExecutor.runAllReady();
        mMainExecutor.runAllReady();

        verify(mDialogFactory).create(eq(/* showPairNewDevice= */ true));
        verify(mDialogFactory).create(eq(/* showPairNewDevice= */ true), eq(TEST_LAUNCH_SOURCE_ID));
    }
}
+19 −12
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import androidx.annotation.VisibleForTesting;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.internal.logging.UiEventLogger;
import com.android.settingslib.bluetooth.BluetoothCallback;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.HapClientProfile;
@@ -105,7 +104,8 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
    private final AudioManager mAudioManager;
    private final LocalBluetoothProfileManager mProfileManager;
    private final HapClientProfile mHapClientProfile;
    private final UiEventLogger mUiEventLogger;
    private final HearingDevicesUiEventLogger mUiEventLogger;
    private final int mLaunchSourceId;
    private HearingDevicesListAdapter mDeviceListAdapter;
    private HearingDevicesPresetsController mPresetsController;
    private Context mApplicationContext;
@@ -153,20 +153,22 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
    public interface Factory {
        /** Create a {@link HearingDevicesDialogDelegate} instance */
        HearingDevicesDialogDelegate create(
                boolean showPairNewDevice);
                boolean showPairNewDevice,
                @HearingDevicesUiEventLogger.LaunchSourceId int launchSource);
    }

    @AssistedInject
    public HearingDevicesDialogDelegate(
            @Application Context applicationContext,
            @Assisted boolean showPairNewDevice,
            @Assisted @HearingDevicesUiEventLogger.LaunchSourceId int launchSourceId,
            SystemUIDialog.Factory systemUIDialogFactory,
            ActivityStarter activityStarter,
            DialogTransitionAnimator dialogTransitionAnimator,
            @Nullable LocalBluetoothManager localBluetoothManager,
            @Main Handler handler,
            AudioManager audioManager,
            UiEventLogger uiEventLogger) {
            HearingDevicesUiEventLogger uiEventLogger) {
        mApplicationContext = applicationContext;
        mShowPairNewDevice = showPairNewDevice;
        mSystemUIDialogFactory = systemUIDialogFactory;
@@ -178,6 +180,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
        mProfileManager = localBluetoothManager.getProfileManager();
        mHapClientProfile = mProfileManager.getHapClientProfile();
        mUiEventLogger = uiEventLogger;
        mLaunchSourceId = launchSourceId;
    }

    @Override
@@ -191,7 +194,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,

    @Override
    public void onDeviceItemGearClicked(@NonNull DeviceItem deviceItem, @NonNull View view) {
        mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_GEAR_CLICK);
        mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_GEAR_CLICK, mLaunchSourceId);
        dismissDialogIfExists();
        Intent intent = new Intent(ACTION_BLUETOOTH_DEVICE_DETAILS);
        Bundle bundle = new Bundle();
@@ -207,15 +210,17 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
        CachedBluetoothDevice cachedBluetoothDevice = deviceItem.getCachedBluetoothDevice();
        switch (deviceItem.getType()) {
            case ACTIVE_MEDIA_BLUETOOTH_DEVICE, CONNECTED_BLUETOOTH_DEVICE -> {
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_DISCONNECT);
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_DISCONNECT,
                        mLaunchSourceId);
                cachedBluetoothDevice.disconnect();
            }
            case AVAILABLE_MEDIA_BLUETOOTH_DEVICE -> {
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_SET_ACTIVE);
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_SET_ACTIVE,
                        mLaunchSourceId);
                cachedBluetoothDevice.setActive();
            }
            case SAVED_BLUETOOTH_DEVICE -> {
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_CONNECT);
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_CONNECT, mLaunchSourceId);
                cachedBluetoothDevice.connect();
            }
        }
@@ -275,7 +280,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
        if (mLocalBluetoothManager == null) {
            return;
        }
        mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_DIALOG_SHOW);
        mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_DIALOG_SHOW, mLaunchSourceId);
        mPairButton = dialog.requireViewById(R.id.pair_new_device_button);
        mDeviceList = dialog.requireViewById(R.id.device_list);
        mPresetSpinner = dialog.requireViewById(R.id.preset_spinner);
@@ -363,7 +368,8 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
        mPresetSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_PRESET_SELECT);
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_PRESET_SELECT,
                        mLaunchSourceId);
                mPresetsController.selectPreset(
                        mPresetsController.getAllPresetInfo().get(position).getIndex());
            }
@@ -381,7 +387,7 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
    private void setupPairNewDeviceButton(SystemUIDialog dialog, @Visibility int visibility) {
        if (visibility == VISIBLE) {
            mPairButton.setOnClickListener(v -> {
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_PAIR);
                mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_PAIR, mLaunchSourceId);
                dismissDialogIfExists();
                final Intent intent = new Intent(Settings.ACTION_HEARING_DEVICE_PAIRING_SETTINGS);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
@@ -485,7 +491,8 @@ public class HearingDevicesDialogDelegate implements SystemUIDialog.Delegate,
            final String name = intent.getComponent() != null
                    ? intent.getComponent().flattenToString()
                    : intent.getPackage() + "/" + intent.getAction();
            mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_RELATED_TOOL_CLICK, 0, name);
            mUiEventLogger.log(HearingDevicesUiEvent.HEARING_DEVICES_RELATED_TOOL_CLICK,
                    mLaunchSourceId, name);
            dismissDialogIfExists();
            mActivityStarter.postStartActivityDismissingKeyguard(intent, /* delay= */ 0,
                    mDialogTransitionAnimator.createActivityTransitionController(view));
+5 −2
Original line number Diff line number Diff line
@@ -70,8 +70,10 @@ public class HearingDevicesDialogManager {
     * Shows the dialog.
     *
     * @param expandable {@link Expandable} from which the dialog is shown.
     * @param launchSourceId the id indicates where the dialog is launched from.
     */
    public void showDialog(Expandable expandable) {
    public void showDialog(Expandable expandable,
            @HearingDevicesUiEventLogger.LaunchSourceId int launchSourceId) {
        if (mDialog != null) {
            if (DEBUG) {
                Log.d(TAG, "HearingDevicesDialog already showing. Destroy it first.");
@@ -91,7 +93,8 @@ public class HearingDevicesDialogManager {
                });
        pairedHearingDeviceCheckTask.addListener(() -> {
            try {
                mDialog = mDialogFactory.create(!pairedHearingDeviceCheckTask.get()).createDialog();
                mDialog = mDialogFactory.create(!pairedHearingDeviceCheckTask.get(),
                        launchSourceId).createDialog();

                if (expandable != null) {
                    DialogTransitionAnimator.Controller controller =
+3 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.systemui.accessibility.hearingaid;

import static com.android.systemui.accessibility.hearingaid.HearingDevicesUiEventLogger.LAUNCH_SOURCE_A11Y;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -46,7 +48,7 @@ public class HearingDevicesDialogReceiver extends BroadcastReceiver {
        }

        if (ACTION.equals(intent.getAction())) {
            mDialogManager.showDialog(/* view= */ null);
            mDialogManager.showDialog(/* expandable= */ null, LAUNCH_SOURCE_A11Y);
        }
    }
}
+35 −0
Original line number Diff line number Diff line
@@ -14,38 +14,22 @@
 * limitations under the License.
 */

package com.android.systemui.accessibility.hearingaid;
package com.android.systemui.accessibility.hearingaid

import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger

public enum HearingDevicesUiEvent implements UiEventLogger.UiEventEnum {
enum class HearingDevicesUiEvent(private val id: Int) : UiEventLogger.UiEventEnum {

    @UiEvent(doc = "Hearing devices dialog is shown")
    HEARING_DEVICES_DIALOG_SHOW(1848),
    @UiEvent(doc = "Pair new device")
    HEARING_DEVICES_PAIR(1849),
    @UiEvent(doc = "Connect to the device")
    HEARING_DEVICES_CONNECT(1850),
    @UiEvent(doc = "Disconnect from the device")
    HEARING_DEVICES_DISCONNECT(1851),
    @UiEvent(doc = "Set the device as active device")
    HEARING_DEVICES_SET_ACTIVE(1852),
    @UiEvent(doc = "Hearing devices dialog is shown") HEARING_DEVICES_DIALOG_SHOW(1848),
    @UiEvent(doc = "Pair new device") HEARING_DEVICES_PAIR(1849),
    @UiEvent(doc = "Connect to the device") HEARING_DEVICES_CONNECT(1850),
    @UiEvent(doc = "Disconnect from the device") HEARING_DEVICES_DISCONNECT(1851),
    @UiEvent(doc = "Set the device as active device") HEARING_DEVICES_SET_ACTIVE(1852),
    @UiEvent(doc = "Click on the device gear to enter device detail page")
    HEARING_DEVICES_GEAR_CLICK(1853),
    @UiEvent(doc = "Select a preset from preset spinner")
    HEARING_DEVICES_PRESET_SELECT(1854),
    @UiEvent(doc = "Click on related tool")
    HEARING_DEVICES_RELATED_TOOL_CLICK(1856);
    @UiEvent(doc = "Select a preset from preset spinner") HEARING_DEVICES_PRESET_SELECT(1854),
    @UiEvent(doc = "Click on related tool") HEARING_DEVICES_RELATED_TOOL_CLICK(1856);

    private final int mId;

    HearingDevicesUiEvent(int id) {
        mId = id;
    }

    @Override
    public int getId() {
        return mId;
    }
    override fun getId(): Int = this.id
}
Loading