Merge "Guard against null input device in StylusDeviceUpdater" into udc-dev am: e78b1f377e
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22894945 Change-Id: I01556c0442565babb72c2f879f109ee8e12ba277 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -100,6 +100,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
|||||||
@Override
|
@Override
|
||||||
public void onInputDeviceAdded(int deviceId) {
|
public void onInputDeviceAdded(int deviceId) {
|
||||||
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
|
InputDevice inputDevice = mInputManager.getInputDevice(deviceId);
|
||||||
|
if (inputDevice == null) return;
|
||||||
|
|
||||||
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)
|
if (inputDevice.supportsSource(InputDevice.SOURCE_STYLUS)
|
||||||
&& !inputDevice.isExternal()) {
|
&& !inputDevice.isExternal()) {
|
||||||
try {
|
try {
|
||||||
@@ -121,7 +123,10 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
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();
|
forceUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,6 +194,8 @@ public class StylusDeviceUpdater implements InputManager.InputDeviceListener,
|
|||||||
boolean hasConnectedBluetoothStylusDevice() {
|
boolean hasConnectedBluetoothStylusDevice() {
|
||||||
for (int deviceId : mInputManager.getInputDeviceIds()) {
|
for (int deviceId : mInputManager.getInputDeviceIds()) {
|
||||||
InputDevice device = mInputManager.getInputDevice(deviceId);
|
InputDevice device = mInputManager.getInputDevice(deviceId);
|
||||||
|
if (device == null) continue;
|
||||||
|
|
||||||
if (device.supportsSource(InputDevice.SOURCE_STYLUS)
|
if (device.supportsSource(InputDevice.SOURCE_STYLUS)
|
||||||
&& mInputManager.getInputDeviceBluetoothAddress(deviceId) != null) {
|
&& mInputManager.getInputDeviceBluetoothAddress(deviceId) != null) {
|
||||||
return true;
|
return true;
|
||||||
|
@@ -26,6 +26,7 @@ import static org.mockito.Mockito.never;
|
|||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -108,6 +109,15 @@ public class StylusDeviceUpdaterTest {
|
|||||||
any());
|
any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onInputDeviceAdded_null_doesNothing() {
|
||||||
|
doReturn(null).when(mInputManager).getInputDevice(0);
|
||||||
|
mStylusDeviceUpdater.onInputDeviceAdded(0);
|
||||||
|
|
||||||
|
verify(mInputManager).getInputDevice(0);
|
||||||
|
verifyNoMoreInteractions(mInputManager);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void onInputDeviceAdded_internalStylus_registersBatteryListener() {
|
public void onInputDeviceAdded_internalStylus_registersBatteryListener() {
|
||||||
mStylusDeviceUpdater.onInputDeviceAdded(1);
|
mStylusDeviceUpdater.onInputDeviceAdded(1);
|
||||||
@@ -124,6 +134,15 @@ public class StylusDeviceUpdaterTest {
|
|||||||
any());
|
any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onInputDeviceChanged_null_doesNothing() {
|
||||||
|
doReturn(null).when(mInputManager).getInputDevice(0);
|
||||||
|
mStylusDeviceUpdater.onInputDeviceChanged(0);
|
||||||
|
|
||||||
|
verify(mInputManager).getInputDevice(0);
|
||||||
|
verifyNoMoreInteractions(mInputManager);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void click_usiPreference_launchUsiDetailsPage() {
|
public void click_usiPreference_launchUsiDetailsPage() {
|
||||||
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();
|
doReturn(mSettingsActivity).when(mDashboardFragment).getContext();
|
||||||
|
Reference in New Issue
Block a user