Flag_secure doesn't work in Scrcpy program. Is there any other method other than flag_secure?

Viewed 1448

FLAG_SECURE prevents taking screen pictures and screen mirroring. But FLAG_SECURE doesn't prevent screen sharing over USB. I do screen sharing with scrcpy program. DEVELOPMENT_SETTINGS_ENABLED is not a sufficient solution. How can I prevent scrcpy from grabbing my screen? I have to do this on Android Studio. Is there any other method other than flag_secure?

2 Answers

But FLAG_SECURE doesn't prevent screen sharing over USB

I can reproduce the problem. I am somewhat surprised that this works.

I had forgotten the history behind all of this. Originally, scrcpy could not access secure windows. They found a workaround in 2019, and it appears that workaround is being blocked in Android 12.

How can I prevent scrcpy from grabbing my screen?

Your app could refuse to run if you detect that USB debugging is enabled. That will make development painful.

AFAIK, scrcpy works by installing and running an agent on the device that works on behalf of the desktop program. You might see if there are ways to detect that agent. This does not stop other attackers, though, from modifying scrcpy in ways that defeat your agent detection logic.

But there is no FLAG_SECURE_NO_REALLY_I_MEAN_IT_THIS_TIME flag for you to use instead of FLAG_SECURE. Nor is there something else for blocking screen access besides FLAG_SECURE that I am aware of.

I was facing the same issue, even after tried with FLAG_SECURE but the best option is to check if the developer option is enabled or not.

Please follow the below solution to check if the developer option is turned on or not.

  public static int devOptions(Context context) {
    int devOptions = Settings.Secure.getInt(context.getContentResolver(), Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0);
    return devOptions;
}

if the response is 1 then the developer option is turned on and you can ask the user to turned off first.

Happy Coding...

Related