diff --git a/res/layout/preference_bluetooth.xml b/res/layout/preference_bluetooth.xml deleted file mode 100644 index c339e675f21..00000000000 --- a/res/layout/preference_bluetooth.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - diff --git a/res/layout/preference_progress_category.xml b/res/layout/preference_progress_category.xml index 138069829f7..9f5a8b4d10e 100644 --- a/res/layout/preference_progress_category.xml +++ b/res/layout/preference_progress_category.xml @@ -35,7 +35,6 @@ android:id="@android:id/icon" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:tint="?android:attr/textColorPrimary" android:maxWidth="18dp" android:maxHeight="18dp"/> @@ -47,7 +46,8 @@ android:layout_height="wrap_content" android:layout_weight="1" android:layout_gravity="start|center" - android:textAppearance="@android:style/TextAppearance.Material.Body2"/> + android:textAppearance="@android:style/TextAppearance.Material.Body2" + android:textColor="?android:attr/colorAccent"/> (R.drawable.ic_bt_headset_hfp, HEADSET); } - if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) { + if (btClass.doesClassMatch(BluetoothClass.PROFILE_A2DP)) { return new Pair(R.drawable.ic_bt_headphones_a2dp, HEADPHONE); } } diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index 5679f906f60..317a350d80a 100644 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -45,13 +45,14 @@ import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.settings.LinkifyUtils; import com.android.settings.R; import com.android.settings.SettingsActivity; -import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.location.ScanningSettings; import com.android.settings.search.BaseSearchIndexProvider; import com.android.settings.search.Indexable; import com.android.settings.search.SearchIndexableRaw; import com.android.settings.widget.FooterPreference; +import com.android.settings.widget.GearPreference; +import com.android.settings.widget.SummaryUpdater.OnSummaryChangeListener; import com.android.settings.widget.SwitchBar; import com.android.settings.widget.SwitchBarController; import com.android.settingslib.bluetooth.BluetoothDeviceFilter; @@ -476,24 +477,25 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem } } - private final View.OnClickListener mDeviceProfilesListener = new View.OnClickListener() { - @Override - public void onClick(View v) { - // User clicked on advanced options icon for a device in the list - if (!(v.getTag() instanceof CachedBluetoothDevice)) { - Log.w(TAG, "onClick() called for other View: " + v); - return; - } - - final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag(); - Bundle args = new Bundle(); - args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS, - device.getDevice().getAddress()); - DeviceProfilesSettings profileSettings = new DeviceProfilesSettings(); - profileSettings.setArguments(args); - profileSettings.show(getFragmentManager(), - DeviceProfilesSettings.class.getSimpleName()); + private final GearPreference.OnGearClickListener mDeviceProfilesListener = pref -> { + // User clicked on advanced options icon for a device in the list + if (!(pref instanceof BluetoothDevicePreference)) { + Log.w(TAG, "onClick() called for other View: " + pref); + return; } + final CachedBluetoothDevice device = + ((BluetoothDevicePreference) pref).getBluetoothDevice(); + if (device == null) { + Log.w(TAG, "No BT device attached with this pref: " + pref); + return; + } + final Bundle args = new Bundle(); + args.putString(DeviceProfilesSettings.ARG_DEVICE_ADDRESS, + device.getDevice().getAddress()); + final DeviceProfilesSettings profileSettings = new DeviceProfilesSettings(); + profileSettings.setArguments(args); + profileSettings.show(getFragmentManager(), + DeviceProfilesSettings.class.getSimpleName()); }; /** @@ -506,7 +508,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem CachedBluetoothDevice cachedDevice = preference.getCachedDevice(); if (cachedDevice.getBondState() == BluetoothDevice.BOND_BONDED) { // Only paired device have an associated advanced settings screen - preference.setOnSettingsClickListener(mDeviceProfilesListener); + preference.setOnGearClickListener(mDeviceProfilesListener); } } diff --git a/src/com/android/settings/bluetooth/DevicePickerFragment.java b/src/com/android/settings/bluetooth/DevicePickerFragment.java index f250c9a1325..490a3adeeb1 100644 --- a/src/com/android/settings/bluetooth/DevicePickerFragment.java +++ b/src/com/android/settings/bluetooth/DevicePickerFragment.java @@ -61,11 +61,6 @@ public final class DevicePickerFragment extends DeviceListPreferenceFragment { mLaunchClass = intent.getStringExtra(BluetoothDevicePicker.EXTRA_LAUNCH_CLASS); } - @Override - void initDevicePreference(BluetoothDevicePreference preference) { - preference.setWidgetLayoutResource(R.layout.preference_empty_list); - } - @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { menu.add(Menu.NONE, MENU_ID_REFRESH, 0, R.string.bluetooth_search_for_devices) diff --git a/tests/app/src/com/android/settings/bluetooth/DevicePickerActivityTest.java b/tests/app/src/com/android/settings/bluetooth/DevicePickerActivityTest.java new file mode 100644 index 00000000000..1b855c93b62 --- /dev/null +++ b/tests/app/src/com/android/settings/bluetooth/DevicePickerActivityTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2017 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.bluetooth; + +import android.app.Instrumentation; +import android.content.Intent; +import android.support.test.InstrumentationRegistry; +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +@SmallTest +public class DevicePickerActivityTest { + + private Instrumentation mInstrumentation; + + @Before + public void setUp() throws Exception { + mInstrumentation = InstrumentationRegistry.getInstrumentation(); + } + + @Test + public void startActivityNoCrash() { + mInstrumentation.startActivitySync( + new Intent("android.bluetooth.devicepicker.action.LAUNCH")); + // No crash + } +} diff --git a/tests/app/src/com/android/settings/fuelgauge/PowerUsageSummaryUiTest.java b/tests/app/src/com/android/settings/fuelgauge/PowerUsageSummaryUiTest.java index 47e644adfbf..6c372c5f5f1 100644 --- a/tests/app/src/com/android/settings/fuelgauge/PowerUsageSummaryUiTest.java +++ b/tests/app/src/com/android/settings/fuelgauge/PowerUsageSummaryUiTest.java @@ -16,26 +16,11 @@ package com.android.settings.fuelgauge; -import static android.support.test.InstrumentationRegistry.getTargetContext; -import static android.support.test.espresso.Espresso.onData; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.action.ViewActions.click; -import static android.support.test.espresso.intent.Intents.intended; -import static android.support.test.espresso.intent.Intents.intending; -import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent; -import static android.support.test.espresso.matcher.PreferenceMatchers.withKey; -import static android.support.test.espresso.matcher.ViewMatchers.isDescendantOfA; -import static android.support.test.espresso.matcher.ViewMatchers.withId; import static android.support.test.espresso.matcher.ViewMatchers.withText; -import static org.hamcrest.Matchers.allOf; -import static org.hamcrest.core.IsAnything.anything; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import android.app.Activity; import android.app.Instrumentation; -import android.content.Context; import android.content.Intent; import android.support.test.InstrumentationRegistry; import android.support.test.filters.SmallTest; diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java index 59151180584..c4c1f8a89e8 100644 --- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java +++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDevicePreferenceTest.java @@ -17,8 +17,10 @@ package com.android.settings.bluetooth; import android.bluetooth.BluetoothDevice; import android.content.Context; +import android.os.UserManager; import com.android.internal.logging.nano.MetricsProto.MetricsEvent; +import com.android.settings.R; import com.android.settings.SettingsRobolectricTestRunner; import com.android.settings.TestConfig; import com.android.settings.core.instrumentation.MetricsFeatureProvider; @@ -32,7 +34,10 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.robolectric.RuntimeEnvironment; import org.robolectric.annotation.Config; +import org.robolectric.util.ReflectionHelpers; +import static com.google.common.truth.Truth.assertThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -66,7 +71,7 @@ public class BluetoothDevicePreferenceTest { mPreference.onClicked(); verify(mMetricsFeatureProvider).action( - mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT); + mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_DISCONNECT); } @Test @@ -77,7 +82,7 @@ public class BluetoothDevicePreferenceTest { mPreference.onClicked(); verify(mMetricsFeatureProvider).action( - mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT); + mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_CONNECT); } @Test @@ -89,6 +94,46 @@ public class BluetoothDevicePreferenceTest { mPreference.onClicked(); verify(mMetricsFeatureProvider).action( - mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR); + mContext, MetricsEvent.ACTION_SETTINGS_BLUETOOTH_PAIR); + } + + @Test + public void getSecondTargetResource_shouldBeGearIconLayout() { + assertThat(mPreference.getSecondTargetResId()).isEqualTo(R.layout.preference_widget_gear); + } + + @Test + public void shouldHideSecondTarget_noDevice_shouldReturnTrue() { + ReflectionHelpers.setField(mPreference, "mCachedDevice", null); + + assertThat(mPreference.shouldHideSecondTarget()).isTrue(); + } + + @Test + public void shouldHideSecondTarget_notBond_shouldReturnTrue() { + when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_NONE); + + assertThat(mPreference.shouldHideSecondTarget()).isTrue(); + } + + @Test + public void shouldHideSecondTarget_hasUserRestriction_shouldReturnTrue() { + final UserManager um = mock(UserManager.class); + ReflectionHelpers.setField(mPreference, "mUserManager", um); + when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH)) + .thenReturn(true); + + assertThat(mPreference.shouldHideSecondTarget()).isTrue(); + } + + @Test + public void shouldHideSecondTarget_hasBoundDeviceAndNoRestriction_shouldReturnFalse() { + when(mCachedBluetoothDevice.getBondState()).thenReturn(BluetoothDevice.BOND_BONDED); + final UserManager um = mock(UserManager.class); + ReflectionHelpers.setField(mPreference, "mUserManager", um); + when(um.hasUserRestriction(UserManager.DISALLOW_CONFIG_BLUETOOTH)) + .thenReturn(false); + + assertThat(mPreference.shouldHideSecondTarget()).isFalse(); } }