Android 12: Detect if user disables/enables camera and microphone
Asked Answered
M

1

5

With the new Android 12 operating system, the user now has the ability to completely disable microphone and camera usage from ALL apps. This is actually a good thing, letting users easily control privacy.

If an app starts and has permission to use the microphone and the camera AND the user has disabled all access to either of these hardware, Android 12 automatically pops up an alert asking the user to re-enable the microphone or camera, or to continue with the hardware disabled for the app.

Also, on creation, the app can simply check when starting to see if the needed hardware is enabled, and can also prompt the user further or handle the condition as the app sees fit.

But what if the user disables the microphone or camera while the app is running? I can't seem to find any interfaces for something like onMicrophoneEnabled() or even a Broadcast of such an event.

It's possible to check every time onResume() is called, but I was hoping there'd be a more elegant solution.

If anyone knows of something that my app can use to capture this when the user has made changes either way, please let me know.

Mosemoseley answered 25/4, 2022 at 22:38 Comment(4)
Usually, when a runtime permission is revoked, your process is terminated. Does that not happen for this related case?Hammack
The app continues running. But the microphone or the camera simply don't work. I'd like to be able to add an icon that tells the user that those devices have been disabled. Our app has lots of video chat modes, so it's really nice to know if your microphone or camera has been turned off.Mosemoseley
@Mosemoseley "If an app starts and has permission to use the microphone and the camera AND the user has disabled all access to either of these hardware, Android 12 automatically pops up an alert asking the user to re-enable the microphone or camera, or to continue with the hardware disabled for the app." - In my case somehow operating system is not showing this alert. Can you please suggest.Mieshamiett
@hemanthkumar To my knowledge the operating system shows this alert just once and then remembers the user's preference. There may be a way to delete this preference by clearing the cache/data for the app. I don't know a way to force this alert to show again. Anyone else out there know? I am not at a place to test this, but possibly calling requestPermissions() may cause the pop-up alert to go again?Mosemoseley
M
6

After carefully reading the google docs (https://developer.android.com/training/permissions/explaining-access#toggles) on their implementation of the user enable/disable of the camera and microphone I discovered something very interesting:

Apps are explicitly forbidden from knowing if the user has done any of these actions. So of course there is no way to get notified of these changes: it is by design.

If the user turns off the camera this way, the app will still get a camera feed, but it will be black. Similarly the microphone will still work, but we'll get only silence. This is a feature--a way to ensure privacy.

The operating system will remind users that they have disabled the microphone or camera and provide a chance to re-enable the hardware, which is nice. But the app is completely in the dark (hehe).

Another way to think of it: Just like putting a piece of tape over your camera or your thumb over the microphone. Only this time it's done by the operating system. This way a spy program or some other nefarious software will still think it's working and not try to bypass or give up.

This also explains why testing during onResume() or onWindowFocusChanged() didn't work either. I was getting results that didn't align with the settings (they aligned with current permissions).

So to answer my question: There is no way to be notified. That is the point.

Mosemoseley answered 29/4, 2022 at 13:1 Comment(1)
Yea, this is greatTempe

© 2022 - 2024 — McMap. All rights reserved.