{"id":1771,"date":"2022-08-30T15:19:18","date_gmt":"2022-08-30T15:19:18","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/window-manager-crash-on-dispatching-down-key-on-samsung-galaxy-s-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:19:18","modified_gmt":"2022-08-30T15:19:18","slug":"window-manager-crash-on-dispatching-down-key-on-samsung-galaxy-s-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/window-manager-crash-on-dispatching-down-key-on-samsung-galaxy-s-collection-of-common-programming-errors\/","title":{"rendered":"&ldquo;Window Manager Crash&rdquo; on dispatching &#39;Down&#39; key on Samsung Galaxy S-Collection of common programming errors"},"content":{"rendered":"<p>\nI am running my Unit tests on various android devices using Instrumentation . Testcases works fine on emulator &amp; all devices except <b>Samsung Galaxy S<\/b>. On Samsung Galaxy S it displays a <b>Window Manager crash after injecting some 30 key events<\/b> using instrumentation here is the complete crash log:<\/p>\n<pre><code>D\/dalvikvm(11862): GC_EXPLICIT freed 6800 objects \/ 374040 bytes in 54ms\nD\/dalvikvm(11862): GC_EXPLICIT freed 780 objects \/ 71856 bytes in 39ms\nW\/dalvikvm(11862): threadid=9: thread exiting with uncaught exception (group=0x4001d7d0)\nE\/WindowManager( 2472): Window Manager Crash\nE\/WindowManager( 2472): java.lang.NullPointerException\nE\/WindowManager( 2472):         at com.android.server.WindowManagerService$KeyWaiter.waitForNextEventTarget(WindowManagerService.java:5844)\nE\/WindowManager( 2472):         at com.android.server.WindowManagerService.injectKeyEvent(WindowManagerService.java:5565)\nE\/WindowManager( 2472):         at android.view.IWindowManager$Stub.onTransact(IWindowManager.java:110)\nE\/WindowManager( 2472):         at com.android.server.WindowManagerService.onTransact(WindowManagerService.java:692)\nE\/WindowManager( 2472):         at android.os.Binder.execTransact(Binder.java:288)\nE\/WindowManager( 2472):         at dalvik.system.NativeStart.run(Native Method)\nE\/AndroidRuntime(11862): FATAL EXCEPTION: Instr: com.myapp.test.ImpInstrumentation\nE\/AndroidRuntime(11862): java.lang.NullPointerException\nE\/AndroidRuntime(11862):        at android.os.Parcel.readException(Parcel.java:1266)\nE\/AndroidRuntime(11862):        at android.os.Parcel.readException(Parcel.java:1248)\nE\/AndroidRuntime(11862):        at android.view.IWindowManager$Stub$Proxy.injectKeyEvent(IWindowManager.java:830)\nE\/AndroidRuntime(11862):        at android.app.Instrumentation.sendKeySync(Instrumentation.java:859)\nE\/AndroidRuntime(11862):        at android.app.Instrumentation.sendKeyDownUpSync(Instrumentation.java:872)\nE\/AndroidRuntime(11862):        at com.myapp.test.util.ListUtil.<b>arrowDownToPosition<\/b>(ListUtil.java:69)\n<\/code><\/pre>\n<p>And here is the piece of code where it generally crashes:<\/p>\n<pre><code>    private void arrowDownToPosition(int position) {\n          int maxDowns = 50;\n        while(mListView.getSelectedItemPosition() &lt; position &amp;&amp; --maxDowns &gt; 0) {\n             mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);\n        }\n\n\/\/Crashes on below line dispatching enter key\n      mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_ENTER);\n    }\n<\/code><\/pre>\n<p>All solutions\/suggestions are welcome.<\/p>\n<ol>\n<li>\n<p>Not sure if this helps, but while briefly researching this issue, I found this source. Have a look, particularly from line 175 about a bug with DPAD_CENTER on the Galaxy S, and how the issue is resolved.<\/p>\n<\/li>\n<li>\n<p>according to your stacktrace it seems that your variable <code>mInstrumentation<\/code> is null. did you forget to initialize it?<\/p>\n<p>try this:<\/p>\n<pre><code>while(mInstrumentation!=null &amp;&amp; mListView.getSelectedItemPosition()&gt;-1) {\n    mInstrumentation.sendKeyDownUpSync(KeyEvent.KEYCODE_DPAD_DOWN);\n}\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-12-02 01:20:58. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am running my Unit tests on various android devices using Instrumentation . Testcases works fine on emulator &amp; all devices except Samsung Galaxy S. On Samsung Galaxy S it displays a Window Manager crash after injecting some 30 key events using instrumentation here is the complete crash log: D\/dalvikvm(11862): GC_EXPLICIT freed 6800 objects \/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1771","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1771","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1771"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1771\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1771"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1771"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1771"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}