OSDN Git Service

Keyboard Shortcuts: protect against NPE in WindowManagerService
authorAndrei Stingaceanu <stg@google.com>
Wed, 6 Apr 2016 13:48:33 +0000 (14:48 +0100)
committerAndrei Stingaceanu <stg@google.com>
Wed, 6 Apr 2016 13:55:07 +0000 (14:55 +0100)
Using an unresponsive app [while (true) { Thread.sleep(1000) }]
produces NPE:

WindowManager: Window Manager Crash
WindowManager: java.lang.NullPointerException: Attempt to read
               from field 'android.view.IWindow
               com.android.server.wm.WindowState.mClient' on a
               null object reference
WindowManager: at com.android.server.wm.WindowManagerService
               .requestAppKeyboardShortcuts
               (WindowManagerService.java:10628)

Which puts down SysUI (and requires restarting SysUI).

Protect against this by checking for nulls. The end result
is that the dialog is no longer shown for unresponsive apps
and SysUI does not break.

Bug: 27914463
Change-Id: I37f0b0d5980f6ddc50f3bb778582d23ee1c7e9c3

services/core/java/com/android/server/wm/WindowManagerService.java

index eba7818..08d9ddf 100644 (file)
@@ -10625,7 +10625,10 @@ public class WindowManagerService extends IWindowManager.Stub
     @Override
     public void requestAppKeyboardShortcuts(IResultReceiver receiver, int deviceId) {
         try {
-            getFocusedWindow().mClient.requestAppKeyboardShortcuts(receiver, deviceId);
+            WindowState focusedWindow = getFocusedWindow();
+            if (focusedWindow != null && focusedWindow.mClient != null) {
+                getFocusedWindow().mClient.requestAppKeyboardShortcuts(receiver, deviceId);
+            }
         } catch (RemoteException e) {
         }
     }