[Android General] AbrahamGC:
Secure flag - Snapchat fix - Pie

Well, after facebook fix, here is the snapchat version ... ;)

When we mod WindowManagerService (isSecureLocked method), to force it to return always false (0x0), Snapchat will ban our accounts, maybe not today, not tomorrow... in a week... but they ban us.

The workaround till now was make a toggle for the secure flag and not enabling it when using Snapchat. Is not a bad idea, but since we only need to disable the mod on Snapchat, let's automate it.

The logic is simple, detect current running app, if is snapchat, return the stock value, and if is not, return false, that's what allow us to use screenshots/captures on secure apps.

The source code for the method is HERE. Like always, thanks to my partner [MENTION=5829833]a.raul[/MENTION] .

How to implement it :

- Open services.jar/smali_classes2/com/android/server/wm/WindowManagerService.smali

- Add this under # instance fields :

.field private final DLX:Ljava/lang/Runnable;

.field private isSnapchat:Z

- Add these two methods under # direct methods :

.method static synthetic access$666(Lcom/android/server/wm/WindowManagerService;)Landroid/content/Context;
.registers 2
.param p0, "x0" # Lcom/android/server/wm/WindowManagerService;

.prologue
.line 14
iget-object v0, p0, Lcom/android/server/wm/WindowManagerService;->mContext:Landroid/content/Context;

return-object v0
.end method

.method static synthetic access$777(Lcom/android/server/wm/WindowManagerService;Z)Z
.registers 2
.param p0, "x0" # Lcom/android/server/wm/WindowManagerService;
.param p1, "x1" # Z

.prologue
.line 14
iput-boolean p1, p0, Lcom/android/server/wm/WindowManagerService;->isSnapchat:Z

return p1
.end method

- Find iput-object v12, v11, Lcom/android/server/wm/WindowManagerService;->mContext:Landroid/content/Context; and add :

const/4 v1, 0x0

iput-boolean v1, v11, Lcom/android/server/wm/WindowManagerService;->isSnapchat:Z

new-instance v1, Lcom/android/server/wm/WindowManagerService$DLX;

invoke-direct {v1, v11}, Lcom/android/server/wm/WindowManagerService$DLX;-><init>(Lcom/android/server/wm/WindowManagerService;)V

iput-object v1, v11, Lcom/android/server/wm/WindowManagerService;->DLX:Ljava/lang/Runnable;

And for finish, replace .method isSecureLocked(Lcom/android/server/wm/WindowState; )Z :

.method isSecureLocked(Lcom/android/server/wm/WindowState;)Z
.registers 5
.param p1, "windowState" # Lcom/android/server/wm/WindowState;

.prologue
const/4 v0, 0x0

.line 35
invoke-static {}, Landroid/os/Handler;->getMain()Landroid/os/Handler;

move-result-object v1

iget-object v2, p0, Lcom/android/server/wm/WindowManagerService;->DLX:Ljava/lang/Runnable;

invoke-virtual {v1, v2}, Landroid/os/Handler;->post(Ljava/lang/Runnable;)Z

.line 36
iget-boolean v1, p0, Lcom/android/server/wm/WindowManagerService;->isSnapchat:Z

if-nez v1, :cond_f

.line 39
:cond_e
:goto_e
return v0

:cond_f
iget-object v1, p1, Lcom/android/server/wm/WindowState;->mAttrs:Landroid/view/WindowManager$LayoutParams;

iget v1, v1, Landroid/view/WindowManager$LayoutParams;->flags:I

and-int/lit16 v1, v1, 0x2000

if-nez v1, :cond_30

invoke-static {}, Landroid/app/admin/DevicePolicyCache;->getInstance()Landroid/app/admin/DevicePolicyCache;

move-result-object v1

invoke-virtual {p1}, Ljava/lang/Object;->getClass()Ljava/lang/Class;

invoke-static {v0}, Landroid/os/UserHandle;->getUserId(I)I

move-result v2

invoke-virtual {v1, v2}, Landroid/app/admin/DevicePolicyCache;->getScreenCaptureDisabled(I)Z

move-result v1

if-nez v1, :cond_30

iget-object v1, p0, Lcom/android/server/wm/WindowManagerService;->mSamsungWindowManager:Lcom/android/server/wm/SamsungWindowManagerService;

invoke-virtual {v1, p1}, Lcom/android/server/wm/SamsungWindowManagerService;->isScreenCaptureDisabledLocked(Lcom/android/server/wm/WindowState;)Z

move-result v1

if-eqz v1, :cond_e

:cond_30
const/4 v0, 0x1

goto :goto_e
.end method

Copy the attached smali to the same path and done.

Enjoy :good:
​