Merge "Guard against null input device in StylusDeviceUpdater" into udc-dev
This commit is contained in:
@@ -100,6 +100,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
||||
@Override
|
||||
public void onInputDeviceAdded(int deviceId) {
|
||||
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
|
||||
if (inputDevice == null) return;
|
||||
|
||||
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)
|
||||
&& !inputDevice.isExternal()) {
|
||||
try {
|
||||
@@ -121,7 +123,10 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
||||
|
||||
@Override
|
||||
public void onInputDeviceChanged(int deviceId) {
|
||||
if (mInputManager.getInputDevice(deviceId).supportsSource(InputDevice.SOURCE_STYLUS)) {
|
||||
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
|
||||
if (inputDevice == null) return;
|
||||
|
||||
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)) {
|
||||
forceUpdate();
|
||||
}
|
||||
}
|
||||
@@ -189,6 +194,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
||||
boolean hasConnectedBluetoothStylusDevice() {
|
||||
for (int deviceId : mInputManager.getInputDeviceIds()) {
|
||||
InputDevice device = mInputManager.getInputDevice(deviceId);
|
||||
if (device == null) continue;
|
||||
|
||||
if (device.supportsSource(InputDevice.SOURCE_STYLUS)
|
||||
&& mInputManager.getInputDeviceBluetoothAddress(deviceId) != null) {
|
||||
return true;
|
||||
|
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -108,6 +109,15 @@ public class StylusDeviceUpdaterTest {
|
||||
any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInputDeviceAdded_null_doesNothing() {
|
||||
doReturn(null).when(mInputManager).getInputDevice(0);
|
||||
mStylusDeviceUpdater.onInputDeviceAdded(0);
|
||||
|
||||
verify(mInputManager).getInputDevice(0);
|
||||
verifyNoMoreInteractions(mInputManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInputDeviceAdded_internalStylus_registersBatteryListener() {
|
||||
mStylusDeviceUpdater.onInputDeviceAdded(1);
|
||||
@@ -124,6 +134,15 @@ public class StylusDeviceUpdaterTest {
|
||||
any());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInputDeviceChanged_null_doesNothing() {
|
||||
doReturn(null).when(mInputManager).getInputDevice(0);
|
||||
mStylusDeviceUpdater.onInputDeviceChanged(0);
|
||||
|
||||
verify(mInputManager).getInputDevice(0);
|
||||
verifyNoMoreInteractions(mInputManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void click_usiPreference_launchUsiDetailsPage() {
|
||||
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();
|
||||
|
Reference in New Issue
Block a user