1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.accessibilityservice.cts; 18 19 import android.accessibility.cts.common.InstrumentedAccessibilityService; 20 import android.accessibilityservice.AccessibilityServiceInfo; 21 import android.view.MotionEvent; 22 23 import androidx.annotation.NonNull; 24 25 import java.util.function.Consumer; 26 27 public class StubMotionInterceptingAccessibilityService extends InstrumentedAccessibilityService { 28 private Consumer<MotionEvent> mMotionEventListener; 29 setMotionEventSources(int sources)30 public void setMotionEventSources(int sources) { 31 AccessibilityServiceInfo info = getServiceInfo(); 32 info.setMotionEventSources(sources); 33 setServiceInfo(info); 34 } 35 setOnMotionEventListener(Consumer<MotionEvent> listener)36 public void setOnMotionEventListener(Consumer<MotionEvent> listener) { 37 mMotionEventListener = listener; 38 getServiceInfo(); 39 } 40 41 @Override onMotionEvent(@onNull MotionEvent event)42 public void onMotionEvent(@NonNull MotionEvent event) { 43 super.onMotionEvent(event); 44 mMotionEventListener.accept(event); 45 } 46 } 47