diff options
Diffstat (limited to 'services')
6 files changed, 105 insertions, 339 deletions
diff --git a/services/java/com/android/server/accessibility/AccessibilityInputFilter.java b/services/java/com/android/server/accessibility/AccessibilityInputFilter.java index 8fa6722..fc774d4 100644 --- a/services/java/com/android/server/accessibility/AccessibilityInputFilter.java +++ b/services/java/com/android/server/accessibility/AccessibilityInputFilter.java @@ -16,13 +16,12 @@ package com.android.server.accessibility; -import com.android.server.input.InputFilter; - import android.content.Context; import android.os.PowerManager; import android.util.Slog; import android.view.InputDevice; import android.view.InputEvent; +import android.view.InputFilter; import android.view.MotionEvent; import android.view.WindowManagerPolicy; import android.view.accessibility.AccessibilityEvent; diff --git a/services/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/java/com/android/server/accessibility/AccessibilityManagerService.java index 5650da8..857334e 100644 --- a/services/java/com/android/server/accessibility/AccessibilityManagerService.java +++ b/services/java/com/android/server/accessibility/AccessibilityManagerService.java @@ -58,6 +58,7 @@ import android.text.TextUtils.SimpleStringSplitter; import android.util.Slog; import android.util.SparseArray; import android.view.IWindow; +import android.view.IWindowManager; import android.view.InputDevice; import android.view.KeyCharacterMap; import android.view.KeyEvent; @@ -74,7 +75,6 @@ import android.view.accessibility.IAccessibilityManagerClient; import com.android.internal.R; import com.android.internal.content.PackageMonitor; import com.android.internal.statusbar.IStatusBarService; -import com.android.server.wm.WindowManagerService; import org.xmlpull.v1.XmlPullParserException; @@ -157,7 +157,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private boolean mIsTouchExplorationEnabled; - private final WindowManagerService mWindowManagerService; + private final IWindowManager mWindowManager; private final SecurityPolicy mSecurityPolicy; @@ -181,8 +181,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { public AccessibilityManagerService(Context context) { mContext = context; mPackageManager = mContext.getPackageManager(); - mWindowManagerService = (WindowManagerService) ServiceManager.getService( - Context.WINDOW_SERVICE); + mWindowManager = (IWindowManager) ServiceManager.getService(Context.WINDOW_SERVICE); mSecurityPolicy = new SecurityPolicy(); mMainHandler = new MainHanler(); registerPackageChangeAndBootCompletedBroadcastReceiver(); @@ -583,15 +582,21 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { * * @param outBounds The output to which to write the bounds. */ - void getActiveWindowBounds(Rect outBounds) { + boolean getActiveWindowBounds(Rect outBounds) { synchronized (mLock) { final int windowId = mSecurityPolicy.mActiveWindowId; IBinder token = mWindowIdToWindowTokenMap.get(windowId); - mWindowManagerService.getWindowFrame(token, outBounds); + try { + mWindowManager.getWindowFrame(token, outBounds); + return true; + } catch (RemoteException re) { + /* ignore */ + } + return false; } } - int getActiveWindowId() { + public int getActiveWindowId() { return mSecurityPolicy.mActiveWindowId; } @@ -966,13 +971,21 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { if (mInputFilter == null) { mInputFilter = new AccessibilityInputFilter(mContext, this); } - mWindowManagerService.setInputFilter(mInputFilter); + try { + mWindowManager.setInputFilter(mInputFilter); + } catch (RemoteException re) { + /* ignore */ + } } return; } if (mHasInputFilter) { mHasInputFilter = false; - mWindowManagerService.setInputFilter(null); + try { + mWindowManager.setInputFilter(null); + } catch (RemoteException re) { + /* ignore */ + } } } @@ -1347,8 +1360,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) throws RemoteException { final int resolvedWindowId = resolveAccessibilityWindowId(accessibilityWindowId); - final int windowLeft; - final int windowTop; IAccessibilityInteractionConnection connection = null; synchronized (mLock) { mSecurityPolicy.enforceCanRetrieveWindowContent(this); @@ -1361,10 +1372,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return 0; } } - IBinder token = mWindowIdToWindowTokenMap.get(resolvedWindowId); - mWindowManagerService.getWindowFrame(token, mTempBounds); - windowLeft = mTempBounds.left; - windowTop = mTempBounds.top; } final int flags = (mIncludeNotImportantViews) ? AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS : 0; @@ -1372,8 +1379,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { final long identityToken = Binder.clearCallingIdentity(); try { connection.findAccessibilityNodeInfoByViewId(accessibilityNodeId, viewId, - windowLeft, windowTop, interactionId, callback, flags, interrogatingPid, - interrogatingTid); + interactionId, callback, flags, interrogatingPid, interrogatingTid); + return getCompatibilityScale(resolvedWindowId); } catch (RemoteException re) { if (DEBUG) { Slog.e(LOG_TAG, "Error findAccessibilityNodeInfoByViewId()."); @@ -1381,7 +1388,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } finally { Binder.restoreCallingIdentity(identityToken); } - return getCompatibilityScale(resolvedWindowId); + return 0; } @Override @@ -1390,8 +1397,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) throws RemoteException { final int resolvedWindowId = resolveAccessibilityWindowId(accessibilityWindowId); - final int windowLeft; - final int windowTop; IAccessibilityInteractionConnection connection = null; synchronized (mLock) { mSecurityPolicy.enforceCanRetrieveWindowContent(this); @@ -1405,19 +1410,16 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return 0; } } - IBinder token = mWindowIdToWindowTokenMap.get(resolvedWindowId); - mWindowManagerService.getWindowFrame(token, mTempBounds); - windowLeft = mTempBounds.left; - windowTop = mTempBounds.top; } final int flags = (mIncludeNotImportantViews) ? AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS : 0; final int interrogatingPid = Binder.getCallingPid(); final long identityToken = Binder.clearCallingIdentity(); try { - connection.findAccessibilityNodeInfosByText(accessibilityNodeId, text, windowLeft, - windowTop, interactionId, callback, flags, interrogatingPid, + connection.findAccessibilityNodeInfosByText(accessibilityNodeId, text, + interactionId, callback, flags, interrogatingPid, interrogatingTid); + return getCompatibilityScale(resolvedWindowId); } catch (RemoteException re) { if (DEBUG) { Slog.e(LOG_TAG, "Error calling findAccessibilityNodeInfosByText()"); @@ -1425,7 +1427,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } finally { Binder.restoreCallingIdentity(identityToken); } - return getCompatibilityScale(resolvedWindowId); + return 0; } @Override @@ -1434,8 +1436,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { IAccessibilityInteractionConnectionCallback callback, int flags, long interrogatingTid) throws RemoteException { final int resolvedWindowId = resolveAccessibilityWindowId(accessibilityWindowId); - final int windowLeft; - final int windowTop; IAccessibilityInteractionConnection connection = null; synchronized (mLock) { mSecurityPolicy.enforceCanRetrieveWindowContent(this); @@ -1449,10 +1449,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return 0; } } - IBinder token = mWindowIdToWindowTokenMap.get(resolvedWindowId); - mWindowManagerService.getWindowFrame(token, mTempBounds); - windowLeft = mTempBounds.left; - windowTop = mTempBounds.top; } final int allFlags = flags | ((mIncludeNotImportantViews) ? AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS : 0); @@ -1460,8 +1456,8 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { final long identityToken = Binder.clearCallingIdentity(); try { connection.findAccessibilityNodeInfoByAccessibilityId(accessibilityNodeId, - windowLeft, windowTop, interactionId, callback, allFlags, interrogatingPid, - interrogatingTid); + interactionId, callback, allFlags, interrogatingPid, interrogatingTid); + return getCompatibilityScale(resolvedWindowId); } catch (RemoteException re) { if (DEBUG) { Slog.e(LOG_TAG, "Error calling findAccessibilityNodeInfoByAccessibilityId()"); @@ -1469,7 +1465,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } finally { Binder.restoreCallingIdentity(identityToken); } - return getCompatibilityScale(resolvedWindowId); + return 0; } @Override @@ -1478,8 +1474,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) throws RemoteException { final int resolvedWindowId = resolveAccessibilityWindowId(accessibilityWindowId); - final int windowLeft; - final int windowTop; IAccessibilityInteractionConnection connection = null; synchronized (mLock) { mSecurityPolicy.enforceCanRetrieveWindowContent(this); @@ -1493,18 +1487,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return 0; } } - IBinder token = mWindowIdToWindowTokenMap.get(resolvedWindowId); - mWindowManagerService.getWindowFrame(token, mTempBounds); - windowLeft = mTempBounds.left; - windowTop = mTempBounds.top; } final int flags = (mIncludeNotImportantViews) ? AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS : 0; final int interrogatingPid = Binder.getCallingPid(); final long identityToken = Binder.clearCallingIdentity(); try { - connection.findFocus(accessibilityNodeId, focusType, windowLeft, windowTop, - interactionId, callback, flags, interrogatingPid, interrogatingTid); + connection.findFocus(accessibilityNodeId, focusType, interactionId, callback, + flags, interrogatingPid, interrogatingTid); + return getCompatibilityScale(resolvedWindowId); } catch (RemoteException re) { if (DEBUG) { Slog.e(LOG_TAG, "Error calling findAccessibilityFocus()"); @@ -1512,7 +1503,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } finally { Binder.restoreCallingIdentity(identityToken); } - return getCompatibilityScale(resolvedWindowId); + return 0; } @Override @@ -1521,8 +1512,6 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { IAccessibilityInteractionConnectionCallback callback, long interrogatingTid) throws RemoteException { final int resolvedWindowId = resolveAccessibilityWindowId(accessibilityWindowId); - final int windowLeft; - final int windowTop; IAccessibilityInteractionConnection connection = null; synchronized (mLock) { mSecurityPolicy.enforceCanRetrieveWindowContent(this); @@ -1536,18 +1525,15 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { return 0; } } - IBinder token = mWindowIdToWindowTokenMap.get(resolvedWindowId); - mWindowManagerService.getWindowFrame(token, mTempBounds); - windowLeft = mTempBounds.left; - windowTop = mTempBounds.top; } final int flags = (mIncludeNotImportantViews) ? AccessibilityNodeInfo.INCLUDE_NOT_IMPORTANT_VIEWS : 0; final int interrogatingPid = Binder.getCallingPid(); final long identityToken = Binder.clearCallingIdentity(); try { - connection.focusSearch(accessibilityNodeId, direction, windowLeft, windowTop, - interactionId, callback, flags, interrogatingPid, interrogatingTid); + connection.focusSearch(accessibilityNodeId, direction, interactionId, callback, + flags, interrogatingPid, interrogatingTid); + return getCompatibilityScale(resolvedWindowId); } catch (RemoteException re) { if (DEBUG) { Slog.e(LOG_TAG, "Error calling accessibilityFocusSearch()"); @@ -1555,7 +1541,7 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } finally { Binder.restoreCallingIdentity(identityToken); } - return getCompatibilityScale(resolvedWindowId); + return 0; } @Override @@ -1833,7 +1819,12 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { private float getCompatibilityScale(int windowId) { IBinder windowToken = mWindowIdToWindowTokenMap.get(windowId); - return mWindowManagerService.getWindowCompatibilityScale(windowToken); + try { + return mWindowManager.getWindowCompatibilityScale(windowToken); + } catch (RemoteException re) { + /* ignore */ + } + return 1.0f; } } @@ -1952,18 +1943,25 @@ public class AccessibilityManagerService extends IAccessibilityManager.Stub { } private int getFocusedWindowId() { - // We call this only on window focus change or after touch - // exploration gesture end and the shown windows are not that - // many, so the linear look up is just fine. - IBinder token = mWindowManagerService.getFocusedWindowClientToken(); - if (token != null) { - SparseArray<IBinder> windows = mWindowIdToWindowTokenMap; - final int windowCount = windows.size(); - for (int i = 0; i < windowCount; i++) { - if (windows.valueAt(i) == token) { - return windows.keyAt(i); + final long identity = Binder.clearCallingIdentity(); + try { + // We call this only on window focus change or after touch + // exploration gesture end and the shown windows are not that + // many, so the linear look up is just fine. + IBinder token = mWindowManager.getFocusedWindowToken(); + if (token != null) { + SparseArray<IBinder> windows = mWindowIdToWindowTokenMap; + final int windowCount = windows.size(); + for (int i = 0; i < windowCount; i++) { + if (windows.valueAt(i) == token) { + return windows.keyAt(i); + } } } + } catch (RemoteException re) { + /* ignore */ + } finally { + Binder.restoreCallingIdentity(identity); } return -1; } diff --git a/services/java/com/android/server/accessibility/TouchExplorer.java b/services/java/com/android/server/accessibility/TouchExplorer.java index 48c6b2a..ba9f2cd 100644 --- a/services/java/com/android/server/accessibility/TouchExplorer.java +++ b/services/java/com/android/server/accessibility/TouchExplorer.java @@ -28,6 +28,7 @@ import android.graphics.Rect; import android.os.Handler; import android.os.SystemClock; import android.util.Slog; +import android.view.InputFilter; import android.view.MotionEvent; import android.view.MotionEvent.PointerCoords; import android.view.MotionEvent.PointerProperties; @@ -37,7 +38,6 @@ import android.view.WindowManagerPolicy; import android.view.accessibility.AccessibilityEvent; import com.android.internal.R; -import com.android.server.input.InputFilter; import java.util.ArrayList; import java.util.Arrays; diff --git a/services/java/com/android/server/input/InputFilter.java b/services/java/com/android/server/input/InputFilter.java deleted file mode 100644 index 2ce0a02..0000000 --- a/services/java/com/android/server/input/InputFilter.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.server.input; - -import com.android.server.wm.WindowManagerService; - -import android.os.Handler; -import android.os.Looper; -import android.os.Message; -import android.view.InputEvent; -import android.view.InputEventConsistencyVerifier; -import android.view.KeyEvent; -import android.view.MotionEvent; -import android.view.WindowManagerPolicy; - -/** - * Filters input events before they are dispatched to the system. - * <p> - * At most one input filter can be installed by calling - * {@link WindowManagerService#setInputFilter}. When an input filter is installed, the - * system's behavior changes as follows: - * <ul> - * <li>Input events are first delivered to the {@link WindowManagerPolicy} - * interception methods before queuing as usual. This critical step takes care of managing - * the power state of the device and handling wake keys.</li> - * <li>Input events are then asynchronously delivered to the input filter's - * {@link #onInputEvent(InputEvent)} method instead of being enqueued for dispatch to - * applications as usual. The input filter only receives input events that were - * generated by input device; the input filter will not receive input events that were - * injected into the system by other means, such as by instrumentation.</li> - * <li>The input filter processes and optionally transforms the stream of events. For example, - * it may transform a sequence of motion events representing an accessibility gesture into - * a different sequence of motion events, key presses or other system-level interactions. - * The input filter can send events to be dispatched by calling - * {@link #sendInputEvent(InputEvent)} and passing appropriate policy flags for the - * input event.</li> - * </ul> - * </p> - * <h3>The importance of input event consistency</h3> - * <p> - * The input filter mechanism is very low-level. At a minimum, it needs to ensure that it - * sends an internally consistent stream of input events to the dispatcher. There are - * very important invariants to be maintained. - * </p><p> - * For example, if a key down is sent, a corresponding key up should also be sent eventually. - * Likewise, for touch events, each pointer must individually go down with - * {@link MotionEvent#ACTION_DOWN} or {@link MotionEvent#ACTION_POINTER_DOWN} and then - * individually go up with {@link MotionEvent#ACTION_POINTER_UP} or {@link MotionEvent#ACTION_UP} - * and the sequence of pointer ids used must be consistent throughout the gesture. - * </p><p> - * Sometimes a filter may wish to cancel a previously dispatched key or motion. It should - * use {@link KeyEvent#FLAG_CANCELED} or {@link MotionEvent#ACTION_CANCEL} accordingly. - * </p><p> - * The input filter must take into account the fact that the input events coming from different - * devices or even different sources all consist of distinct streams of input. - * Use {@link InputEvent#getDeviceId()} and {@link InputEvent#getSource()} to identify - * the source of the event and its semantics. There are be multiple sources of keys, - * touches and other input: they must be kept separate. - * </p> - * <h3>Policy flags</h3> - * <p> - * Input events received from the dispatcher and sent to the dispatcher have policy flags - * associated with them. Policy flags control some functions of the dispatcher. - * </p><p> - * The early policy interception decides whether an input event should be delivered - * to applications or dropped. The policy indicates its decision by setting the - * {@link WindowManagerPolicy#FLAG_PASS_TO_USER} policy flag. The input filter may - * sometimes receive events that do not have this flag set. It should take note of - * the fact that the policy intends to drop the event, clean up its state, and - * then send appropriate cancellation events to the dispatcher if needed. - * </p><p> - * For example, suppose the input filter is processing a gesture and one of the touch events - * it receives does not have the {@link WindowManagerPolicy#FLAG_PASS_TO_USER} flag set. - * The input filter should clear its internal state about the gesture and then send key or - * motion events to the dispatcher to cancel any keys or pointers that are down. - * </p><p> - * Corollary: Events that set sent to the dispatcher should usually include the - * {@link WindowManagerPolicy#FLAG_PASS_TO_USER} flag. Otherwise, they will be dropped! - * </p><p> - * It may be prudent to disable automatic key repeating for synthetic key events - * by setting the {@link WindowManagerPolicy#FLAG_DISABLE_KEY_REPEAT} policy flag. - * </p> - */ -public abstract class InputFilter { - private static final int MSG_INSTALL = 1; - private static final int MSG_UNINSTALL = 2; - private static final int MSG_INPUT_EVENT = 3; - - private final H mH; - private Host mHost; - - // Consistency verifiers for debugging purposes. - private final InputEventConsistencyVerifier mInboundInputEventConsistencyVerifier = - InputEventConsistencyVerifier.isInstrumentationEnabled() ? - new InputEventConsistencyVerifier(this, - InputEventConsistencyVerifier.FLAG_RAW_DEVICE_INPUT, - "InputFilter#InboundInputEventConsistencyVerifier") : null; - private final InputEventConsistencyVerifier mOutboundInputEventConsistencyVerifier = - InputEventConsistencyVerifier.isInstrumentationEnabled() ? - new InputEventConsistencyVerifier(this, - InputEventConsistencyVerifier.FLAG_RAW_DEVICE_INPUT, - "InputFilter#OutboundInputEventConsistencyVerifier") : null; - - /** - * Creates the input filter. - * - * @param looper The looper to run callbacks on. - */ - public InputFilter(Looper looper) { - mH = new H(looper); - } - - /** - * Called when the input filter is installed. - * This method is guaranteed to be non-reentrant. - * - * @param host The input filter host environment. - */ - final void install(Host host) { - mH.obtainMessage(MSG_INSTALL, host).sendToTarget(); - } - - /** - * Called when the input filter is uninstalled. - * This method is guaranteed to be non-reentrant. - */ - final void uninstall() { - mH.obtainMessage(MSG_UNINSTALL).sendToTarget(); - } - - /** - * Called to enqueue the input event for filtering. - * The event will be recycled after the input filter processes it. - * This method is guaranteed to be non-reentrant. - * - * @param event The input event to enqueue. - */ - final void filterInputEvent(InputEvent event, int policyFlags) { - mH.obtainMessage(MSG_INPUT_EVENT, policyFlags, 0, event).sendToTarget(); - } - - /** - * Sends an input event to the dispatcher. - * - * @param event The input event to publish. - * @param policyFlags The input event policy flags. - */ - public void sendInputEvent(InputEvent event, int policyFlags) { - if (event == null) { - throw new IllegalArgumentException("event must not be null"); - } - if (mHost == null) { - throw new IllegalStateException("Cannot send input event because the input filter " + - "is not installed."); - } - if (mOutboundInputEventConsistencyVerifier != null) { - mOutboundInputEventConsistencyVerifier.onInputEvent(event, 0); - } - mHost.sendInputEvent(event, policyFlags); - } - - /** - * Called when an input event has been received from the dispatcher. - * <p> - * The default implementation sends the input event back to the dispatcher, unchanged. - * </p><p> - * The event will be recycled when this method returns. If you want to keep it around, - * make a copy! - * </p> - * - * @param event The input event that was received. - * @param policyFlags The input event policy flags. - */ - public void onInputEvent(InputEvent event, int policyFlags) { - sendInputEvent(event, policyFlags); - } - - /** - * Called when the filter is installed into the dispatch pipeline. - * <p> - * This method is called before the input filter receives any input events. - * The input filter should take this opportunity to prepare itself. - * </p> - */ - public void onInstalled() { - } - - /** - * Called when the filter is uninstalled from the dispatch pipeline. - * <p> - * This method is called after the input filter receives its last input event. - * The input filter should take this opportunity to clean up. - * </p> - */ - public void onUninstalled() { - } - - private final class H extends Handler { - public H(Looper looper) { - super(looper); - } - - @Override - public void handleMessage(Message msg) { - switch (msg.what) { - case MSG_INSTALL: - mHost = (Host)msg.obj; - if (mInboundInputEventConsistencyVerifier != null) { - mInboundInputEventConsistencyVerifier.reset(); - } - if (mOutboundInputEventConsistencyVerifier != null) { - mOutboundInputEventConsistencyVerifier.reset(); - } - onInstalled(); - break; - - case MSG_UNINSTALL: - try { - onUninstalled(); - } finally { - mHost = null; - } - break; - - case MSG_INPUT_EVENT: { - final InputEvent event = (InputEvent)msg.obj; - try { - if (mInboundInputEventConsistencyVerifier != null) { - mInboundInputEventConsistencyVerifier.onInputEvent(event, 0); - } - onInputEvent(event, msg.arg1); - } finally { - event.recycle(); - } - break; - } - } - } - } - - interface Host { - public void sendInputEvent(InputEvent event, int policyFlags); - } -} diff --git a/services/java/com/android/server/input/InputManagerService.java b/services/java/com/android/server/input/InputManagerService.java index bdd0aa4..e7afb1a 100644 --- a/services/java/com/android/server/input/InputManagerService.java +++ b/services/java/com/android/server/input/InputManagerService.java @@ -42,8 +42,8 @@ import android.content.res.Resources.NotFoundException; import android.content.res.TypedArray; import android.content.res.XmlResourceParser; import android.database.ContentObserver; -import android.hardware.input.IInputManager; import android.hardware.input.IInputDevicesChangedListener; +import android.hardware.input.IInputManager; import android.hardware.input.InputManager; import android.hardware.input.KeyboardLayout; import android.os.Binder; @@ -62,6 +62,8 @@ import android.util.Log; import android.util.Slog; import android.util.SparseArray; import android.util.Xml; +import android.view.IInputFilter; +import android.view.IInputFilterHost; import android.view.InputChannel; import android.view.InputDevice; import android.view.InputEvent; @@ -137,7 +139,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog. // State for the currently installed input filter. final Object mInputFilterLock = new Object(); - InputFilter mInputFilter; // guarded by mInputFilterLock + IInputFilter mInputFilter; // guarded by mInputFilterLock InputFilterHost mInputFilterHost; // guarded by mInputFilterLock private static native int nativeInit(InputManagerService service, @@ -425,9 +427,9 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog. * * @param filter The input filter, or null to remove the current filter. */ - public void setInputFilter(InputFilter filter) { + public void setInputFilter(IInputFilter filter) { synchronized (mInputFilterLock) { - final InputFilter oldFilter = mInputFilter; + final IInputFilter oldFilter = mInputFilter; if (oldFilter == filter) { return; // nothing to do } @@ -436,13 +438,21 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog. mInputFilter = null; mInputFilterHost.disconnectLocked(); mInputFilterHost = null; - oldFilter.uninstall(); + try { + oldFilter.uninstall(); + } catch (RemoteException re) { + /* ignore */ + } } if (filter != null) { mInputFilter = filter; mInputFilterHost = new InputFilterHost(); - filter.install(mInputFilterHost); + try { + filter.install(mInputFilterHost); + } catch (RemoteException re) { + /* ignore */ + } } nativeSetInputFilterEnabled(mPtr, filter != null); @@ -1229,7 +1239,11 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog. final boolean filterInputEvent(InputEvent event, int policyFlags) { synchronized (mInputFilterLock) { if (mInputFilter != null) { - mInputFilter.filterInputEvent(event, policyFlags); + try { + mInputFilter.filterInputEvent(event, policyFlags); + } catch (RemoteException e) { + /* ignore */ + } return false; } } @@ -1447,7 +1461,7 @@ public class InputManagerService extends IInputManager.Stub implements Watchdog. /** * Hosting interface for input filters to call back into the input manager. */ - private final class InputFilterHost implements InputFilter.Host { + private final class InputFilterHost extends IInputFilterHost.Stub { private boolean mDisconnected; public void disconnectLocked() { diff --git a/services/java/com/android/server/wm/WindowManagerService.java b/services/java/com/android/server/wm/WindowManagerService.java index 61e3560..2c7d36f 100755 --- a/services/java/com/android/server/wm/WindowManagerService.java +++ b/services/java/com/android/server/wm/WindowManagerService.java @@ -45,7 +45,6 @@ import com.android.server.AttributeCache; import com.android.server.EventLogTags; import com.android.server.Watchdog; import com.android.server.am.BatteryStatsService; -import com.android.server.input.InputFilter; import com.android.server.input.InputManagerService; import com.android.server.power.PowerManagerService; import com.android.server.power.ShutdownThread; @@ -107,6 +106,7 @@ import android.view.Choreographer; import android.view.Display; import android.view.Gravity; import android.view.IApplicationToken; +import android.view.IInputFilter; import android.view.IOnKeyguardExitResult; import android.view.IRotationWatcher; import android.view.IWindow; @@ -3069,6 +3069,10 @@ public class WindowManagerService extends IWindowManager.Stub } public float getWindowCompatibilityScale(IBinder windowToken) { + if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, + "getWindowCompatibilityScale()")) { + throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); + } synchronized (mWindowMap) { WindowState windowState = mWindowMap.get(windowToken); return (windowState != null) ? windowState.mGlobalScale : 1.0f; @@ -5190,7 +5194,10 @@ public class WindowManagerService extends IWindowManager.Stub ShutdownThread.rebootSafeMode(mContext, true); } - public void setInputFilter(InputFilter filter) { + public void setInputFilter(IInputFilter filter) { + if (!checkCallingPermission(android.Manifest.permission.FILTER_EVENTS, "setInputFilter()")) { + throw new SecurityException("Requires FILTER_EVENTS permission"); + } mInputManager.setInputFilter(filter); } @@ -6752,8 +6759,11 @@ public class WindowManagerService extends IWindowManager.Stub } } - // TODO: Put this on the IWindowManagerService and guard with a permission. - public IBinder getFocusedWindowClientToken() { + public IBinder getFocusedWindowToken() { + if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, + "getFocusedWindowToken()")) { + throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); + } synchronized (mWindowMap) { WindowState windowState = getFocusedWindowLocked(); if (windowState != null) { @@ -6763,8 +6773,11 @@ public class WindowManagerService extends IWindowManager.Stub } } - // TODO: This is a workaround - remove when 6623031 is fixed. public boolean getWindowFrame(IBinder token, Rect outBounds) { + if (!checkCallingPermission(android.Manifest.permission.RETRIEVE_WINDOW_INFO, + "getWindowFrame()")) { + throw new SecurityException("Requires RETRIEVE_WINDOW_INFO permission."); + } synchronized (mWindowMap) { WindowState windowState = mWindowMap.get(token); if (windowState != null) { |