Android Question is lock access to statusbar still possible in Android 8?

fransvlaarhoven

Active Member
Licensed User
Longtime User
i was blocking access to the status bar using the code

mlp.InitializeNewInstance("android.view.WindowManager$LayoutParams", Array(vtype, Height0, 2010,296, pixelFormat))

this code runs on devices with android 4 up to android 7.
However, trying to run the same code on devices running android 8.0 and 8.1 generates this error:

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@f3e70bc -- permission denied for window type 2010

As far as i can see, it is no longer allowed to draw over the status bar.
Is it still possible to block access to the status bar and if so, how should that be done?
 

Semen Matusovskiy

Well-Known Member
Licensed User
Guess, you use TYPE_SYSTEM_ERROR. Meanwhile SDK talks

1) This constant was deprecated in API level 26. for non-system apps. Use TYPE_APPLICATION_OVERLAY (2038) instead.

2)
If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen. The app requests the user's approval by sending an intent with action Settings.ACTION_MANAGE_OVERLAY_PERMISSION. The app can check whether it has this authorization by callingSettings.canDrawOverlays().
The situation is similar to WRITE_SETTINGS - see Erel's code (#14) in https://www.b4x.com/android/forum/threads/permission-write_settings.94311/#content

B4X:
Sub CanDrawOverlays As Boolean

    Dim javaobjectContext                                                As JavaObject
    Dim javaobjectSettings                                               As JavaObject   
    Dim phoneInstance                                                    As Phone
   
    If phoneInstance.SdkVersion >= 23 Then       
        javaobjectContext.InitializeContext       
        javaobjectSettings.InitializeStatic ("android.provider.Settings")
        Return javaobjectSettings.RunMethod ("canDrawOverlays", Array (javaobjectContext))
    Else
        Return True
    End If
   
End Sub

....

        If CanDrawOverlays = False Then
            Dim in As Intent
            in.Initialize("android.settings.action.MANAGE_OVERLAY_PERMISSION", "package:" & Application.PackageName)
            StartActivity (in)
            Wait For Activity_Resume
        End If

.....
 
Last edited:
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
Hello,

Just to be sure, I tried the suggestions you gave me. Unfortunately, it brought no solution:

Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@6e2a31f -- permission denied for window type 2010

So, it looks as one has to use type 1000 instead of type 2010. Unfortunately, i can't make Erels code working when i just replace type 2010 with type 1000.

Furthermore, it looks as this type of overlay is not blokking access to the status bar...

Any suggestions?
 
Upvote 0

Semen Matusovskiy

Well-Known Member
Licensed User
About Erel's code. I attached small sample, how to retrieve a permission under Oreo.
From your alone statement it's hard to understand, what are you doing exactly. But if you continue to receive "2010", then you didn't change 2010 to 2038.
 

Attachments

  • 1.zip
    8 KB · Views: 309
Upvote 0

fransvlaarhoven

Active Member
Licensed User
Longtime User
indeed, i changed to 1000. I will give it another try. In the mean time i was experimenting with a real kiosk application so that i do not have to use overlays.

But thank you verry much for you help.
 
Upvote 0
Top