Huaweiの端末はAndroidアプリのログを握り潰す

Adding Voice Capabilities | Android Developersにしたがって、RecognizerIntentを使った音声認識のコードを書いていたのだが、音声認識画面(下画像)でBackボタンを押すとアプリが落ちるという問題が発生した。
f:id:sle:20180226005755p:plain
Android StudioのLogcatを見ても、主要なメッセージは

02-26 00:59:56.197 24384-24384/com.example.ashia.speechwithoutintent I/HwSecImmHelper: mSecurityInputMethodService is null
(中略)
02-26 00:59:56.292 24384-24384/com.example.ashia.speechwithoutintent I/Process: Sending signal. PID: 24384 SIG: 9

しか出てこず、例外が発生したようではない。はじめは、音声認識画面のBackがメインのActivityまで伝わってしまってプログラムが終了するのだと思ってBackの信号を握り潰すなどをやってみがたどうにも解決しない。


しばらく(5時間ぐらい)、ぐぐったり飽きてゲームをしたりしていたのだが、最後にこのような記事を見つけた:
https://stackoverflow.com/questions/38587844/msecurityinputmethodservice-is-null-in-logcat
曰く、

For my Huawei device the following helps:

Dial:

#*#2846579#*#*

and a hidden menu is shown. Go to "Background Setting" -> "Log setting" and enable the log levels.

ということで、デフォルトではHuaweiの端末では、ある程度のログレベル以下のログは握り潰されてしまうらしい。ここにあるように、
電話アプリを起動して「*#*#2846579#*#*」と打つと、以下のような画面がでる。ちなみに、打ち間違えてバックスペースで消して打つと出ないような気がするので、一発で打つ必要があると思う。
f:id:sle:20180226010644p:plain
この上で、「Background Setting」→「Log setting」と入ると、チェックボックスが4つぐらい出てくるのですべてにチェックを入れる。「This might affect the performance!」みたいなことを言われるが、まあ覚悟の上である(必要ならあとで外したほうがいいかも)。

これでデバッグ実行をしてみると、

02-26 00:59:56.265 24384-24384/com.example.ashia.speechwithoutintent E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ashia.speechwithoutintent, PID: 24384
kotlin.NotImplementedError: An operation is not implemented: not implemented
at com.example.ashia.speechwithoutintent.MainActivity$M.onError(MainActivity.kt:44)
at android.speech.SpeechRecognizer$InternalListener$1.handleMessage(SpeechRecognizer.java:450)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5621)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)

のように新たにエラーメッセージを得ることができて、ちゃんと例外が起こっているということがわかるようになった。