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

Commit 1d10e6bb authored by Chelsea Hao's avatar Chelsea Hao Committed by Android (Google) Code Review
Browse files

Merge "[Audiosharing] When bt is off or unsupported, we show "Please connect a...

Merge "[Audiosharing] When bt is off or unsupported, we show "Please connect a device" dialog after camera scans a QR code" into main
parents a98694a3 d187437c
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.settings.connecteddevice.audiosharing.audiostreams;

import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
@@ -51,6 +52,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
    @Override
    protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) {
        if (BluetoothUtils.isAudioSharingUIAvailable(this)
                && !isBluetoothUnsupportedOrOff()
                && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent");
            mSavedState = savedState;
@@ -68,6 +70,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
    @Override
    public void onStart() {
        if (BluetoothUtils.isAudioSharingUIAvailable(this)
                && !isBluetoothUnsupportedOrOff()
                && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            Log.d(TAG, "onStart() : supported but not ready, listen to service ready");
            if (mProfileManager != null) {
@@ -88,6 +91,7 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
    @Override
    public void onServiceConnected() {
        if (BluetoothUtils.isAudioSharingUIAvailable(this)
                && !isBluetoothUnsupportedOrOff()
                && AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
            if (mProfileManager != null) {
                mProfileManager.removeServiceListener(this);
@@ -106,4 +110,9 @@ public class AudioStreamConfirmDialogActivity extends SettingsActivity
    protected boolean isValidFragment(String fragmentName) {
        return AudioStreamConfirmDialog.class.getName().equals(fragmentName);
    }

    private static boolean isBluetoothUnsupportedOrOff() {
        var adapter = BluetoothAdapter.getDefaultAdapter();
        return adapter == null || !adapter.isEnabled();
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -139,6 +139,15 @@ public class AudioStreamConfirmDialogActivityTest {
        verify(mLocalBluetoothProfileManager, never()).addServiceListener(any());
    }

    @Test
    public void setupActivity_serviceNotReady_bluetoothOff_doNothing() {
        when(mAssistant.isProfileReady()).thenReturn(false);
        mShadowBluetoothAdapter.setEnabled(false);
        mActivity = Robolectric.setupActivity(AudioStreamConfirmDialogActivity.class);

        verify(mLocalBluetoothProfileManager, never()).addServiceListener(any());
    }

    @Test
    public void onStop_unregisterCallback() {
        mActivity = Robolectric.setupActivity(AudioStreamConfirmDialogActivity.class);