Rename ConnectedDeviceSlice to BluetoothDevicesSlice
Bug: 120029006 Test: robotests Change-Id: I7e39f52a87ebd017bf0635cd5a76945b39eee6fc
This commit is contained in:
@@ -10245,15 +10245,13 @@
|
|||||||
<!-- OK button for Network connection timeout Dialog [CHAR LIMIT=30] -->
|
<!-- OK button for Network connection timeout Dialog [CHAR LIMIT=30] -->
|
||||||
<string name="network_connection_timeout_dialog_ok">Scan again</string>
|
<string name="network_connection_timeout_dialog_ok">Scan again</string>
|
||||||
|
|
||||||
<!-- Summary for connected devices count in connected device slice. [CHAR LIMIT=NONE] -->
|
<!-- Summary for bluetooth devices count in Bluetooth devices slice. [CHAR LIMIT=NONE] -->
|
||||||
<plurals name="show_connected_devices">
|
<plurals name="show_bluetooth_devices">
|
||||||
<item quantity="one"><xliff:g id="number_device_count">%1$d</xliff:g> device connected</item>
|
<item quantity="one"><xliff:g id="number_device_count">%1$d</xliff:g> device connected</item>
|
||||||
<item quantity="other"><xliff:g id="number_device_count">%1$d</xliff:g> devices connected</item>
|
<item quantity="other"><xliff:g id="number_device_count">%1$d</xliff:g> devices connected</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
<!-- Title for bluetooth connected devices in connected device slice. [CHAR LIMIT=NONE] -->
|
<!-- Title for no bluetooth devices in Bluetooth devices slice. [CHAR LIMIT=NONE] -->
|
||||||
<string name="bluetooth_connected_devices">Bluetooth Devices</string>
|
<string name="no_bluetooth_devices">No Bluetooth devices</string>
|
||||||
<!-- Title for no connected devices in connected device slice. [CHAR LIMIT=NONE] -->
|
|
||||||
<string name="no_connected_devices">No connected devices</string>
|
|
||||||
|
|
||||||
<!-- Default title for the settings panel [CHAR LIMIT=NONE] -->
|
<!-- Default title for the settings panel [CHAR LIMIT=NONE] -->
|
||||||
<string name="settings_panel_title">Settings Panel</string>
|
<string name="settings_panel_title">Settings Panel</string>
|
||||||
|
@@ -20,7 +20,7 @@ import static android.app.slice.Slice.HINT_ERROR;
|
|||||||
|
|
||||||
import static androidx.slice.widget.SliceLiveData.SUPPORTED_SPECS;
|
import static androidx.slice.widget.SliceLiveData.SUPPORTED_SPECS;
|
||||||
|
|
||||||
import static com.android.settings.slices.CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI;
|
import static com.android.settings.slices.CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI;
|
||||||
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
import static com.android.settings.slices.CustomSliceRegistry.WIFI_SLICE_URI;
|
||||||
|
|
||||||
import android.content.ContentProviderClient;
|
import android.content.ContentProviderClient;
|
||||||
@@ -196,7 +196,7 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>
|
|||||||
private int getNumberOfLargeCard(List<ContextualCard> cards) {
|
private int getNumberOfLargeCard(List<ContextualCard> cards) {
|
||||||
return (int) cards.stream()
|
return (int) cards.stream()
|
||||||
.filter(card -> card.getSliceUri().equals(WIFI_SLICE_URI)
|
.filter(card -> card.getSliceUri().equals(WIFI_SLICE_URI)
|
||||||
|| card.getSliceUri().equals(CONNECTED_DEVICE_SLICE_URI))
|
|| card.getSliceUri().equals(BLUETOOTH_DEVICES_SLICE_URI))
|
||||||
.count();
|
.count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -40,8 +40,8 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
|
|||||||
.build();
|
.build();
|
||||||
final ContextualCard connectedDeviceCard =
|
final ContextualCard connectedDeviceCard =
|
||||||
ContextualCard.newBuilder()
|
ContextualCard.newBuilder()
|
||||||
.setSliceUri(CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI.toString())
|
.setSliceUri(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString())
|
||||||
.setCardName(CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI.toString())
|
.setCardName(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI.toString())
|
||||||
.setCardCategory(ContextualCard.Category.IMPORTANT)
|
.setCardCategory(ContextualCard.Category.IMPORTANT)
|
||||||
.build();
|
.build();
|
||||||
final ContextualCard lowStorageCard =
|
final ContextualCard lowStorageCard =
|
||||||
|
@@ -57,19 +57,12 @@ import java.util.Comparator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
public class BluetoothDevicesSlice implements CustomSliceable {
|
||||||
* TODO(b/114807655): Contextual Home Page - Connected Device
|
|
||||||
*
|
|
||||||
* Show connected device info if one is currently connected. UI for connected device should
|
|
||||||
* match Connected Devices > Currently Connected Devices
|
|
||||||
*
|
|
||||||
* TODO This class will be refactor for Bluetooth connected devices only.
|
|
||||||
*/
|
|
||||||
public class ConnectedDeviceSlice implements CustomSliceable {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To sort the Bluetooth devices by {@link CachedBluetoothDevice}.
|
* TODO(b/114807655): Contextual Home Page - Connected Device
|
||||||
* Refer compareTo method from {@link com.android.settings.bluetooth.BluetoothDevicePreference}.
|
* Re-design sorting for new rule:
|
||||||
|
* Sorting rule: Audio Streaming > Last connected > Recently connected.
|
||||||
*/
|
*/
|
||||||
private static final Comparator<CachedBluetoothDevice> COMPARATOR
|
private static final Comparator<CachedBluetoothDevice> COMPARATOR
|
||||||
= Comparator.naturalOrder();
|
= Comparator.naturalOrder();
|
||||||
@@ -80,11 +73,11 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
*/
|
*/
|
||||||
private static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
private static final int DEFAULT_EXPANDED_ROW_COUNT = 3;
|
||||||
|
|
||||||
private static final String TAG = "ConnectedDeviceSlice";
|
private static final String TAG = "BluetoothDevicesSlice";
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
public ConnectedDeviceSlice(Context context) {
|
public BluetoothDevicesSlice(Context context) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,38 +94,38 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri getUri() {
|
public Uri getUri() {
|
||||||
return CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI;
|
return CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Slice getSlice() {
|
public Slice getSlice() {
|
||||||
final IconCompat icon = IconCompat.createWithResource(mContext,
|
final IconCompat icon = IconCompat.createWithResource(mContext,
|
||||||
R.drawable.ic_homepage_connected_device);
|
R.drawable.ic_settings_bluetooth);
|
||||||
final CharSequence title = mContext.getText(R.string.bluetooth_connected_devices);
|
final CharSequence title = mContext.getText(R.string.bluetooth_devices);
|
||||||
final CharSequence titleNoConnectedDevices = mContext.getText(
|
final CharSequence titleNoBluetoothDevices = mContext.getText(
|
||||||
R.string.no_connected_devices);
|
R.string.no_bluetooth_devices);
|
||||||
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0,
|
final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0,
|
||||||
getIntent(), 0);
|
getIntent(), 0);
|
||||||
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
|
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon,
|
||||||
ListBuilder.ICON_IMAGE, title);
|
ListBuilder.ICON_IMAGE, title);
|
||||||
final ListBuilder listBuilder =
|
final ListBuilder listBuilder =
|
||||||
new ListBuilder(mContext, CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI,
|
new ListBuilder(mContext, CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI,
|
||||||
ListBuilder.INFINITY)
|
ListBuilder.INFINITY)
|
||||||
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
|
.setAccentColor(Utils.getColorAccentDefaultColor(mContext));
|
||||||
|
|
||||||
// Get row builders by connected devices, e.g. Bluetooth.
|
// Get row builders by Bluetooth devices.
|
||||||
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder(primarySliceAction);
|
final List<ListBuilder.RowBuilder> rows = getBluetoothRowBuilder(primarySliceAction);
|
||||||
|
|
||||||
// Return a header with IsError flag, if no connected devices.
|
// Return a header with IsError flag, if no Bluetooth devices.
|
||||||
if (rows.isEmpty()) {
|
if (rows.isEmpty()) {
|
||||||
return listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
return listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
||||||
.setTitle(titleNoConnectedDevices)
|
.setTitle(titleNoBluetoothDevices)
|
||||||
.setPrimaryAction(primarySliceAction))
|
.setPrimaryAction(primarySliceAction))
|
||||||
.setIsError(true)
|
.setIsError(true)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
// According the number of connected devices to set sub title of header.
|
// According the number of Bluetooth devices to set sub title of header.
|
||||||
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
listBuilder.setHeader(new ListBuilder.HeaderBuilder()
|
||||||
.setTitle(title)
|
.setTitle(title)
|
||||||
.setSubtitle(getSubTitle(rows.size()))
|
.setSubtitle(getSubTitle(rows.size()))
|
||||||
@@ -161,7 +154,7 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
screenTitle,
|
screenTitle,
|
||||||
MetricsProto.MetricsEvent.SLICE)
|
MetricsProto.MetricsEvent.SLICE)
|
||||||
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
|
.setClassName(mContext.getPackageName(), SubSettings.class.getName())
|
||||||
.setData(CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI);
|
.setData(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -174,25 +167,30 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
List<CachedBluetoothDevice> getBluetoothConnectedDevices() {
|
List<CachedBluetoothDevice> getBluetoothDevices() {
|
||||||
final List<CachedBluetoothDevice> connectedBluetoothList = new ArrayList<>();
|
final List<CachedBluetoothDevice> bluetoothDeviceList = new ArrayList<>();
|
||||||
|
|
||||||
// If Bluetooth is disable, skip to get the bluetooth devices.
|
// If Bluetooth is disable, skip to get the bluetooth devices.
|
||||||
if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
|
if (!BluetoothAdapter.getDefaultAdapter().isEnabled()) {
|
||||||
Log.i(TAG, "Cannot get Bluetooth connected devices, Bluetooth is disabled.");
|
Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is disabled.");
|
||||||
return connectedBluetoothList;
|
return bluetoothDeviceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the Bluetooth devices from LocalBluetoothManager.
|
// Get the Bluetooth devices from LocalBluetoothManager.
|
||||||
final LocalBluetoothManager bluetoothManager =
|
final LocalBluetoothManager bluetoothManager =
|
||||||
com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
|
com.android.settings.bluetooth.Utils.getLocalBtManager(mContext);
|
||||||
if (bluetoothManager == null) {
|
if (bluetoothManager == null) {
|
||||||
Log.i(TAG, "Cannot get Bluetooth connected devices, Bluetooth is unsupported.");
|
Log.i(TAG, "Cannot get Bluetooth devices, Bluetooth is unsupported.");
|
||||||
return connectedBluetoothList;
|
return bluetoothDeviceList;
|
||||||
}
|
}
|
||||||
final Collection<CachedBluetoothDevice> cachedDevices =
|
final Collection<CachedBluetoothDevice> cachedDevices =
|
||||||
bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
|
bluetoothManager.getCachedDeviceManager().getCachedDevicesCopy();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TODO(b/114807655): Contextual Home Page - Connected Device
|
||||||
|
* Re-design to get all Bluetooth devices and sort them by new rule:
|
||||||
|
* Sorting rule: Audio Streaming > Last connected > Recently connected.
|
||||||
|
*/
|
||||||
// Get connected Bluetooth devices and sort them.
|
// Get connected Bluetooth devices and sort them.
|
||||||
return cachedDevices.stream().filter(device -> device.isConnected()).sorted(
|
return cachedDevices.stream().filter(device -> device.isConnected()).sorted(
|
||||||
COMPARATOR).collect(Collectors.toList());
|
COMPARATOR).collect(Collectors.toList());
|
||||||
@@ -217,25 +215,29 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
IconCompat getConnectedDeviceIcon(CachedBluetoothDevice device) {
|
IconCompat getBluetoothDeviceIcon(CachedBluetoothDevice device) {
|
||||||
final Pair<Drawable, String> pair = BluetoothUtils
|
final Pair<Drawable, String> pair = BluetoothUtils
|
||||||
.getBtClassDrawableWithDescription(mContext, device);
|
.getBtClassDrawableWithDescription(mContext, device);
|
||||||
|
|
||||||
if (pair.first != null) {
|
if (pair.first != null) {
|
||||||
return IconCompat.createWithBitmap(getBitmapFromVectorDrawable(pair.first));
|
return IconCompat.createWithBitmap(getBitmapFromVectorDrawable(pair.first));
|
||||||
} else {
|
} else {
|
||||||
return IconCompat.createWithResource(mContext, R.drawable.ic_homepage_connected_device);
|
return IconCompat.createWithResource(mContext, R.drawable.ic_settings_bluetooth);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder(SliceAction primarySliceAction) {
|
private List<ListBuilder.RowBuilder> getBluetoothRowBuilder(SliceAction primarySliceAction) {
|
||||||
final List<ListBuilder.RowBuilder> bluetoothRows = new ArrayList<>();
|
final List<ListBuilder.RowBuilder> bluetoothRows = new ArrayList<>();
|
||||||
|
|
||||||
// According Bluetooth connected device to create row builders.
|
/**
|
||||||
final List<CachedBluetoothDevice> bluetoothDevices = getBluetoothConnectedDevices();
|
* TODO(b/114807655): Contextual Home Page - Connected Device
|
||||||
|
* Re-design to do action "activating" in primary action.
|
||||||
|
*/
|
||||||
|
// According Bluetooth device to create row builders.
|
||||||
|
final List<CachedBluetoothDevice> bluetoothDevices = getBluetoothDevices();
|
||||||
for (CachedBluetoothDevice bluetoothDevice : bluetoothDevices) {
|
for (CachedBluetoothDevice bluetoothDevice : bluetoothDevices) {
|
||||||
bluetoothRows.add(new ListBuilder.RowBuilder()
|
bluetoothRows.add(new ListBuilder.RowBuilder()
|
||||||
.setTitleItem(getConnectedDeviceIcon(bluetoothDevice), ListBuilder.ICON_IMAGE)
|
.setTitleItem(getBluetoothDeviceIcon(bluetoothDevice), ListBuilder.ICON_IMAGE)
|
||||||
.setTitle(bluetoothDevice.getName())
|
.setTitle(bluetoothDevice.getName())
|
||||||
.setSubtitle(bluetoothDevice.getConnectionSummary())
|
.setSubtitle(bluetoothDevice.getConnectionSummary())
|
||||||
.setPrimaryAction(primarySliceAction)
|
.setPrimaryAction(primarySliceAction)
|
||||||
@@ -254,7 +256,7 @@ public class ConnectedDeviceSlice implements CustomSliceable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private CharSequence getSubTitle(int deviceCount) {
|
private CharSequence getSubTitle(int deviceCount) {
|
||||||
return mContext.getResources().getQuantityString(R.plurals.show_connected_devices,
|
return mContext.getResources().getQuantityString(R.plurals.show_bluetooth_devices,
|
||||||
deviceCount, deviceCount);
|
deviceCount, deviceCount);
|
||||||
}
|
}
|
||||||
|
|
@@ -29,7 +29,7 @@ import com.android.settings.homepage.contextualcards.deviceinfo.DeviceInfoSlice;
|
|||||||
import com.android.settings.homepage.contextualcards.deviceinfo.EmergencyInfoSlice;
|
import com.android.settings.homepage.contextualcards.deviceinfo.EmergencyInfoSlice;
|
||||||
import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
|
import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
|
||||||
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
|
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
|
||||||
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
|
import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
|
||||||
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
|
||||||
import com.android.settings.location.LocationSlice;
|
import com.android.settings.location.LocationSlice;
|
||||||
import com.android.settings.wifi.WifiSlice;
|
import com.android.settings.wifi.WifiSlice;
|
||||||
@@ -106,7 +106,7 @@ public class CustomSliceManager {
|
|||||||
private void addSlices() {
|
private void addSlices() {
|
||||||
mUriMap.put(CustomSliceRegistry.BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
|
mUriMap.put(CustomSliceRegistry.BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
|
||||||
mUriMap.put(CustomSliceRegistry.BATTERY_INFO_SLICE_URI, BatterySlice.class);
|
mUriMap.put(CustomSliceRegistry.BATTERY_INFO_SLICE_URI, BatterySlice.class);
|
||||||
mUriMap.put(CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI, ConnectedDeviceSlice.class);
|
mUriMap.put(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
|
||||||
mUriMap.put(CustomSliceRegistry.DATA_USAGE_SLICE_URI, DataUsageSlice.class);
|
mUriMap.put(CustomSliceRegistry.DATA_USAGE_SLICE_URI, DataUsageSlice.class);
|
||||||
mUriMap.put(CustomSliceRegistry.DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class);
|
mUriMap.put(CustomSliceRegistry.DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class);
|
||||||
mUriMap.put(CustomSliceRegistry.EMERGENCY_INFO_SLICE_URI, EmergencyInfoSlice.class);
|
mUriMap.put(CustomSliceRegistry.EMERGENCY_INFO_SLICE_URI, EmergencyInfoSlice.class);
|
||||||
|
@@ -72,13 +72,13 @@ public class CustomSliceRegistry {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backing Uri for Connected device Slice.
|
* Backing Uri for Bluetooth devices Slice.
|
||||||
*/
|
*/
|
||||||
public static final Uri CONNECTED_DEVICE_SLICE_URI = new Uri.Builder()
|
public static final Uri BLUETOOTH_DEVICES_SLICE_URI = new Uri.Builder()
|
||||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||||
.appendPath("connected_device")
|
.appendPath("bluetooth_devices")
|
||||||
.build();
|
.build();
|
||||||
/**
|
/**
|
||||||
* Backing Uri for the Data usage Slice.
|
* Backing Uri for the Data usage Slice.
|
||||||
|
@@ -162,7 +162,7 @@ public class ContextualCardLoaderTest {
|
|||||||
cards.add(new ContextualCard.Builder()
|
cards.add(new ContextualCard.Builder()
|
||||||
.setName("test_connected")
|
.setName("test_connected")
|
||||||
.setCardType(ContextualCard.CardType.SLICE)
|
.setCardType(ContextualCard.CardType.SLICE)
|
||||||
.setSliceUri(CustomSliceRegistry.CONNECTED_DEVICE_SLICE_URI)
|
.setSliceUri(CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI)
|
||||||
.build());
|
.build());
|
||||||
cards.add(new ContextualCard.Builder()
|
cards.add(new ContextualCard.Builder()
|
||||||
.setName("test_gesture")
|
.setName("test_gesture")
|
||||||
|
@@ -52,7 +52,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
public class ConnectedDeviceSliceTest {
|
public class BluetoothDevicesSliceTest {
|
||||||
|
|
||||||
private static final String BLUETOOTH_MOCK_SUMMARY = "BluetoothSummary";
|
private static final String BLUETOOTH_MOCK_SUMMARY = "BluetoothSummary";
|
||||||
private static final String BLUETOOTH_MOCK_TITLE = "BluetoothTitle";
|
private static final String BLUETOOTH_MOCK_TITLE = "BluetoothTitle";
|
||||||
@@ -60,8 +60,8 @@ public class ConnectedDeviceSliceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
private CachedBluetoothDevice mCachedBluetoothDevice;
|
private CachedBluetoothDevice mCachedBluetoothDevice;
|
||||||
|
|
||||||
private List<CachedBluetoothDevice> mBluetoothConnectedDeviceList;
|
private List<CachedBluetoothDevice> mBluetoothDeviceList;
|
||||||
private ConnectedDeviceSlice mConnectedDeviceSlice;
|
private BluetoothDevicesSlice mBluetoothDevicesSlice;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private IconCompat mIcon;
|
private IconCompat mIcon;
|
||||||
private PendingIntent mDetailIntent;
|
private PendingIntent mDetailIntent;
|
||||||
@@ -74,57 +74,53 @@ public class ConnectedDeviceSliceTest {
|
|||||||
// Set-up specs for SliceMetadata.
|
// Set-up specs for SliceMetadata.
|
||||||
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
SliceProvider.setSpecs(SliceLiveData.SUPPORTED_SPECS);
|
||||||
|
|
||||||
mConnectedDeviceSlice = spy(new ConnectedDeviceSlice(mContext));
|
mBluetoothDevicesSlice = spy(new BluetoothDevicesSlice(mContext));
|
||||||
|
|
||||||
// Mock the icon and detail intent of Bluetooth.
|
// Mock the icon and detail intent of Bluetooth.
|
||||||
mIcon = IconCompat.createWithResource(mContext, R.drawable.ic_homepage_connected_device);
|
mIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_bluetooth);
|
||||||
mDetailIntent = PendingIntent.getActivity(mContext, 0, new Intent("test action"), 0);
|
mDetailIntent = PendingIntent.getActivity(mContext, 0, new Intent("test action"), 0);
|
||||||
doReturn(mIcon).when(mConnectedDeviceSlice).getConnectedDeviceIcon(any());
|
doReturn(mIcon).when(mBluetoothDevicesSlice).getBluetoothDeviceIcon(any());
|
||||||
doReturn(mDetailIntent).when(mConnectedDeviceSlice).getBluetoothDetailIntent(any());
|
doReturn(mDetailIntent).when(mBluetoothDevicesSlice).getBluetoothDetailIntent(any());
|
||||||
|
|
||||||
// Initial Bluetooth connected device list.
|
// Initial Bluetooth device list.
|
||||||
mBluetoothConnectedDeviceList = new ArrayList<>();
|
mBluetoothDeviceList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
public void tearDown() {
|
public void tearDown() {
|
||||||
if (!mBluetoothConnectedDeviceList.isEmpty()) {
|
if (!mBluetoothDeviceList.isEmpty()) {
|
||||||
mBluetoothConnectedDeviceList.clear();
|
mBluetoothDeviceList.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSlice_hasConnectedDevices_shouldHaveConnectedDeviceTitle() {
|
public void getSlice_hasBluetoothDevices_shouldHaveBluetoothDevicesTitle() {
|
||||||
mockBluetoothDeviceList();
|
mockBluetoothDeviceList();
|
||||||
doReturn(mBluetoothConnectedDeviceList).when(
|
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getBluetoothDevices();
|
||||||
mConnectedDeviceSlice).getBluetoothConnectedDevices();
|
|
||||||
|
|
||||||
final Slice slice = mConnectedDeviceSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final List<SliceItem> sliceItems = slice.getItems();
|
final List<SliceItem> sliceItems = slice.getItems();
|
||||||
SliceTester.assertTitle(sliceItems,
|
SliceTester.assertTitle(sliceItems, mContext.getString(R.string.bluetooth_devices));
|
||||||
mContext.getString(R.string.bluetooth_connected_devices));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSlice_hasConnectedDevices_shouldMatchBluetoothMockTitle() {
|
public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() {
|
||||||
mockBluetoothDeviceList();
|
mockBluetoothDeviceList();
|
||||||
doReturn(mBluetoothConnectedDeviceList).when(
|
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getBluetoothDevices();
|
||||||
mConnectedDeviceSlice).getBluetoothConnectedDevices();
|
|
||||||
|
|
||||||
final Slice slice = mConnectedDeviceSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final List<SliceItem> sliceItems = slice.getItems();
|
final List<SliceItem> sliceItems = slice.getItems();
|
||||||
SliceTester.assertTitle(sliceItems, BLUETOOTH_MOCK_TITLE);
|
SliceTester.assertTitle(sliceItems, BLUETOOTH_MOCK_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSlice_hasConnectedDevices_shouldHavePairNewDevice() {
|
public void getSlice_hasBluetoothDevices_shouldHavePairNewDevice() {
|
||||||
mockBluetoothDeviceList();
|
mockBluetoothDeviceList();
|
||||||
doReturn(mBluetoothConnectedDeviceList).when(
|
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getBluetoothDevices();
|
||||||
mConnectedDeviceSlice).getBluetoothConnectedDevices();
|
|
||||||
|
|
||||||
final Slice slice = mConnectedDeviceSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final List<SliceItem> sliceItems = slice.getItems();
|
final List<SliceItem> sliceItems = slice.getItems();
|
||||||
SliceTester.assertTitle(sliceItems,
|
SliceTester.assertTitle(sliceItems,
|
||||||
@@ -132,22 +128,20 @@ public class ConnectedDeviceSliceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSlice_noConnectedDevices_shouldHaveNoConnectedDeviceTitle() {
|
public void getSlice_noBluetoothDevices_shouldHaveNoBluetoothDevicesTitle() {
|
||||||
doReturn(mBluetoothConnectedDeviceList).when(
|
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getBluetoothDevices();
|
||||||
mConnectedDeviceSlice).getBluetoothConnectedDevices();
|
|
||||||
|
|
||||||
final Slice slice = mConnectedDeviceSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final List<SliceItem> sliceItems = slice.getItems();
|
final List<SliceItem> sliceItems = slice.getItems();
|
||||||
SliceTester.assertTitle(sliceItems, mContext.getString(R.string.no_connected_devices));
|
SliceTester.assertTitle(sliceItems, mContext.getString(R.string.no_bluetooth_devices));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSlice_noConnectedDevices_shouldNotHavePairNewDevice() {
|
public void getSlice_noBluetoothDevices_shouldNotHavePairNewDevice() {
|
||||||
doReturn(mBluetoothConnectedDeviceList).when(
|
doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getBluetoothDevices();
|
||||||
mConnectedDeviceSlice).getBluetoothConnectedDevices();
|
|
||||||
|
|
||||||
final Slice slice = mConnectedDeviceSlice.getSlice();
|
final Slice slice = mBluetoothDevicesSlice.getSlice();
|
||||||
|
|
||||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||||
assertThat(hasTitle(metadata,
|
assertThat(hasTitle(metadata,
|
||||||
@@ -157,7 +151,7 @@ public class ConnectedDeviceSliceTest {
|
|||||||
private void mockBluetoothDeviceList() {
|
private void mockBluetoothDeviceList() {
|
||||||
doReturn(BLUETOOTH_MOCK_TITLE).when(mCachedBluetoothDevice).getName();
|
doReturn(BLUETOOTH_MOCK_TITLE).when(mCachedBluetoothDevice).getName();
|
||||||
doReturn(BLUETOOTH_MOCK_SUMMARY).when(mCachedBluetoothDevice).getConnectionSummary();
|
doReturn(BLUETOOTH_MOCK_SUMMARY).when(mCachedBluetoothDevice).getConnectionSummary();
|
||||||
mBluetoothConnectedDeviceList.add(mCachedBluetoothDevice);
|
mBluetoothDeviceList.add(mCachedBluetoothDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasTitle(SliceMetadata metadata, String title) {
|
private boolean hasTitle(SliceMetadata metadata, String title) {
|
Reference in New Issue
Block a user