title: Android alarm clock app crashes SystemUI with NullPointerException under Oreo (only)
body: <p>I have an Android alarm clock app. I have the usual(?) alarm Intent -> receiver -> activity chain, whose last step creates a full-screen window and sounds the alarm.</p>
  
  <p>All this works fine on pre-Oreo (API 26) versions of Android. But on Oreo, when the alarm fires, the System UI crashes and I get this exception in the emulator (slightly reformatted here):</p>
  
  <pre><code>        12-12 01:15:02.864 9570-9570/com.android.systemui E/AndroidRuntime: 
      FATAL EXCEPTION: main
  Process: com.android.systemui, PID: 9570
  java.lang.NullPointerException: Attempt to invoke virtual method 'void com.android.systemui.statusbar.phone.NavigationBarFragment.onKeyguardOccludedChanged(boolean)' on a null object reference
  at com.android.systemui.statusbar.phone.StatusBar.onKeyguardOccludedChanged(StatusBar.java:3843)
  at com.android.systemui.statusbar.phone.StatusBarKeyguardViewManager.setOccluded(StatusBarKeyguardViewManager.java:277)
  at com.android.systemui.keyguard.KeyguardViewMediator.handleSetOccluded(KeyguardViewMediator.java:1176)
  at com.android.systemui.keyguard.KeyguardViewMediator.-wrap14(Unknown Source:0)
  at com.android.systemui.keyguard.KeyguardViewMediator$4.handleMessage(KeyguardViewMediator.java:1531)
  at android.os.Handler.dispatchMessage(Handler.java:105)
  at android.os.Looper.loop(Looper.java:164)
  at android.app.ActivityThread.main(ActivityThread.java:6541)
  at java.lang.reflect.Method.invoke(Native Method)
  at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
  </code></pre>
  
  <p>As a possible clue, I've found that when I remove <code>WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED</code> from <code>win.addFlags()</code>, it doesn't crash -- but of course, it also doesn't show the alarm when the phone is locked.</p>
  
  <p>I don't remember everything I've tried, but here are some of the things:</p>
  
  <ol>
  <li>Locating Android's <code>StatusBar.java</code> source code to try to figure out exactly what thing is null that's not supposed to be. My Google-fu has failed me here, apparently.</li>
  <li>Explicitly dismissing the keyguard with something like <code>getSystemService(KeyguardManager.class).requestDismissKeyguard(this, null);</code>.</li>
  <li>Dismissing the keyguard by using <code>WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD</code>.</li>
  <li>Both explicitly showing and explicitly hiding the status bar.</li>
  <li>I think I tried some other method of showing the window when locked -- like, calling <code>setShowWhenLocked(true)</code> or something like that. But it didn't help, and anyway that method was added only in API 27, so it wouldn't solve the problem for API 26 even if it <em>had</em> worked.</li>
  <li>Um ... other things I no longer remember.</li>
  </ol>
  
  <p>None of these has had any effect.</p>
  
  <p>Clearly this <em>can</em> work, because other alarm clock apps work under Oreo. What am I doing wrong?</p>