Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c584bfae authored by Vania Januar's avatar Vania Januar Committed by Automerger Merge Worker
Browse files

Merge "Guard against null input device in StylusDeviceUpdater" into udc-dev...

Merge "Guard against null input device in StylusDeviceUpdater" into udc-dev am: e78b1f37 am: 3f449e0c

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/22894945



Change-Id: Ieec3b8affc3f6f1226aacf214a458ea5cd2ec48c
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 046d7356 3f449e0c
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -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;
+19 −0
Original line number Diff line number Diff line
@@ -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();