AccessibilityInputFilter.java revision 736c2756bf3c14ae9fef7255c119057f7a2be1ed
10029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown/* 20029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * Copyright (C) 2011 The Android Open Source Project 30029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * 40029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * Licensed under the Apache License, Version 2.0 (the "License"); 50029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * you may not use this file except in compliance with the License. 60029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * You may obtain a copy of the License at 70029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * 80029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * http://www.apache.org/licenses/LICENSE-2.0 90029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * 100029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * Unless required by applicable law or agreed to in writing, software 110029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * distributed under the License is distributed on an "AS IS" BASIS, 120029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * See the License for the specific language governing permissions and 140029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * limitations under the License. 150029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown */ 160029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 170029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownpackage com.android.server.accessibility; 180029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 190029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport com.android.server.wm.InputFilter; 200029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 210029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport android.content.Context; 220029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport android.util.Slog; 23736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganovimport android.view.InputDevice; 240029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport android.view.InputEvent; 250029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport android.view.MotionEvent; 260029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownimport android.view.WindowManagerPolicy; 270029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 280029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown/** 290029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * Input filter for accessibility. 300029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * 310029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown * Currently just a stub but will eventually implement touch exploration, etc. 320029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown */ 330029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brownpublic class AccessibilityInputFilter extends InputFilter { 340029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown private static final String TAG = "AccessibilityInputFilter"; 35736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov private static final boolean DEBUG = false; 360029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 370029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown private final Context mContext; 380029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 39736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov /** 40736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * This is an interface for explorers that take a {@link MotionEvent} 41736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * stream and perform touch exploration of the screen content. 42736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov */ 43736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov public interface Explorer { 44736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov /** 45736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * Handles a {@link MotionEvent}. 46736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * 47736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * @param event The event to handle. 48736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * @param policyFlags The policy flags associated with the event. 49736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov */ 50736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov public void onMotionEvent(MotionEvent event, int policyFlags); 51736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov 52736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov /** 53736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * Requests that the explorer clears its internal state. 54736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * 55736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * @param event The last received event. 56736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov * @param policyFlags The policy flags associated with the event. 57736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov */ 58736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov public void clear(MotionEvent event, int policyFlags); 59736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov } 60736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov 61736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov private TouchExplorer mTouchExplorer; 62736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov private int mTouchscreenSourceDeviceId; 63736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov 640029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown public AccessibilityInputFilter(Context context) { 650029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown super(context.getMainLooper()); 660029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown mContext = context; 670029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 680029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 690029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown @Override 700029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown public void onInstalled() { 710029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown if (DEBUG) { 720029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown Slog.d(TAG, "Accessibility input filter installed."); 730029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 740029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown super.onInstalled(); 750029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 760029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 770029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown @Override 780029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown public void onUninstalled() { 790029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown if (DEBUG) { 800029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown Slog.d(TAG, "Accessibility input filter uninstalled."); 810029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 820029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown super.onUninstalled(); 830029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 840029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown 850029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown @Override 860029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown public void onInputEvent(InputEvent event, int policyFlags) { 870029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown if (DEBUG) { 88736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov Slog.d(TAG, "Received event: " + event + ", policyFlags=0x" 89736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov + Integer.toHexString(policyFlags)); 900029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 91736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov if (event.getSource() == InputDevice.SOURCE_TOUCHSCREEN) { 92736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov MotionEvent motionEvent = (MotionEvent) event; 93736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov int deviceId = event.getDeviceId(); 94736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov if (mTouchscreenSourceDeviceId != deviceId) { 95736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov mTouchscreenSourceDeviceId = deviceId; 96736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov if (mTouchExplorer != null) { 97736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov mTouchExplorer.clear(motionEvent, policyFlags); 98736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov } else { 99736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov mTouchExplorer = new TouchExplorer(this, mContext); 1000029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 1010029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 102736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov if ((policyFlags & WindowManagerPolicy.FLAG_PASS_TO_USER) != 0) { 103736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov mTouchExplorer.onMotionEvent(motionEvent, policyFlags); 104736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov } else { 105736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov mTouchExplorer.clear(motionEvent, policyFlags); 106736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov } 107736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov } else { 108736c2756bf3c14ae9fef7255c119057f7a2be1edSvetoslav Ganov super.onInputEvent(event, policyFlags); 1090029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 1100029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown } 1110029c66203ab9ded4342976bf7a17bb63af8c44aJeff Brown} 112