Background
I'm investigating how to replace the UI of the dialer, when the user gets a phone call (incoming/outgoing phone calls).
This seems to be possible in 2 ways:
On old Android versions, it's possible by having an on top view that is triggered by PHONE_STATE_CHANGED and NEW_OUTGOING_CALL Intents.
On new Android versions (at least API 23 - Android M-6.0) , it's possible by extending InCallService, and provide an Activity that will be opened from there. I've even found an example to do it, here.
The problem
Looking at how the built in dialer works, if the user is using an app in immersive mode (a game or a YouTube video on landscape), and now the device is ringing (incoming call), there is a notification instead of a full screen Activity.
But I can't find how to do it using the API.
What I've tried
I've tried to look at all the docs of InCallService. I've also tried to see if I can differentiate between immersive and non-immersive, by checking the various values I get from WindowManager:
val wm = getSystemService(Service.WINDOW_SERVICE) as WindowManager
val display = wm.defaultDisplay
val metrics = DisplayMetrics()
display.getMetrics(metrics)
val realMetrics = DisplayMetrics()
display.getRealMetrics(realMetrics)
val realSize = Point()
display.getRealSize(realSize)
val size = Point()
display.getSize(size)
Log.d("AppLog", "mode:${display.mode} state:${display.state} size:$size realSize:$realSize metrics:$metrics realMetrics:$realMetrics rotation:${display.rotation}")
I guess it might be possible to check it using accessibility service (not sure how though), but this seems like too much to do for it.
The question
Is it possible for the app to check if the screen is now in immersive mode?
If it is possible, how, and from which Android version is it supported?
If it's not possible, how come the built in app knows how to check it?