Merge changes Iecf987cc,Ibbbb9e78
* changes: Remove unused variable Remove MediaOutputPanel and MediaOutputSlice
This commit is contained in:
@@ -18,8 +18,6 @@ package com.android.settings.media;
|
||||
|
||||
import static android.media.AudioManager.STREAM_DEVICES_CHANGED_ACTION;
|
||||
|
||||
import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -55,6 +53,8 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
private static final String TAG = "MediaDeviceUpdateWorker";
|
||||
private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
|
||||
|
||||
public static final String MEDIA_PACKAGE_NAME = "media_package_name";
|
||||
|
||||
protected final Context mContext;
|
||||
protected final Collection<MediaDevice> mMediaDevices = new CopyOnWriteArrayList<>();
|
||||
private final DevicesChangedBroadcastReceiver mReceiver;
|
||||
|
@@ -87,7 +87,7 @@ public class MediaOutputIndicatorSlice implements CustomSliceable {
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
// This Slice reflects active media device information and launch MediaOutputSlice. It does
|
||||
// This Slice reflects active media device information and launch MediaOutputDialog. It does
|
||||
// not contain its owned Slice data
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,415 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.media;
|
||||
|
||||
import static android.app.slice.Slice.EXTRA_RANGE_VALUE;
|
||||
import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.text.SpannableString;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.builders.ListBuilder;
|
||||
import androidx.slice.builders.SliceAction;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.bluetooth.BluetoothPairingDetail;
|
||||
import com.android.settings.core.SubSettingLauncher;
|
||||
import com.android.settings.slices.CustomSliceable;
|
||||
import com.android.settings.slices.SliceBackgroundWorker;
|
||||
import com.android.settings.slices.SliceBroadcastReceiver;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
import com.android.settingslib.media.MediaOutputSliceConstants;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Show the Media device that can be transfer the media.
|
||||
*/
|
||||
public class MediaOutputSlice implements CustomSliceable {
|
||||
|
||||
private static final String TAG = "MediaOutputSlice";
|
||||
private static final String MEDIA_DEVICE_ID = "media_device_id";
|
||||
private static final String MEDIA_GROUP_DEVICE = "media_group_device";
|
||||
private static final String MEDIA_GROUP_REQUEST = "media_group_request";
|
||||
private static final int NON_SLIDER_VALUE = -1;
|
||||
|
||||
public static final String MEDIA_PACKAGE_NAME = "media_package_name";
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
private MediaDeviceUpdateWorker mWorker;
|
||||
|
||||
public MediaOutputSlice(Context context) {
|
||||
mContext = context;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(MediaDeviceUpdateWorker worker) {
|
||||
mWorker = worker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Slice getSlice() {
|
||||
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
|
||||
.setAccentColor(COLOR_NOT_TINTED);
|
||||
if (!isVisible()) {
|
||||
Log.d(TAG, "getSlice() is not visible");
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
final Collection<MediaDevice> devices = getMediaDevices();
|
||||
final MediaDeviceUpdateWorker worker = getWorker();
|
||||
|
||||
if (worker.getSelectedMediaDevice().size() > 1) {
|
||||
// Insert group item to the first when it is available
|
||||
if (worker.getSessionVolumeMax() > 0 && !worker.hasAdjustVolumeUserRestriction()) {
|
||||
listBuilder.addInputRange(getGroupSliderRow());
|
||||
} else {
|
||||
listBuilder.addRow(getGroupRow());
|
||||
}
|
||||
// Add all other devices
|
||||
for (MediaDevice device : devices) {
|
||||
addRow(device, null /* connectedDevice */, listBuilder);
|
||||
}
|
||||
} else {
|
||||
final MediaDevice connectedDevice = worker.getCurrentConnectedMediaDevice();
|
||||
if (devices.size() == 1) {
|
||||
// Zero state
|
||||
final MediaDevice device = devices.iterator().next();
|
||||
addRow(device, device, listBuilder);
|
||||
// Add "pair new" only when local output device exists
|
||||
final int type = device.getDeviceType();
|
||||
if (type == MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE
|
||||
|| type == MediaDevice.MediaDeviceType.TYPE_3POINT5_MM_AUDIO_DEVICE
|
||||
|| type == MediaDevice.MediaDeviceType.TYPE_USB_C_AUDIO_DEVICE) {
|
||||
listBuilder.addRow(getPairNewRow());
|
||||
}
|
||||
} else {
|
||||
final boolean isTouched = worker.getIsTouched();
|
||||
// Fix the last top device when user press device to transfer.
|
||||
final MediaDevice topDevice = isTouched ? worker.getTopDevice() : connectedDevice;
|
||||
|
||||
if (topDevice != null) {
|
||||
addRow(topDevice, connectedDevice, listBuilder);
|
||||
worker.setTopDevice(topDevice);
|
||||
}
|
||||
|
||||
for (MediaDevice device : devices) {
|
||||
if (topDevice == null || !TextUtils.equals(topDevice.getId(), device.getId())) {
|
||||
addRow(device, connectedDevice, listBuilder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return listBuilder.build();
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getPairNewRow() {
|
||||
final Drawable d = mContext.getDrawable(R.drawable.ic_add_24dp);
|
||||
d.setColorFilter(new PorterDuffColorFilter(Utils.getColorAccentDefaultColor(mContext),
|
||||
PorterDuff.Mode.SRC_IN));
|
||||
final IconCompat icon = Utils.createIconWithDrawable(d);
|
||||
final String title = mContext.getString(R.string.bluetooth_pairing_pref_title);
|
||||
final Intent intent = new SubSettingLauncher(mContext)
|
||||
.setDestination(BluetoothPairingDetail.class.getName())
|
||||
.setTitleRes(R.string.bluetooth_pairing_page_title)
|
||||
.setSourceMetricsCategory(SettingsEnums.PANEL_MEDIA_OUTPUT)
|
||||
.toIntent();
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(
|
||||
PendingIntent.getActivity(mContext, 0 /* requestCode */, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE),
|
||||
IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp/*ic_add_blue_24dp*/),
|
||||
ListBuilder.ICON_IMAGE,
|
||||
mContext.getText(R.string.bluetooth_pairing_pref_title));
|
||||
final ListBuilder.RowBuilder builder = new ListBuilder.RowBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setPrimaryAction(primarySliceAction);
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ListBuilder.InputRangeBuilder getGroupSliderRow() {
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_speaker_group_black_24dp);
|
||||
final CharSequence sessionName = getWorker().getSessionName();
|
||||
final CharSequence title = TextUtils.isEmpty(sessionName)
|
||||
? mContext.getString(R.string.media_output_group) : sessionName;
|
||||
final PendingIntent broadcastAction =
|
||||
getBroadcastIntent(mContext, MEDIA_GROUP_DEVICE, MEDIA_GROUP_DEVICE.hashCode());
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(broadcastAction, icon,
|
||||
ListBuilder.ICON_IMAGE, title);
|
||||
final ListBuilder.InputRangeBuilder builder = new ListBuilder.InputRangeBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setPrimaryAction(primarySliceAction)
|
||||
.setInputAction(getSliderInputAction(MEDIA_GROUP_DEVICE.hashCode(),
|
||||
MEDIA_GROUP_DEVICE))
|
||||
.setMax(getWorker().getSessionVolumeMax())
|
||||
.setValue(getWorker().getSessionVolume())
|
||||
.addEndItem(getEndItemSliceAction());
|
||||
return builder;
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getGroupRow() {
|
||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||
R.drawable.ic_speaker_group_black_24dp);
|
||||
final CharSequence sessionName = getWorker().getSessionName();
|
||||
final CharSequence title = TextUtils.isEmpty(sessionName)
|
||||
? mContext.getString(R.string.media_output_group) : sessionName;
|
||||
final PendingIntent broadcastAction =
|
||||
getBroadcastIntent(mContext, MEDIA_GROUP_DEVICE, MEDIA_GROUP_DEVICE.hashCode());
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(broadcastAction, icon,
|
||||
ListBuilder.ICON_IMAGE, title);
|
||||
final ListBuilder.RowBuilder builder = new ListBuilder.RowBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setPrimaryAction(primarySliceAction)
|
||||
.addEndItem(getEndItemSliceAction());
|
||||
return builder;
|
||||
}
|
||||
|
||||
private void addRow(MediaDevice device, MediaDevice connectedDevice, ListBuilder listBuilder) {
|
||||
if (connectedDevice != null && TextUtils.equals(device.getId(), connectedDevice.getId())) {
|
||||
final String title = device.getName();
|
||||
final IconCompat icon = getDeviceIconCompat(device);
|
||||
|
||||
final PendingIntent broadcastAction =
|
||||
getBroadcastIntent(mContext, device.getId(), device.hashCode());
|
||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(broadcastAction, icon,
|
||||
ListBuilder.ICON_IMAGE, title);
|
||||
|
||||
if (device.getMaxVolume() > 0 && !getWorker().hasAdjustVolumeUserRestriction()) {
|
||||
final ListBuilder.InputRangeBuilder builder = new ListBuilder.InputRangeBuilder()
|
||||
.setTitleItem(icon, ListBuilder.ICON_IMAGE)
|
||||
.setTitle(title)
|
||||
.setPrimaryAction(primarySliceAction)
|
||||
.setInputAction(getSliderInputAction(device.hashCode(), device.getId()))
|
||||
.setMax(device.getMaxVolume())
|
||||
.setValue(device.getCurrentVolume());
|
||||
// Check end item visibility
|
||||
if (device.getDeviceType() == MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE
|
||||
&& !getWorker().getSelectableMediaDevice().isEmpty()) {
|
||||
builder.addEndItem(getEndItemSliceAction());
|
||||
}
|
||||
listBuilder.addInputRange(builder);
|
||||
} else {
|
||||
Log.d(TAG, "addRow device = " + device.getName() + " MaxVolume = "
|
||||
+ device.getMaxVolume());
|
||||
final ListBuilder.RowBuilder builder = getMediaDeviceRow(device);
|
||||
// Check end item visibility
|
||||
if (device.getDeviceType() == MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE
|
||||
&& !getWorker().getSelectableMediaDevice().isEmpty()) {
|
||||
builder.addEndItem(getEndItemSliceAction());
|
||||
}
|
||||
listBuilder.addRow(builder);
|
||||
}
|
||||
} else {
|
||||
if (device.getState() == LocalMediaManager.MediaDeviceState.STATE_CONNECTING) {
|
||||
listBuilder.addRange(getTransferringMediaDeviceRow(device));
|
||||
} else {
|
||||
listBuilder.addRow(getMediaDeviceRow(device));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private PendingIntent getSliderInputAction(int requestCode, String id) {
|
||||
final Intent intent = new Intent(getUri().toString())
|
||||
.setData(getUri())
|
||||
.putExtra(MEDIA_DEVICE_ID, id)
|
||||
.setClass(mContext, SliceBroadcastReceiver.class);
|
||||
|
||||
return PendingIntent.getBroadcast(mContext, requestCode, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
private SliceAction getEndItemSliceAction() {
|
||||
final Intent intent = new Intent()
|
||||
.setAction(MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT_GROUP)
|
||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
.putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME,
|
||||
getWorker().getPackageName());
|
||||
final int requestCode = TextUtils.isEmpty(getWorker().getPackageName())
|
||||
? 0
|
||||
: getWorker().getPackageName().hashCode();
|
||||
return SliceAction.createDeeplink(
|
||||
PendingIntent.getActivity(mContext, requestCode, intent,
|
||||
PendingIntent.FLAG_IMMUTABLE),
|
||||
IconCompat.createWithResource(mContext, R.drawable.ic_add_blue_24dp),
|
||||
ListBuilder.ICON_IMAGE,
|
||||
mContext.getText(R.string.add));
|
||||
}
|
||||
|
||||
private IconCompat getDeviceIconCompat(MediaDevice device) {
|
||||
Drawable drawable = device.getIcon();
|
||||
if (drawable == null) {
|
||||
Log.d(TAG, "getDeviceIconCompat() device : " + device.getName() + ", drawable is null");
|
||||
// Use default Bluetooth device icon to handle getIcon() is null case.
|
||||
drawable = mContext.getDrawable(com.android.internal.R.drawable.ic_bt_headphones_a2dp);
|
||||
}
|
||||
|
||||
return Utils.createIconWithDrawable(drawable);
|
||||
}
|
||||
|
||||
private MediaDeviceUpdateWorker getWorker() {
|
||||
if (mWorker == null) {
|
||||
mWorker = SliceBackgroundWorker.getInstance(getUri());
|
||||
}
|
||||
return mWorker;
|
||||
}
|
||||
|
||||
private Collection<MediaDevice> getMediaDevices() {
|
||||
final Collection<MediaDevice> devices = getWorker().getMediaDevices();
|
||||
return devices;
|
||||
}
|
||||
|
||||
private ListBuilder.RangeBuilder getTransferringMediaDeviceRow(MediaDevice device) {
|
||||
final IconCompat deviceIcon = getDeviceIconCompat(device);
|
||||
final SliceAction sliceAction = SliceAction.create(getBroadcastIntent(mContext,
|
||||
device.getId(), device.hashCode()), deviceIcon, ListBuilder.ICON_IMAGE,
|
||||
mContext.getText(R.string.media_output_switching));
|
||||
|
||||
return new ListBuilder.RangeBuilder()
|
||||
.setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE)
|
||||
.setMode(ListBuilder.RANGE_MODE_INDETERMINATE)
|
||||
.setTitle(device.getName())
|
||||
.setPrimaryAction(sliceAction);
|
||||
}
|
||||
|
||||
private ListBuilder.RowBuilder getMediaDeviceRow(MediaDevice device) {
|
||||
final String deviceName = device.getName();
|
||||
final PendingIntent broadcastAction =
|
||||
getBroadcastIntent(mContext, device.getId(), device.hashCode());
|
||||
final IconCompat deviceIcon = getDeviceIconCompat(device);
|
||||
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
|
||||
.setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE);
|
||||
|
||||
if (device.getDeviceType() == MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE
|
||||
&& !device.isConnected()) {
|
||||
final int state = device.getState();
|
||||
if (state == LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED) {
|
||||
rowBuilder.setTitle(deviceName);
|
||||
rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
|
||||
ListBuilder.ICON_IMAGE, deviceName));
|
||||
rowBuilder.setSubtitle(mContext.getText(R.string.bluetooth_connect_failed));
|
||||
} else {
|
||||
// Append status to title only for the disconnected Bluetooth device.
|
||||
final SpannableString spannableTitle = new SpannableString(
|
||||
mContext.getString(R.string.media_output_disconnected_status, deviceName));
|
||||
spannableTitle.setSpan(new ForegroundColorSpan(
|
||||
Utils.getColorAttrDefaultColor(mContext,
|
||||
android.R.attr.textColorSecondary)),
|
||||
deviceName.length(),
|
||||
spannableTitle.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||
rowBuilder.setTitle(spannableTitle);
|
||||
rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
|
||||
ListBuilder.ICON_IMAGE, spannableTitle));
|
||||
}
|
||||
} else {
|
||||
rowBuilder.setTitle(deviceName);
|
||||
rowBuilder.setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon,
|
||||
ListBuilder.ICON_IMAGE, deviceName));
|
||||
if (device.getState() == LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED) {
|
||||
rowBuilder.setSubtitle(mContext.getText(R.string.media_output_switch_error_text));
|
||||
}
|
||||
}
|
||||
|
||||
return rowBuilder;
|
||||
}
|
||||
|
||||
private PendingIntent getBroadcastIntent(Context context, String id, int requestCode) {
|
||||
final Intent intent = new Intent(getUri().toString());
|
||||
intent.setClass(context, SliceBroadcastReceiver.class);
|
||||
intent.putExtra(MEDIA_DEVICE_ID, id);
|
||||
intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
|
||||
return PendingIntent.getBroadcast(context, requestCode, intent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uri getUri() {
|
||||
return MEDIA_OUTPUT_SLICE_URI;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNotifyChange(Intent intent) {
|
||||
final MediaDeviceUpdateWorker worker = getWorker();
|
||||
final String id = intent != null ? intent.getStringExtra(MEDIA_DEVICE_ID) : "";
|
||||
if (TextUtils.isEmpty(id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int newPosition = intent.getIntExtra(EXTRA_RANGE_VALUE, NON_SLIDER_VALUE);
|
||||
if (TextUtils.equals(id, MEDIA_GROUP_DEVICE)) {
|
||||
// Session volume adjustment
|
||||
worker.adjustSessionVolume(newPosition);
|
||||
} else {
|
||||
final MediaDevice device = worker.getMediaDeviceById(id);
|
||||
if (device == null) {
|
||||
Log.d(TAG, "onNotifyChange: Unable to get device " + id);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPosition == NON_SLIDER_VALUE) {
|
||||
// Intent for device connection
|
||||
Log.d(TAG, "onNotifyChange: Switch to " + device.getName());
|
||||
worker.setIsTouched(true);
|
||||
worker.connectDevice(device);
|
||||
} else {
|
||||
// Single device volume adjustment
|
||||
worker.adjustVolume(device, newPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getBackgroundWorkerClass() {
|
||||
return MediaDeviceUpdateWorker.class;
|
||||
}
|
||||
|
||||
private boolean isVisible() {
|
||||
// To decide Slice's visibility.
|
||||
// Return true if
|
||||
// 1. AudioMode is not in on-going call
|
||||
// 2. worker is not null
|
||||
// 3. Available devices are more than 0
|
||||
return getWorker() != null
|
||||
&& !com.android.settingslib.Utils.isAudioModeOngoingCall(mContext)
|
||||
&& getWorker().getMediaDevices().size() > 0;
|
||||
}
|
||||
}
|
@@ -1,256 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.panel;
|
||||
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_START;
|
||||
import static androidx.lifecycle.Lifecycle.Event.ON_STOP;
|
||||
|
||||
import static com.android.settings.media.MediaOutputSlice.MEDIA_PACKAGE_NAME;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.media.MediaMetadata;
|
||||
import android.media.session.MediaController;
|
||||
import android.media.session.MediaSessionManager;
|
||||
import android.media.session.PlaybackState;
|
||||
import android.net.Uri;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.core.graphics.drawable.IconCompat;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.media.InfoMediaDevice;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
import com.android.settingslib.media.MediaOutputSliceConstants;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Represents the Media output Panel.
|
||||
*
|
||||
* <p>
|
||||
* Displays Media output item
|
||||
* </p>
|
||||
*/
|
||||
public class MediaOutputPanel implements PanelContent, LocalMediaManager.DeviceCallback,
|
||||
LifecycleObserver {
|
||||
|
||||
private static final String TAG = "MediaOutputPanel";
|
||||
|
||||
private final Context mContext;
|
||||
private final String mPackageName;
|
||||
|
||||
@VisibleForTesting
|
||||
LocalMediaManager mLocalMediaManager;
|
||||
|
||||
private PanelContentCallback mCallback;
|
||||
private boolean mIsCustomizedButtonUsed = true;
|
||||
private MediaSessionManager mMediaSessionManager;
|
||||
private MediaController mMediaController;
|
||||
|
||||
public static MediaOutputPanel create(Context context, String packageName) {
|
||||
// Redirect to new media output dialog
|
||||
context.sendBroadcast(new Intent()
|
||||
.addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
|
||||
.setPackage(MediaOutputSliceConstants.SYSTEMUI_PACKAGE_NAME)
|
||||
.setAction(MediaOutputSliceConstants.ACTION_LAUNCH_MEDIA_OUTPUT_DIALOG)
|
||||
.putExtra(MediaOutputSliceConstants.EXTRA_PACKAGE_NAME, packageName));
|
||||
return null;
|
||||
}
|
||||
|
||||
private MediaOutputPanel(Context context, String packageName) {
|
||||
mContext = context.getApplicationContext();
|
||||
mPackageName = TextUtils.isEmpty(packageName) ? "" : packageName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getTitle() {
|
||||
if (mMediaController != null) {
|
||||
final MediaMetadata metadata = mMediaController.getMetadata();
|
||||
if (metadata != null) {
|
||||
return metadata.getDescription().getTitle();
|
||||
}
|
||||
}
|
||||
return mContext.getText(R.string.media_volume_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSubTitle() {
|
||||
if (mMediaController != null) {
|
||||
final MediaMetadata metadata = mMediaController.getMetadata();
|
||||
if (metadata != null) {
|
||||
return metadata.getDescription().getSubtitle();
|
||||
}
|
||||
}
|
||||
return mContext.getText(R.string.media_output_panel_title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IconCompat getIcon() {
|
||||
if (mMediaController == null) {
|
||||
return null;
|
||||
}
|
||||
final MediaMetadata metadata = mMediaController.getMetadata();
|
||||
if (metadata != null) {
|
||||
final Bitmap bitmap = metadata.getDescription().getIconBitmap();
|
||||
if (bitmap != null) {
|
||||
final Bitmap roundBitmap = Utils.convertCornerRadiusBitmap(mContext, bitmap,
|
||||
(float) mContext.getResources().getDimensionPixelSize(
|
||||
R.dimen.output_switcher_panel_icon_corner_radius));
|
||||
|
||||
return IconCompat.createWithBitmap(roundBitmap);
|
||||
}
|
||||
}
|
||||
Log.d(TAG, "Media meta data does not contain icon information");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Uri> getSlices() {
|
||||
final List<Uri> uris = new ArrayList<>();
|
||||
MEDIA_OUTPUT_SLICE_URI =
|
||||
MEDIA_OUTPUT_SLICE_URI
|
||||
.buildUpon()
|
||||
.clearQuery()
|
||||
.appendQueryParameter(MEDIA_PACKAGE_NAME, mPackageName)
|
||||
.build();
|
||||
uris.add(MEDIA_OUTPUT_SLICE_URI);
|
||||
return uris;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getSeeMoreIntent() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCustomizedButtonUsed() {
|
||||
return mIsCustomizedButtonUsed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getCustomizedButtonTitle() {
|
||||
return mContext.getText(R.string.service_stop);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClickCustomizedButton() {
|
||||
mLocalMediaManager.releaseSession();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerCallback(PanelContentCallback callback) {
|
||||
mCallback = callback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
return SettingsEnums.PANEL_MEDIA_OUTPUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelectedDeviceStateChanged(MediaDevice device, int state) {
|
||||
dispatchCustomButtonStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceListUpdate(List<MediaDevice> devices) {
|
||||
dispatchCustomButtonStateChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceAttributesChanged() {
|
||||
dispatchCustomButtonStateChanged();
|
||||
}
|
||||
|
||||
private void dispatchCustomButtonStateChanged() {
|
||||
hideCustomButtonIfNecessary();
|
||||
if (mCallback != null) {
|
||||
mCallback.onCustomizedButtonStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private void hideCustomButtonIfNecessary() {
|
||||
final MediaDevice device = mLocalMediaManager.getCurrentConnectedDevice();
|
||||
mIsCustomizedButtonUsed = device instanceof InfoMediaDevice;
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_START)
|
||||
public void onStart() {
|
||||
if (!TextUtils.isEmpty(mPackageName)) {
|
||||
mMediaSessionManager = mContext.getSystemService(MediaSessionManager.class);
|
||||
for (MediaController controller : mMediaSessionManager.getActiveSessions(null)) {
|
||||
if (TextUtils.equals(controller.getPackageName(), mPackageName)) {
|
||||
mMediaController = controller;
|
||||
mMediaController.registerCallback(mCb);
|
||||
mCallback.onHeaderChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mMediaController == null) {
|
||||
Log.d(TAG, "No media controller for " + mPackageName);
|
||||
}
|
||||
if (mLocalMediaManager == null) {
|
||||
mLocalMediaManager = new LocalMediaManager(mContext, mPackageName, null);
|
||||
}
|
||||
mLocalMediaManager.registerCallback(this);
|
||||
mLocalMediaManager.startScan();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(ON_STOP)
|
||||
public void onStop() {
|
||||
if (mMediaController != null) {
|
||||
mMediaController.unregisterCallback(mCb);
|
||||
}
|
||||
mLocalMediaManager.unregisterCallback(this);
|
||||
mLocalMediaManager.stopScan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getViewType() {
|
||||
return PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON;
|
||||
}
|
||||
|
||||
private final MediaController.Callback mCb = new MediaController.Callback() {
|
||||
@Override
|
||||
public void onMetadataChanged(MediaMetadata metadata) {
|
||||
if (mCallback != null) {
|
||||
mCallback.onHeaderChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlaybackStateChanged(PlaybackState state) {
|
||||
final int playState = state.getState();
|
||||
if (mCallback != null && (playState == PlaybackState.STATE_STOPPED
|
||||
|| playState == PlaybackState.STATE_PAUSED)) {
|
||||
mCallback.forceClose();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
@@ -31,7 +31,6 @@ import java.util.List;
|
||||
public interface PanelContent extends Instrumentable {
|
||||
|
||||
int VIEW_TYPE_SLIDER = 1;
|
||||
int VIEW_TYPE_SLIDER_LARGE_ICON = 2;
|
||||
|
||||
/**
|
||||
* @return a icon for the title of the Panel.
|
||||
|
@@ -16,8 +16,6 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settingslib.media.MediaOutputSliceConstants.ACTION_MEDIA_OUTPUT;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
@@ -38,8 +36,6 @@ public class PanelFeatureProviderImpl implements PanelFeatureProvider {
|
||||
switch (panelType) {
|
||||
case Settings.Panel.ACTION_INTERNET_CONNECTIVITY:
|
||||
return InternetConnectivityPanel.create(context);
|
||||
case ACTION_MEDIA_OUTPUT:
|
||||
return MediaOutputPanel.create(context, mediaPackageName);
|
||||
case Settings.Panel.ACTION_NFC:
|
||||
return NfcPanel.create(context);
|
||||
case Settings.Panel.ACTION_WIFI:
|
||||
|
@@ -240,7 +240,7 @@ public class PanelFragment extends Fragment {
|
||||
final IconCompat icon = mPanel.getIcon();
|
||||
final CharSequence title = mPanel.getTitle();
|
||||
|
||||
if (icon != null || mPanel.getViewType() == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
||||
if (icon != null) {
|
||||
enablePanelHeader(icon, title);
|
||||
} else {
|
||||
mTitleView.setVisibility(View.VISIBLE);
|
||||
@@ -248,11 +248,7 @@ public class PanelFragment extends Fragment {
|
||||
mTitleView.setText(title);
|
||||
}
|
||||
|
||||
if (mPanel.getViewType() == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
||||
mFooterDivider.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
mFooterDivider.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mSeeMoreButton.setOnClickListener(getSeeMoreListener());
|
||||
mDoneButton.setOnClickListener(getCloseListener());
|
||||
|
@@ -16,9 +16,7 @@
|
||||
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_GROUP_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
@@ -75,8 +73,6 @@ public class PanelSlicesAdapter
|
||||
View view;
|
||||
if (viewType == PanelContent.VIEW_TYPE_SLIDER) {
|
||||
view = inflater.inflate(R.layout.panel_slice_slider_row, viewGroup, false);
|
||||
} else if (viewType == PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON) {
|
||||
view = inflater.inflate(R.layout.panel_slice_slider_row_large_icon, viewGroup, false);
|
||||
} else {
|
||||
view = inflater.inflate(R.layout.panel_slice_row, viewGroup, false);
|
||||
}
|
||||
@@ -142,15 +138,6 @@ public class PanelSlicesAdapter
|
||||
final Slice slice = sliceLiveData.getValue();
|
||||
if (slice == null || slice.getUri().equals(MEDIA_OUTPUT_INDICATOR_SLICE_URI)) {
|
||||
mDividerAllowedAbove = false;
|
||||
} else if (position == 0 && (slice.getUri().equals(MEDIA_OUTPUT_SLICE_URI)
|
||||
|| slice.getUri().equals(MEDIA_OUTPUT_GROUP_SLICE_URI))) {
|
||||
sliceView.setClickable(false);
|
||||
// Customize output switcher slice padding
|
||||
final int padding = mPanelFragment.getResources().getDimensionPixelSize(
|
||||
R.dimen.output_switcher_slice_padding_top);
|
||||
mSliceSliderLayout.setPadding(mSliceSliderLayout.getPaddingLeft(), padding,
|
||||
mSliceSliderLayout.getPaddingRight(),
|
||||
padding);
|
||||
}
|
||||
|
||||
// Log Panel interaction
|
||||
@@ -175,7 +162,7 @@ public class PanelSlicesAdapter
|
||||
|
||||
@Override
|
||||
public boolean isDividerAllowedBelow() {
|
||||
return mPanelFragment.getPanelViewType() != PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -38,7 +38,6 @@ import com.android.settings.homepage.contextualcards.slices.FaceSetupSlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
||||
import com.android.settings.location.LocationSlice;
|
||||
import com.android.settings.media.MediaOutputIndicatorSlice;
|
||||
import com.android.settings.media.MediaOutputSlice;
|
||||
import com.android.settings.media.RemoteMediaSlice;
|
||||
import com.android.settings.network.AirplaneSafeNetworksSlice;
|
||||
import com.android.settings.network.telephony.MobileDataSlice;
|
||||
@@ -254,26 +253,6 @@ public class CustomSliceRegistry {
|
||||
.appendPath(ZenModeButtonPreferenceController.KEY)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Backing Uri for the Media output Slice.
|
||||
*/
|
||||
public static Uri MEDIA_OUTPUT_SLICE_URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(MediaOutputSliceConstants.KEY_MEDIA_OUTPUT)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Backing Uri for the Media output group Slice.
|
||||
*/
|
||||
public static Uri MEDIA_OUTPUT_GROUP_SLICE_URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath(MediaOutputSliceConstants.KEY_MEDIA_OUTPUT_GROUP)
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Backing Uri for the Media output indicator Slice.
|
||||
*/
|
||||
@@ -339,7 +318,6 @@ public class CustomSliceRegistry {
|
||||
sUriToSlice.put(LOCATION_SLICE_URI, LocationSlice.class);
|
||||
sUriToSlice.put(LOW_STORAGE_SLICE_URI, LowStorageSlice.class);
|
||||
sUriToSlice.put(MEDIA_OUTPUT_INDICATOR_SLICE_URI, MediaOutputIndicatorSlice.class);
|
||||
sUriToSlice.put(MEDIA_OUTPUT_SLICE_URI, MediaOutputSlice.class);
|
||||
sUriToSlice.put(MOBILE_DATA_SLICE_URI, MobileDataSlice.class);
|
||||
sUriToSlice.put(WIFI_SLICE_URI, WifiSlice.class);
|
||||
sUriToSlice.put(DARK_THEME_SLICE_URI, DarkThemeSlice.class);
|
||||
|
@@ -37,7 +37,7 @@ import com.android.settingslib.media.MediaOutputSliceConstants;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class allows launching MediaOutputSlice to switch output device.
|
||||
* This class allows launching MediaOutputDialog to switch output device.
|
||||
* Preference would hide only when
|
||||
* - Bluetooth = OFF
|
||||
* - Bluetooth = ON and Connected Devices = 0 and Previously Connected = 0
|
||||
|
@@ -1,607 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2019 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.media;
|
||||
|
||||
import static android.app.slice.Slice.EXTRA_RANGE_VALUE;
|
||||
import static android.app.slice.Slice.HINT_LIST_ITEM;
|
||||
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
||||
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.AudioManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.slice.Slice;
|
||||
import androidx.slice.SliceMetadata;
|
||||
import androidx.slice.SliceProvider;
|
||||
import androidx.slice.core.SliceAction;
|
||||
import androidx.slice.core.SliceQuery;
|
||||
import androidx.slice.widget.SliceLiveData;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadow.api.Shadow;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
@Config(shadows = {ShadowBluetoothAdapter.class})
|
||||
public class MediaOutputSliceTest {
|
||||
|
||||
private static final String TEST_DEVICE_1_ID = "test_device_1_id";
|
||||
private static final String TEST_DEVICE_2_ID = "test_device_2_id";
|
||||
private static final String TEST_DEVICE_1_NAME = "test_device_1_name";
|
||||
private static final String TEST_DEVICE_2_NAME = "test_device_2_name";
|
||||
private static final int TEST_DEVICE_1_ICON =
|
||||
com.android.internal.R.drawable.ic_bt_headphones_a2dp;
|
||||
|
||||
@Mock
|
||||
private LocalMediaManager mLocalMediaManager;
|
||||
@Mock
|
||||
private Drawable mTestDrawable;
|
||||
|
||||
private final List<MediaDevice> mDevices = new ArrayList<>();
|
||||
|
||||
private Context mContext;
|
||||
private MediaOutputSlice mMediaOutputSlice;
|
||||
private MediaDeviceUpdateWorker mMediaDeviceUpdateWorker;
|
||||
private ShadowBluetoothAdapter mShadowBluetoothAdapter;
|
||||
private AudioManager mAudioManager;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
mAudioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE);
|
||||
mAudioManager.setMode(AudioManager.MODE_NORMAL);
|
||||
|
||||
// Set-up specs for SliceMetadata.
|
||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||
// Setup BluetoothAdapter
|
||||
mShadowBluetoothAdapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter());
|
||||
mShadowBluetoothAdapter.setEnabled(true);
|
||||
|
||||
mMediaOutputSlice = new MediaOutputSlice(mContext);
|
||||
mMediaDeviceUpdateWorker = spy(new MediaDeviceUpdateWorker(mContext,
|
||||
MEDIA_OUTPUT_SLICE_URI));
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
mMediaDeviceUpdateWorker.mLocalMediaManager = mLocalMediaManager;
|
||||
doReturn(false).when(mMediaDeviceUpdateWorker).hasAdjustVolumeUserRestriction();
|
||||
mMediaOutputSlice.init(mMediaDeviceUpdateWorker);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_workerIsNull_shouldReturnZeroRow() {
|
||||
mMediaOutputSlice.init(null);
|
||||
|
||||
final Slice slice = mMediaOutputSlice.getSlice();
|
||||
|
||||
final int rows = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null /* nonHints */).size();
|
||||
|
||||
assertThat(rows).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_bluetoothIsDisable_shouldReturnZeroRow() {
|
||||
mShadowBluetoothAdapter.setEnabled(false);
|
||||
|
||||
final Slice slice = mMediaOutputSlice.getSlice();
|
||||
|
||||
final int rows = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null /* nonHints */).size();
|
||||
|
||||
assertThat(rows).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_audioModeIsOngoingCall_shouldReturnZeroRow() {
|
||||
mAudioManager.setMode(AudioManager.MODE_IN_CALL);
|
||||
|
||||
final Slice slice = mMediaOutputSlice.getSlice();
|
||||
|
||||
final int rows = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null /* nonHints */).size();
|
||||
|
||||
assertThat(rows).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_shouldHaveActiveDeviceName() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
|
||||
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
assertThat(primaryAction.getTitle().toString()).isEqualTo(TEST_DEVICE_1_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_disconnectedBluetooth_verifyTitle() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(false);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, mediaSlice);
|
||||
|
||||
final SliceAction primaryAction = metadata.getPrimaryAction();
|
||||
assertThat(primaryAction.getTitle().toString()).isEqualTo(mContext.getString(
|
||||
R.string.media_output_disconnected_status, TEST_DEVICE_1_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_inGroupState_checkSliceSize() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(true);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectedDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
when(mMediaDeviceUpdateWorker.getSessionVolumeMax()).thenReturn(100);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
|
||||
assertThat(SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM, null).size())
|
||||
.isEqualTo(mDevices.size() + 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_notInGroupState_checkSliceSize() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(true);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
|
||||
assertThat(SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM, null).size())
|
||||
.isEqualTo(mDevices.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_singleCastDevice_notContainGroupIconText() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(null);
|
||||
mSelectedDevices.add(device);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
|
||||
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(R.string.add))).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_multipleCastDevices_containGroupIconText() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(true);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(R.string.add))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_onTransferring_containTransferringSubtitle() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getState()).thenReturn(LocalMediaManager.MediaDeviceState.STATE_CONNECTING);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(R.string.media_output_switching)))
|
||||
.isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_onTransferringFailed_containFailedSubtitle() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getState()).thenReturn(LocalMediaManager.MediaDeviceState
|
||||
.STATE_CONNECTING_FAILED);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
|
||||
R.string.media_output_switch_error_text))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_zeroState_containPairingText() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_PHONE_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
mSelectedDevices.add(device);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
|
||||
R.string.bluetooth_pairing_pref_title))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_twoConnectedDevices_notContainPairingText() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(true);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_CAST_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(
|
||||
R.string.bluetooth_pairing_pref_title))).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_disconnectedBtOnTransferring_containTransferringSubtitle() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getState()).thenReturn(LocalMediaManager.MediaDeviceState.STATE_CONNECTING);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo, mContext.getText(R.string.media_output_switching)))
|
||||
.isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSlice_disconnectedBtOnTransferringFailed_containTransferringFailedSubtitle() {
|
||||
final List<MediaDevice> mSelectedDevices = new ArrayList<>();
|
||||
final List<MediaDevice> mSelectableDevices = new ArrayList<>();
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getName()).thenReturn(TEST_DEVICE_1_NAME);
|
||||
when(device.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device.getMaxVolume()).thenReturn(100);
|
||||
when(device.isConnected()).thenReturn(true);
|
||||
when(device.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
final MediaDevice device2 = mock(MediaDevice.class);
|
||||
when(device2.getName()).thenReturn(TEST_DEVICE_2_NAME);
|
||||
when(device2.getIcon()).thenReturn(mTestDrawable);
|
||||
when(device2.getMaxVolume()).thenReturn(100);
|
||||
when(device2.isConnected()).thenReturn(false);
|
||||
when(device2.getState()).thenReturn(
|
||||
LocalMediaManager.MediaDeviceState.STATE_CONNECTING_FAILED);
|
||||
when(device2.getDeviceType()).thenReturn(MediaDevice.MediaDeviceType.TYPE_BLUETOOTH_DEVICE);
|
||||
when(device2.getId()).thenReturn(TEST_DEVICE_2_ID);
|
||||
mSelectedDevices.add(device);
|
||||
mSelectableDevices.add(device2);
|
||||
when(mLocalMediaManager.getCurrentConnectedDevice()).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
mDevices.add(device2);
|
||||
when(mLocalMediaManager.getSelectedMediaDevice()).thenReturn(mSelectedDevices);
|
||||
when(mLocalMediaManager.getSelectableMediaDevice()).thenReturn(mSelectableDevices);
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Slice mediaSlice = mMediaOutputSlice.getSlice();
|
||||
final String sliceInfo = SliceQuery.findAll(mediaSlice, FORMAT_SLICE, HINT_LIST_ITEM,
|
||||
null).toString();
|
||||
|
||||
assertThat(TextUtils.indexOf(sliceInfo,
|
||||
mContext.getText(R.string.bluetooth_connect_failed))).isNotEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_foundMediaDevice_connect() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("media_device_id", TEST_DEVICE_1_ID);
|
||||
|
||||
mMediaOutputSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mLocalMediaManager).connectDevice(device);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_notFoundMediaDevice_doNothing() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("media_device_id", "fake_123");
|
||||
|
||||
mMediaOutputSlice.onNotifyChange(intent);
|
||||
|
||||
verify(mLocalMediaManager, never()).connectDevice(device);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNotifyChange_adjustVolume() {
|
||||
mDevices.clear();
|
||||
final MediaDevice device = mock(MediaDevice.class);
|
||||
when(device.getId()).thenReturn(TEST_DEVICE_1_ID);
|
||||
when(mLocalMediaManager.getMediaDeviceById(mDevices, TEST_DEVICE_1_ID)).thenReturn(device);
|
||||
mDevices.add(device);
|
||||
|
||||
mMediaDeviceUpdateWorker.onDeviceListUpdate(mDevices);
|
||||
|
||||
final Intent intent = new Intent();
|
||||
intent.putExtra("media_device_id", TEST_DEVICE_1_ID);
|
||||
intent.putExtra(EXTRA_RANGE_VALUE, 30);
|
||||
|
||||
mMediaOutputSlice.onNotifyChange(intent);
|
||||
|
||||
verify(device).requestSetVolume(30);
|
||||
}
|
||||
}
|
@@ -18,7 +18,6 @@
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
@@ -212,22 +211,6 @@ public class PanelFragmentTest {
|
||||
assertThat(titleView.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderLargeIconPanelType_displayFooterDivider() {
|
||||
mFakePanelContent.setViewType(VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
final ActivityController<FakeSettingsPanelActivity> activityController =
|
||||
Robolectric.buildActivity(FakeSettingsPanelActivity.class);
|
||||
activityController.setup();
|
||||
final PanelFragment panelFragment = (PanelFragment)
|
||||
Objects.requireNonNull(activityController
|
||||
.get()
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentById(R.id.main_content));
|
||||
final View footerDivider = panelFragment.mLayoutView.findViewById(R.id.footer_divider);
|
||||
// Check visibility
|
||||
assertThat(footerDivider.getVisibility()).isEqualTo(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderPanelType_notDisplayFooterDivider() {
|
||||
mFakePanelContent.setViewType(VIEW_TYPE_SLIDER);
|
||||
|
@@ -17,11 +17,8 @@
|
||||
package com.android.settings.panel;
|
||||
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER;
|
||||
import static com.android.settings.panel.PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON;
|
||||
import static com.android.settings.panel.PanelSlicesAdapter.MAX_NUM_OF_SLICES;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_GROUP_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_INDICATOR_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.MEDIA_OUTPUT_SLICE_URI;
|
||||
import static com.android.settings.slices.CustomSliceRegistry.VOLUME_MEDIA_URI;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
@@ -143,22 +140,6 @@ public class PanelSlicesAdapterTest {
|
||||
assertThat(viewHolder.isDividerAllowedAbove()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderLargeIconPanel_shouldNotAllowDividerBelow() {
|
||||
addTestLiveData(MEDIA_OUTPUT_SLICE_URI);
|
||||
mFakePanelContent.setViewType(PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.isDividerAllowedBelow()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sliderPanelType_shouldAllowDividerBelow() {
|
||||
addTestLiveData(VOLUME_MEDIA_URI);
|
||||
@@ -190,42 +171,6 @@ public class PanelSlicesAdapterTest {
|
||||
assertThat(viewHolder.isDividerAllowedBelow()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputSwitcherSlice_shouldAddFirstItemPadding() {
|
||||
addTestLiveData(MEDIA_OUTPUT_SLICE_URI);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.mSliceSliderLayout.getPaddingTop()).isEqualTo(
|
||||
mPanelFragment.getResources().getDimensionPixelSize(
|
||||
R.dimen.output_switcher_slice_padding_top));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void outputSwitcherGroupSlice_shouldAddFirstItemPadding() {
|
||||
addTestLiveData(MEDIA_OUTPUT_GROUP_SLICE_URI);
|
||||
|
||||
final PanelSlicesAdapter adapter =
|
||||
new PanelSlicesAdapter(mPanelFragment, mData, 0 /* metrics category */);
|
||||
final int position = 0;
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final SliceRowViewHolder viewHolder =
|
||||
adapter.onCreateViewHolder(view, PanelContent.VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
|
||||
adapter.onBindViewHolder(viewHolder, position);
|
||||
|
||||
assertThat(viewHolder.mSliceSliderLayout.getPaddingTop()).isEqualTo(
|
||||
mPanelFragment.getResources().getDimensionPixelSize(
|
||||
R.dimen.output_switcher_slice_padding_top));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mediaOutputIndicatorSlice_notSliderPanel_noSliderLayout() {
|
||||
addTestLiveData(MEDIA_OUTPUT_INDICATOR_SLICE_URI);
|
||||
@@ -255,19 +200,6 @@ public class PanelSlicesAdapterTest {
|
||||
assertThat(intArgumentCaptor.getValue()).isEqualTo(R.layout.panel_slice_slider_row);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateViewHolder_viewTypeSliderLargeIcon_verifyLayout() {
|
||||
final PanelSlicesAdapter adapter = new PanelSlicesAdapter(mPanelFragment, mData, 0);
|
||||
final ViewGroup view = new FrameLayout(mContext);
|
||||
final ArgumentCaptor<Integer> intArgumentCaptor = ArgumentCaptor.forClass(Integer.class);
|
||||
|
||||
adapter.onCreateViewHolder(view, VIEW_TYPE_SLIDER_LARGE_ICON);
|
||||
|
||||
verify(sLayoutInflater).inflate(intArgumentCaptor.capture(), eq(view), eq(false));
|
||||
assertThat(intArgumentCaptor.getValue()).isEqualTo(
|
||||
R.layout.panel_slice_slider_row_large_icon);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onCreateViewHolder_viewTypeDefault_verifyLayout() {
|
||||
final PanelSlicesAdapter adapter =
|
||||
|
Reference in New Issue
Block a user