Add new preference class MasterSwitchPreference.

- Add a new preference type that has Title and optional summary on the
  left, and a toggle switch on the right. Clicking the left part of the
  preference will open a settings screen.
- Update Connected devices->Bluetooth to use this new preference.
- Refactor BluetoothSettings and BluetoothEnabler to share code between
  the new bluetooth preference controller and the bluetooth setting.

Bug: 34280769
Test: make RunSettingsRoboTests
Change-Id: I109ecdba640ecdd4748a6e5b2b4f4c47cbf653fd
This commit is contained in:
Doris Ling
2017-01-18 13:59:36 -08:00
parent 8f969665e3
commit 1432cb8529
16 changed files with 1107 additions and 233 deletions

View File

@@ -16,14 +16,11 @@
package com.android.settings.bluetooth;
import android.bluetooth.BluetoothAdapter;
import android.content.Context;
import com.android.settings.R;
import com.android.settings.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
import com.android.settingslib.bluetooth.LocalBluetoothManager;
import org.junit.Before;
@@ -34,15 +31,10 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowBluetoothAdapter;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -67,102 +59,27 @@ public class BluetoothSettingsSummaryProviderTest {
}
@Test
public void setListening_shouldUpdateSummary() {
public void setListening_shouldRegister() {
mSummaryProvider.setListening(true);
verify(mBluetoothManager.getEventManager()).registerCallback(mSummaryProvider);
verify(mSummaryLoader).setSummary(eq(mSummaryProvider), anyString());
verify(mBluetoothManager.getEventManager()).registerCallback(
mSummaryProvider.mSummaryHelper);
}
@Test
public void setNotListening_shouldUnregister() {
mSummaryProvider.setListening(false);
verify(mBluetoothManager.getEventManager()).unregisterCallback(mSummaryProvider);
verify(mBluetoothManager.getEventManager()).unregisterCallback(
mSummaryProvider.mSummaryHelper);
}
@Test
public void updateSummary_btDisabled_shouldShowDisabledMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().disable();
mSummaryProvider.setListening(true);
public void onSummaryChanged_shouldSetSummary() {
final String summary = "Bluetooth summary";
mSummaryProvider.onSummaryChanged(summary);
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disabled));
}
@Test
public void updateSummary_btEnabled_noDevice_shouldShowDisconnectedMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
mSummaryProvider.setListening(true);
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disconnected));
}
@Test
public void updateState_btEnabled_noDevice_shouldShowDisconnectedMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
mSummaryProvider.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON);
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disconnected));
}
@Test
public void updateState_btDisabled_shouldShowDisabledMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
mSummaryProvider.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_OFF);
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disabled));
}
@Test
public void updateConnectionState_disconnected_shouldShowDisconnectedMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
when(mBluetoothManager.getBluetoothAdapter().getConnectionState())
.thenReturn(BluetoothAdapter.STATE_DISCONNECTED);
mSummaryProvider.setListening(true);
mSummaryProvider.onConnectionStateChanged(null /* device */,
BluetoothAdapter.STATE_DISCONNECTED);
verify(mSummaryLoader, times(2)).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disconnected));
}
@Test
public void updateConnectionState_connected_shouldShowConnectedMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
when(mBluetoothManager.getBluetoothAdapter().getConnectionState())
.thenReturn(BluetoothAdapter.STATE_CONNECTED);
final List<CachedBluetoothDevice> devices = new ArrayList<>();
devices.add(mock(CachedBluetoothDevice.class));
when(devices.get(0).isConnected()).thenReturn(true);
when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy())
.thenReturn(devices);
mSummaryProvider.setListening(true);
mSummaryProvider.onConnectionStateChanged(null /* device */,
BluetoothAdapter.STATE_CONNECTED);
verify(mSummaryLoader).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_connected));
}
@Test
public void updateConnectionState_inconsistentState_shouldShowDisconnectedMessage() {
ShadowBluetoothAdapter.getDefaultAdapter().enable();
when(mBluetoothManager.getBluetoothAdapter().getConnectionState())
.thenReturn(BluetoothAdapter.STATE_CONNECTED);
mSummaryProvider.setListening(true);
mSummaryProvider.onConnectionStateChanged(null /* device */,
BluetoothAdapter.STATE_CONNECTED);
verify(mSummaryLoader, times(2)).setSummary(mSummaryProvider,
mContext.getString(R.string.bluetooth_disconnected));
verify(mSummaryLoader).setSummary(mSummaryProvider, summary);
}
}