1/* 2 * Copyright (C) 2015 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 17package com.android.server.accessibility; 18 19import android.view.KeyEvent; 20import android.view.MotionEvent; 21import android.view.accessibility.AccessibilityEvent; 22 23/** 24 * Intercepts key events and forwards them to accessibility manager service. 25 */ 26public class KeyboardInterceptor implements EventStreamTransformation { 27 private EventStreamTransformation mNext; 28 private AccessibilityManagerService mAms; 29 30 public KeyboardInterceptor(AccessibilityManagerService service) { 31 mAms = service; 32 } 33 34 @Override 35 public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) { 36 if (mNext != null) { 37 mNext.onMotionEvent(event, rawEvent, policyFlags); 38 } 39 } 40 41 @Override 42 public void onKeyEvent(KeyEvent event, int policyFlags) { 43 mAms.notifyKeyEvent(event, policyFlags); 44 } 45 46 @Override 47 public void onAccessibilityEvent(AccessibilityEvent event) { 48 if (mNext != null) { 49 mNext.onAccessibilityEvent(event); 50 } 51 } 52 53 @Override 54 public void setNext(EventStreamTransformation next) { 55 mNext = next; 56 } 57 58 @Override 59 public void clearEvents(int inputSource) { 60 if (mNext != null) { 61 mNext.clearEvents(inputSource); 62 } 63 } 64 65 @Override 66 public void onDestroy() { 67 } 68} 69