diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 024569b3173..ef6b8183042 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -394,8 +394,6 @@ 1200dp - - @dimen/abc_slice_row_max_height 320dp diff --git a/res/values/strings.xml b/res/values/strings.xml index aa37f063ec9..81c76e4a6f5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -144,6 +144,8 @@ Prevent use of the bluetooth dialer when the screen is locked + + Bluetooth devices Device name diff --git a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java index 3d759628cda..53782e5fa9e 100644 --- a/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java +++ b/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSlice.java @@ -16,14 +16,14 @@ package com.android.settings.homepage.contextualcards.slices; -import static android.app.slice.Slice.EXTRA_TOGGLE_STATE; - import android.app.PendingIntent; import android.app.settings.SettingsEnums; import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; 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.os.Bundle; @@ -77,8 +77,6 @@ public class BluetoothDevicesSlice implements CustomSliceable { private static final String TAG = "BluetoothDevicesSlice"; - private static int sToggledState; - private final Context mContext; public BluetoothDevicesSlice(Context context) { @@ -103,37 +101,26 @@ public class BluetoothDevicesSlice implements CustomSliceable { final IconCompat icon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_settings_bluetooth); - final CharSequence title = mContext.getText(R.string.bluetooth_settings_title); + final CharSequence title = mContext.getText(R.string.bluetooth_devices); final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0, getIntent(), 0); final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title); + final SliceAction pairNewDeviceAction = getPairNewDeviceAction(); final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY) .setAccentColor(COLOR_NOT_TINTED) + .addAction(pairNewDeviceAction) .setHeader(new ListBuilder.HeaderBuilder() .setTitle(title) .setPrimaryAction(primarySliceAction)); - // Only show a toggle when Bluetooth is off and not turning on. - if ((!isBluetoothEnabled(btAdapter) && sToggledState != BluetoothAdapter.STATE_TURNING_ON) - || sToggledState == BluetoothAdapter.STATE_TURNING_OFF) { - sToggledState = 0; - final PendingIntent toggleAction = getBroadcastIntent(mContext); - final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction, - null /* actionTitle */, false /* isChecked */); - return listBuilder - .addAction(toggleSliceAction) - .build(); + // Only show a header when Bluetooth is off. + if (!isBluetoothEnabled(btAdapter)) { + return listBuilder.build(); } - sToggledState = 0; // Get row builders by Bluetooth devices. final List rows = getBluetoothRowBuilder(); - if (rows.isEmpty()) { - return listBuilder - .addRow(getPairNewDeviceRow()) - .build(); - } // Get displayable device count. final int deviceCount = Math.min(rows.size(), DEFAULT_EXPANDED_ROW_COUNT); @@ -161,20 +148,6 @@ public class BluetoothDevicesSlice implements CustomSliceable { @Override public void onNotifyChange(Intent intent) { - final BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); - final boolean currentState = isBluetoothEnabled(btAdapter); - final boolean newState = intent.getBooleanExtra(EXTRA_TOGGLE_STATE, currentState); - if (newState != currentState) { - if (newState) { - sToggledState = BluetoothAdapter.STATE_TURNING_ON; - btAdapter.enable(); - } else { - sToggledState = BluetoothAdapter.STATE_TURNING_OFF; - btAdapter.disable(); - } - mContext.getContentResolver().notifyChange(getUri(), null); - } - // Activate available media device. final int bluetoothDeviceHashCode = intent.getIntExtra(BLUETOOTH_DEVICE_HASH_CODE, -1); for (CachedBluetoothDevice cachedBluetoothDevice : getConnectedBluetoothDevices()) { @@ -250,8 +223,11 @@ public class BluetoothDevicesSlice implements CustomSliceable { return Utils.createIconWithDrawable(drawable); } - private ListBuilder.RowBuilder getPairNewDeviceRow() { - final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_add_24dp); + private SliceAction getPairNewDeviceAction() { + 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()) @@ -260,11 +236,7 @@ public class BluetoothDevicesSlice implements CustomSliceable { .toIntent(); final PendingIntent pi = PendingIntent.getActivity(mContext, intent.hashCode(), intent, 0 /* flags */); - final SliceAction action = SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, - title); - return new ListBuilder.RowBuilder() - .setTitleItem(action) - .setTitle(title); + return SliceAction.createDeeplink(pi, icon, ListBuilder.ICON_IMAGE, title); } private List getBluetoothRowBuilder() { diff --git a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java index 0eda973021b..cec3bee0e7a 100644 --- a/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java +++ b/tests/robotests/src/com/android/settings/homepage/contextualcards/slices/BluetoothDevicesSliceTest.java @@ -16,7 +16,6 @@ package com.android.settings.homepage.contextualcards.slices; -import static android.app.slice.Slice.EXTRA_TOGGLE_STATE; import static android.app.slice.Slice.HINT_LIST_ITEM; import static android.app.slice.SliceItem.FORMAT_SLICE; @@ -38,7 +37,6 @@ import androidx.slice.Slice; import androidx.slice.SliceItem; import androidx.slice.SliceMetadata; import androidx.slice.SliceProvider; -import androidx.slice.core.SliceAction; import androidx.slice.core.SliceQuery; import androidx.slice.widget.SliceLiveData; @@ -117,91 +115,17 @@ public class BluetoothDevicesSliceTest { @Test @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_bluetoothOff_shouldHaveToggle() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_OFF); - + public void getSlice_hasBluetoothHardware_shouldHaveBluetoothDevicesTitleAndPairNewDevice() { final Slice slice = mBluetoothDevicesSlice.getSlice(); final SliceMetadata metadata = SliceMetadata.from(mContext, slice); - assertTitleAndIcon(metadata); - final List toggles = metadata.getToggles(); - assertThat(toggles).hasSize(1); - } - - @Test - @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_bluetoothOn_shouldNotHaveToggle() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_ON); - - final Slice slice = mBluetoothDevicesSlice.getSlice(); - - final SliceMetadata metadata = SliceMetadata.from(mContext, slice); - assertTitleAndIcon(metadata); - final List toggles = metadata.getToggles(); - assertThat(toggles).isEmpty(); - } - - @Test - @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_bluetoothTurningOff_shouldHaveToggle() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_ON); - final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, false); - - mBluetoothDevicesSlice.onNotifyChange(intent); - final Slice slice = mBluetoothDevicesSlice.getSlice(); - - final SliceMetadata metadata = SliceMetadata.from(mContext, slice); - final List toggles = metadata.getToggles(); - assertThat(toggles).hasSize(1); - } - - @Test - @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_bluetoothTurningOn_shouldHaveToggle() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_OFF); - final Intent intent = new Intent().putExtra(EXTRA_TOGGLE_STATE, true); - - mBluetoothDevicesSlice.onNotifyChange(intent); - final Slice slice = mBluetoothDevicesSlice.getSlice(); - - final SliceMetadata metadata = SliceMetadata.from(mContext, slice); - final List toggles = metadata.getToggles(); - assertThat(toggles).isEmpty(); - } - - @Test - @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_noBluetoothDevice_shouldHavePairNewDeviceRow() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_ON); - doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices(); - - final Slice slice = mBluetoothDevicesSlice.getSlice(); + assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices)); final List sliceItems = slice.getItems(); SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString( R.string.bluetooth_pairing_pref_title)); } - @Test - @Config(shadows = ShadowBluetoothAdapter.class) - public void getSlice_hasBluetoothDevices_shouldNotHavePairNewDeviceRow() { - final ShadowBluetoothAdapter adapter = Shadow.extract(BluetoothAdapter.getDefaultAdapter()); - adapter.setState(BluetoothAdapter.STATE_ON); - mockBluetoothDeviceList(1); - doReturn(mBluetoothDeviceList).when(mBluetoothDevicesSlice).getConnectedBluetoothDevices(); - - final Slice slice = mBluetoothDevicesSlice.getSlice(); - - final List sliceItems = slice.getItems(); - SliceTester.assertNoSliceItemContainsTitle(sliceItems, mContext.getString( - R.string.bluetooth_pairing_pref_title)); - } - @Test @Config(shadows = ShadowBluetoothAdapter.class) public void getSlice_hasBluetoothDevices_shouldMatchBluetoothMockTitle() { @@ -280,16 +204,6 @@ public class BluetoothDevicesSliceTest { } } - private void assertTitleAndIcon(SliceMetadata metadata) { - assertThat(metadata.getTitle()).isEqualTo(mContext.getString( - R.string.bluetooth_settings_title)); - - final SliceAction primaryAction = metadata.getPrimaryAction(); - final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, - com.android.internal.R.drawable.ic_settings_bluetooth); - assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString()); - } - @Implements(BluetoothAdapter.class) public static class ShadowNoBluetoothAdapter extends ShadowBluetoothAdapter { @Implementation diff --git a/tests/robotests/src/com/android/settings/testutils/SliceTester.java b/tests/robotests/src/com/android/settings/testutils/SliceTester.java index 03a7146ddc1..6fb2c49ba4c 100644 --- a/tests/robotests/src/com/android/settings/testutils/SliceTester.java +++ b/tests/robotests/src/com/android/settings/testutils/SliceTester.java @@ -242,16 +242,6 @@ public class SliceTester { assertThat(hasText(sliceItems, title, HINT_TITLE)).isTrue(); } - /** - * Assert no slice item contains title. - * - * @param sliceItems All slice items of a Slice. - * @param title Title for asserting. - */ - public static void assertNoSliceItemContainsTitle(List sliceItems, String title) { - assertThat(hasText(sliceItems, title, HINT_TITLE)).isFalse(); - } - /** * Assert any slice item contains subtitle. *