アプリ開発備忘録

PlayStationMobile、Android、UWPの開発備忘録

画面のオーバーレイでシステムUIが落ちると思ったらアダプティブアイコンのせいだった

画面オーバーレイしようと思ったらシステムUIが落ちる。
今までオーバーレイは普通にやってたのに何故…と思ったらアダプティブアイコンのせいだったという話です。

はじまり

画面オーバーレイをしようと思ったらシステムUIが止まった。
LogcatでフィルターをNo filtersにして内容を見てみると以下の内容が出た。Bitmap?
よく見るとこの時点でNotificationとかAdaptiveIconDrawableとか書いてあるのにここで気づくべきだった。

Process: com.android.systemui, PID: 19931
    java.lang.IllegalArgumentException: width and height must be > 0
        at android.graphics.Bitmap.createBitmap(Bitmap.java:1010)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:977)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:927)
        at android.graphics.Bitmap.createBitmap(Bitmap.java:888)
        at android.graphics.drawable.AdaptiveIconDrawable.updateMaskBoundsInternal(AdaptiveIconDrawable.java:333)
        at android.graphics.drawable.AdaptiveIconDrawable.updateLayerBounds(AdaptiveIconDrawable.java:295)
        at android.graphics.drawable.AdaptiveIconDrawable.onStateChange(AdaptiveIconDrawable.java:782)
        at android.graphics.drawable.Drawable.setState(Drawable.java:775)
        at android.widget.ImageView.drawableStateChanged(ImageView.java:1305)
        at android.view.View.refreshDrawableState(View.java:20025)
        at android.view.View.dispatchAttachedToWindow(View.java:17422)
        at android.view.ViewGroup.addViewInner(ViewGroup.java:4955)
        at android.view.ViewGroup.addView(ViewGroup.java:4746)
        at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateIconsForLayout(NotificationIconAreaController.java:247)
        at com.android.systemui.statusbar.phone.NotificationIconAreaController.updateNotificationIcons(NotificationIconAreaController.java:155)
        at com.android.systemui.statusbar.phone.StatusBar.updateNotificationShade(StatusBar.java:2000)
        at com.android.systemui.statusbar.phone.StatusBar.updateNotifications(StatusBar.java:2188)
        at com.android.systemui.statusbar.phone.StatusBar.addNotificationViews(StatusBar.java:6833)
        at com.android.systemui.statusbar.phone.StatusBar.addEntry(StatusBar.java:1671)
        at com.android.systemui.statusbar.phone.StatusBar.onAsyncInflationFinished(StatusBar.java:1688)
        at com.android.systemui.statusbar.notification.NotificationInflater$AsyncInflationTask.onAsyncInflationFinished(NotificationInflater.java:641)
        at com.android.systemui.statusbar.notification.NotificationInflater.finishIfDone(NotificationInflater.java:460)
        at com.android.systemui.statusbar.notification.NotificationInflater.-wrap0(Unknown Source:0)
        at com.android.systemui.statusbar.notification.NotificationInflater$6.onViewApplied(NotificationInflater.java:343)
        at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3421)
        at android.widget.RemoteViews$AsyncApplyTask.onPostExecute(RemoteViews.java:3401)
        at android.os.AsyncTask.finish(AsyncTask.java:695)
        at android.os.AsyncTask.-wrap1(Unknown Source:0)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:712)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:251)
        at android.app.ActivityThread.main(ActivityThread.java:6589)
        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)

次にバージョンごとに調べてみるとAndroid 8.0だけで落ちる。
Android8.0で分岐しているのは「NotificationManager.createNotificationChannel」で通知のチャンネルを作っている部分である。条件分岐を「Build.VERSION_CODES.O_MR1」以降にしてみると落ちなくなったが通知が使えないので意味がない。

オーバーレイのせいだと思っていて時間が掛かってしまいましたがこれ通知のせいだと思い調べてみると以下がヒットしました。
java - Android Oreo Notification Crashes System UI - Stack Overflow

mipmapがうまく変換できてないようなのでDrawableに変えてくれということでした。別の案件でAdaptiveIconDrawableでも嵌められたしアダプティブアイコン勘弁してくれ。

おわりに

原因を調べるのにある程度の当たりをつけるのはいいけどそれが絶対だと思ってはいけない。
オーバーレイのせいだとずっと思っていたので判るのに時間がかかってしまった。

実はおそらくこれのせいで別の箇所でシステムUIが止まるということがあって色々問題が重なりすぎた…