Merge "[Audiosharing] Refine sharing stop dialog." into main
This commit is contained in:
@@ -19,11 +19,16 @@ package com.android.settings.connecteddevice.audiosharing;
|
|||||||
import android.app.Dialog;
|
import android.app.Dialog;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||||
|
|
||||||
public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
||||||
@@ -68,22 +73,20 @@ public class AudioSharingStopDialogFragment extends InstrumentedDialogFragment {
|
|||||||
Bundle arguments = requireArguments();
|
Bundle arguments = requireArguments();
|
||||||
String newDeviceName = arguments.getString(BUNDLE_KEY_NEW_DEVICE_NAME);
|
String newDeviceName = arguments.getString(BUNDLE_KEY_NEW_DEVICE_NAME);
|
||||||
final AlertDialog.Builder builder =
|
final AlertDialog.Builder builder =
|
||||||
new AlertDialog.Builder(getActivity())
|
new AlertDialog.Builder(getActivity()).setCancelable(false);
|
||||||
.setTitle("Stop sharing audio?")
|
LayoutInflater inflater = LayoutInflater.from(builder.getContext());
|
||||||
.setCancelable(false);
|
View customTitle =
|
||||||
|
inflater.inflate(R.layout.dialog_custom_title_audio_sharing, /* parent= */ null);
|
||||||
|
ImageView icon = customTitle.findViewById(R.id.title_icon);
|
||||||
|
icon.setImageResource(R.drawable.ic_warning_24dp);
|
||||||
|
TextView title = customTitle.findViewById(R.id.title_text);
|
||||||
|
title.setText("Stop sharing audio?");
|
||||||
builder.setMessage(
|
builder.setMessage(
|
||||||
newDeviceName + " is connected, devices in audio sharing will disconnect.");
|
newDeviceName + " wants to connect, headphones in audio sharing will disconnect.");
|
||||||
builder.setPositiveButton(
|
builder.setPositiveButton(
|
||||||
"Stop sharing",
|
"Stop sharing", (dialog, which) -> sListener.onStopSharingClick());
|
||||||
(dialog, which) -> {
|
builder.setNegativeButton("Cancel", (dialog, which) -> dismiss());
|
||||||
sListener.onStopSharingClick();
|
AlertDialog dialog = builder.setCustomTitle(customTitle).create();
|
||||||
});
|
|
||||||
builder.setNegativeButton(
|
|
||||||
"Cancel",
|
|
||||||
(dialog, which) -> {
|
|
||||||
dismiss();
|
|
||||||
});
|
|
||||||
AlertDialog dialog = builder.create();
|
|
||||||
dialog.setCanceledOnTouchOutside(false);
|
dialog.setCanceledOnTouchOutside(false);
|
||||||
return dialog;
|
return dialog;
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,122 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.settings.connecteddevice.audiosharing;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.robolectric.shadows.ShadowLooper.shadowMainLooper;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothStatusCodes;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsDisabled;
|
||||||
|
import android.platform.test.annotations.RequiresFlagsEnabled;
|
||||||
|
import android.platform.test.flag.junit.CheckFlagsRule;
|
||||||
|
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
|
import com.android.settings.flags.Flags;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
|
||||||
|
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.shadow.api.Shadow;
|
||||||
|
import org.robolectric.shadows.androidx.fragment.FragmentController;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
@Config(
|
||||||
|
shadows = {
|
||||||
|
ShadowAlertDialogCompat.class,
|
||||||
|
ShadowBluetoothAdapter.class,
|
||||||
|
})
|
||||||
|
public class AudioSharingStopDialogFragmentTest {
|
||||||
|
|
||||||
|
@Rule public final MockitoRule mocks = MockitoJUnit.rule();
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final CheckFlagsRule mCheckFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule();
|
||||||
|
|
||||||
|
private static final String TEST_DEVICE_NAME = "test";
|
||||||
|
|
||||||
|
private Fragment mParent;
|
||||||
|
private AudioSharingStopDialogFragment mFragment;
|
||||||
|
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||||
|
mShadowBluetoothAdapter.setEnabled(true);
|
||||||
|
mShadowBluetoothAdapter.setIsLeAudioBroadcastSourceSupported(
|
||||||
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
|
mShadowBluetoothAdapter.setIsLeAudioBroadcastAssistantSupported(
|
||||||
|
BluetoothStatusCodes.FEATURE_SUPPORTED);
|
||||||
|
mFragment = new AudioSharingStopDialogFragment();
|
||||||
|
mParent = new Fragment();
|
||||||
|
FragmentController.setupFragment(
|
||||||
|
mParent, FragmentActivity.class, /* containerViewId= */ 0, /* bundle= */ null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
ShadowAlertDialogCompat.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsDisabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_flagOff_dialogNotExist() {
|
||||||
|
mFragment.show(mParent, TEST_DEVICE_NAME, () -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
assertThat(dialog).isNull();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_clickCancel_dialogDismiss() {
|
||||||
|
mFragment.show(mParent, TEST_DEVICE_NAME, () -> {});
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
dialog.findViewById(android.R.id.button2).performClick();
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_LE_AUDIO_SHARING)
|
||||||
|
public void onCreateDialog_clickShare_callbackTriggered() {
|
||||||
|
AtomicBoolean isStopBtnClicked = new AtomicBoolean(false);
|
||||||
|
mFragment.show(mParent, TEST_DEVICE_NAME, () -> isStopBtnClicked.set(true));
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
AlertDialog dialog = ShadowAlertDialogCompat.getLatestAlertDialog();
|
||||||
|
dialog.findViewById(android.R.id.button1).performClick();
|
||||||
|
shadowMainLooper().idle();
|
||||||
|
assertThat(dialog.isShowing()).isFalse();
|
||||||
|
assertThat(isStopBtnClicked.get()).isTrue();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user