The threat of someone hijacking your phone’s camera to spy on you is a concern, especially when privacy is at stake. So, Google has determined the issue, as folks at XDA discovered code submissions shows that Android P should prevent idle apps from using both the camera and microphone.
Android P Stops Apps From Hijacking Your Camera
If an inactive program tries to use the camera, Android P should shut it off and give you an error message. Coming to the microphone, it’s slightly different: it will allow recording but report empty data until the app is active.
Malware wouldn’t get away with recording in the background, but legitimate apps like a voice chat client, which stays active shouldn’t have an issue with it. Google hasn’t even announced Andriod P, so it could be a while before you hear about these measures in any formal capacity.
As spotted by XDA Developers, it looks like Android P will also block idle background apps from accessing the microphone. Needless to say, the possibility of an app recording users without their knowledge (granted permission) is a threat or say violation of privacy. There are some situations where you want an app to record audio in the background, there will be some way to allow this too.