Loading src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java +13 −5 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import android.util.Log; import com.android.settings.R; import com.android.settings.widget.SummaryUpdater; Loading @@ -29,9 +29,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothAdapter; import com.android.settingslib.bluetooth.LocalBluetoothManager; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; /** Loading @@ -39,6 +37,7 @@ import java.util.Set; * bluetooth summary info. */ public final class BluetoothSummaryUpdater extends SummaryUpdater implements BluetoothCallback { private static final String TAG = "BluetoothSummaryUpdater"; private final LocalBluetoothManager mBluetoothManager; private final LocalBluetoothAdapter mBluetoothAdapter; Loading @@ -58,6 +57,9 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu public void onBluetoothStateChanged(int bluetoothState) { mEnabled = bluetoothState == BluetoothAdapter.STATE_ON || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; if (!mEnabled) { mConnectionState = BluetoothAdapter.STATE_DISCONNECTED; } notifyChangeIfNeeded(); } Loading Loading @@ -161,7 +163,6 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu if (devices == null || devices.isEmpty()) { return null; } for (BluetoothDevice device : devices) { if (device.isConnected()) { deviceName = device.getName(); Loading @@ -171,7 +172,14 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu } } } if (deviceName == null) { Log.w(TAG, "getConnectedDeviceSummary, deviceName is null, numBondedDevices=" + devices.size()); for (BluetoothDevice device : devices) { Log.w(TAG, "getConnectedDeviceSummary, device=" + device.getName() + "[" + device.getAddress() + "]" + ", isConnected=" + device.isConnected()); } } return count > 1 ? mContext.getString(R.string.bluetooth_connected_multiple_devices_summary) : mContext.getString(R.string.bluetooth_connected_summary, deviceName); } Loading tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -44,8 +44,11 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -132,6 +135,36 @@ public class BluetoothSummaryUpdaterTest { mContext.getString(R.string.disconnected)); } @Test public void onBluetoothStateChanged_ConnectedDisabledEnabled_shouldSendDisconnectedSummary() { final boolean[] connected = {false}; final List<CachedBluetoothDevice> devices = new ArrayList<>(); devices.add(mock(CachedBluetoothDevice.class)); doAnswer(invocation -> connected[0]).when(devices.get(0)).isConnected(); when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) .thenReturn(devices); when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED); prepareConnectedDevice(false); mSummaryUpdater.register(true); verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected)); connected[0] = true; when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED); mSummaryUpdater.onConnectionStateChanged(null /* device */, BluetoothAdapter.STATE_CONNECTED); verify(mListener).onSummaryChanged( mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME)); mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled)); connected[0] = false; mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON); verify(mListener, times(2)).onSummaryChanged(mContext.getString(R.string.disconnected)); verify(mListener, times(4)).onSummaryChanged(anyString()); } @Test public void onConnectionStateChanged_connected_shouldSendConnectedMessage() { final List<CachedBluetoothDevice> devices = new ArrayList<>(); Loading Loading
src/com/android/settings/bluetooth/BluetoothSummaryUpdater.java +13 −5 Original line number Diff line number Diff line Loading @@ -20,7 +20,7 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.content.Context; import android.support.annotation.VisibleForTesting; import android.text.TextUtils; import android.util.Log; import com.android.settings.R; import com.android.settings.widget.SummaryUpdater; Loading @@ -29,9 +29,7 @@ import com.android.settingslib.bluetooth.CachedBluetoothDevice; import com.android.settingslib.bluetooth.LocalBluetoothAdapter; import com.android.settingslib.bluetooth.LocalBluetoothManager; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Set; /** Loading @@ -39,6 +37,7 @@ import java.util.Set; * bluetooth summary info. */ public final class BluetoothSummaryUpdater extends SummaryUpdater implements BluetoothCallback { private static final String TAG = "BluetoothSummaryUpdater"; private final LocalBluetoothManager mBluetoothManager; private final LocalBluetoothAdapter mBluetoothAdapter; Loading @@ -58,6 +57,9 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu public void onBluetoothStateChanged(int bluetoothState) { mEnabled = bluetoothState == BluetoothAdapter.STATE_ON || bluetoothState == BluetoothAdapter.STATE_TURNING_ON; if (!mEnabled) { mConnectionState = BluetoothAdapter.STATE_DISCONNECTED; } notifyChangeIfNeeded(); } Loading Loading @@ -161,7 +163,6 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu if (devices == null || devices.isEmpty()) { return null; } for (BluetoothDevice device : devices) { if (device.isConnected()) { deviceName = device.getName(); Loading @@ -171,7 +172,14 @@ public final class BluetoothSummaryUpdater extends SummaryUpdater implements Blu } } } if (deviceName == null) { Log.w(TAG, "getConnectedDeviceSummary, deviceName is null, numBondedDevices=" + devices.size()); for (BluetoothDevice device : devices) { Log.w(TAG, "getConnectedDeviceSummary, device=" + device.getName() + "[" + device.getAddress() + "]" + ", isConnected=" + device.isConnected()); } } return count > 1 ? mContext.getString(R.string.bluetooth_connected_multiple_devices_summary) : mContext.getString(R.string.bluetooth_connected_summary, deviceName); } Loading
tests/robotests/src/com/android/settings/bluetooth/BluetoothSummaryUpdaterTest.java +33 −0 Original line number Diff line number Diff line Loading @@ -44,8 +44,11 @@ import java.util.HashSet; import java.util.List; import java.util.Set; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; Loading Loading @@ -132,6 +135,36 @@ public class BluetoothSummaryUpdaterTest { mContext.getString(R.string.disconnected)); } @Test public void onBluetoothStateChanged_ConnectedDisabledEnabled_shouldSendDisconnectedSummary() { final boolean[] connected = {false}; final List<CachedBluetoothDevice> devices = new ArrayList<>(); devices.add(mock(CachedBluetoothDevice.class)); doAnswer(invocation -> connected[0]).when(devices.get(0)).isConnected(); when(mBluetoothManager.getCachedDeviceManager().getCachedDevicesCopy()) .thenReturn(devices); when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_DISCONNECTED); prepareConnectedDevice(false); mSummaryUpdater.register(true); verify(mListener).onSummaryChanged(mContext.getString(R.string.disconnected)); connected[0] = true; when(mBtAdapter.getConnectionState()).thenReturn(BluetoothAdapter.STATE_CONNECTED); mSummaryUpdater.onConnectionStateChanged(null /* device */, BluetoothAdapter.STATE_CONNECTED); verify(mListener).onSummaryChanged( mContext.getString(R.string.bluetooth_connected_summary, DEVICE_NAME)); mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_OFF); verify(mListener).onSummaryChanged(mContext.getString(R.string.bluetooth_disabled)); connected[0] = false; mSummaryUpdater.onBluetoothStateChanged(BluetoothAdapter.STATE_TURNING_ON); verify(mListener, times(2)).onSummaryChanged(mContext.getString(R.string.disconnected)); verify(mListener, times(4)).onSummaryChanged(anyString()); } @Test public void onConnectionStateChanged_connected_shouldSendConnectedMessage() { final List<CachedBluetoothDevice> devices = new ArrayList<>(); Loading