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

Commit 971e2ad2 authored by Omar Abdelmonem's avatar Omar Abdelmonem
Browse files

Fix NPE in TouchpadDebugViewTest

Bug: 367331657
Test: Presubmit
Flag: com.android.hardware.input.touchpad_visualizer
Change-Id: Ifcc7d02ec4db5c093aa0e6bb7d9e48c65ed12000
parent 0b2828ce
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -29,7 +29,9 @@ import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.graphics.drawable.ColorDrawable;
import android.hardware.input.InputManager;
import android.testing.TestableContext;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
@@ -60,13 +62,15 @@ import org.mockito.MockitoAnnotations;
 */
@RunWith(AndroidJUnit4.class)
public class TouchpadDebugViewTest {
    private static final int TOUCHPAD_DEVICE_ID = 6;
    private static final int TOUCHPAD_DEVICE_ID = 60;

    private TouchpadDebugView mTouchpadDebugView;
    private WindowManager.LayoutParams mWindowLayoutParams;

    @Mock
    WindowManager mWindowManager;
    @Mock
    InputManager mInputManager;

    Rect mWindowBounds;
    WindowMetrics mWindowMetrics;
@@ -79,12 +83,21 @@ public class TouchpadDebugViewTest {
        mTestableContext = new TestableContext(context);

        mTestableContext.addMockSystemService(WindowManager.class, mWindowManager);
        mTestableContext.addMockSystemService(InputManager.class, mInputManager);

        mWindowBounds = new Rect(0, 0, 2560, 1600);
        mWindowMetrics = new WindowMetrics(mWindowBounds, new WindowInsets(mWindowBounds), 1.0f);

        when(mWindowManager.getCurrentWindowMetrics()).thenReturn(mWindowMetrics);

        InputDevice inputDevice = new InputDevice.Builder()
                .setId(TOUCHPAD_DEVICE_ID)
                .setSources(InputDevice.SOURCE_TOUCHPAD | InputDevice.SOURCE_MOUSE)
                .setName("Test Device " + TOUCHPAD_DEVICE_ID)
                .build();

        when(mInputManager.getInputDevice(TOUCHPAD_DEVICE_ID)).thenReturn(inputDevice);

        mTouchpadDebugView = new TouchpadDebugView(mTestableContext, TOUCHPAD_DEVICE_ID,
                new TouchpadHardwareProperties.Builder(0f, 0f, 500f,
                        500f, 45f, 47f, -4f, 5f, (short) 10, true,