How to programmatically detect if any screen recording process/app is running in Android?
Asked Answered
C

4

23

I don't want users to take screenshot or record screen of my app. I have added secure flag to the window. This prevents user from taking screenshots and recording screen.

If the screen recording is on, my app prevents the content from being recorded but the audio gets recorded.

On some rooted devices, the secure flags may not work as expected. So I just want to detect if any screen recording app/process is running in background so that I can hide sensitive data and prevent it from being recorded.

Is there any way I can detect if the screen recording is on?

Conversationalist answered 14/6, 2017 at 12:33 Comment(3)
there is no way, if you are talking about root. Using root, user can record everything on different layers up to the GPU output level. I'm sure that you can do nothing about it.Pentathlon
You need to have a list of popular and a not so popular recording apps in the market (make sure to grab the package name) because you are going to compare those packages in the current running process since Android does not know what is a recording app.Skim
Is there any solution to this problem? I try to create an application to detect sharing screens and screen recording, but DisplayManager can't work on some devices and I try to find another solution.Uremia
S
14

Is there any way I can detect if the screen recording is on?

No.

So I just want to detect if any screen recording app/process is running in background so that I can hide sensitive data and prevent it from being recorded.

Since screen recording does not require a recording-specific app or a process (e.g., adb shell screenrecord), and since you have no way of knowing particular apps or processes that are using the media projection API, this seems impractical. And, on modern versions of Android, you have no way of knowing what other processes are running, anyway. Plus, there is nothing stopping the user from pointing another camera at the device screen and recording its contents that way.

I don't want users to take screenshot or record screen of my app

Then do not write the app. The idea behind FLAG_SECURE is to help defend the user against third parties, not to defend the developer against the user.

Supertanker answered 14/6, 2017 at 13:8 Comment(3)
I'm fine with FLAG_SECURE, but it still records the audio. They should have prevented that tooSkyros
While everything about the answer is fine, your idea behind FLAG_SECURE seems wrong imo. There are many many use cases where developer might need to secure data from user like when offering data for only paid users which shouldn't be shared in between users via screenshotsRumpf
@Abbas: FLAG_SECURE was not designed as a DRM solution.Supertanker
M
1

The answer here is really just general for security. Once data flows to someone's device then you must assume that they can get full, unrestricted access to it. Everything else is in some sense just obfuscation. It is just making it a little more difficult at best. Even if the device's software provides some protection, the user has physical access to the device and can root it. At some point data has to be unencrypted and deobfuscated, so that it can be shown to the user and a malicious user can MITM that. If you want better security then it needs to be provided by the device via hardware. This was a big issue with movies being streamed to mobile devices at first. Device's needed a special hardware encrypted channel that decrypts to some ungodly amount of data per second making it difficult to write back to a disk if someone tried to MITM the unencrypted data on it's way to the screen.

Now the above is just to show that it is impossible to guarntee that you can control the data when it goes to a user's device. Instead, you should take a step back and ask what you are trying to accomplish? What type of behavior are you trying to prevent? If a small number of technically savvy users are able to workaround your protections, is that okay or a big deal? What is an acceptable rate of data "leaking". This really depends on how sensitive the data is and what type of guarantee you are telling users you have over it. This aspect is 100% the most critical part. If you are telling users that the data they sent is guaranteed to be ephemeral then that is impossible. Trying to build that and patch all the holes and play the whack a mole game is a losing battle. The only way to win is not to play.

Moravian answered 19/10, 2021 at 8:45 Comment(0)
F
0

As @CommonsWare said there is no way

of knowing particular apps or processes that are using the media projection API, this seems impractical.

However you can use the FLAG_SECURE like so.

getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE); 

as stated in the docs here.

Frontogenesis answered 21/10, 2021 at 12:31 Comment(1)
This mostly works very well, but i've gotten reports that a few brands, Huawei for example, seem to ignore this, and users are able to record anyway. I need to find a solution to this, because my app is used to display tickets, and some users are cheating by sharing screen-recordings of those. So far, I've found no solutions that works.Latoria
A
0

I think there is one way you detect screen recording on or off by DisplayManager.DisplayListener

Here is my code:

val listener = object : DisplayManager.DisplayListener {

        override fun onDisplayChanged(displayId: Int) {
               Log.d("test","1")
           //it detect something chnage in screen 
           //you can mute it from here

        }

        override fun onDisplayAdded(displayId: Int) {
         Log.d("test","2")
             //you can mute it to here from
             

        }

        override fun onDisplayRemoved(displayId: Int) {
                    Log.d("test","3")
                    //final here you can unMute it 
            }
    
Alnico answered 14/4, 2023 at 7:5 Comment(1)
This detects external monitors.Supertanker

© 2022 - 2024 — McMap. All rights reserved.