androidpermission-deniedkeyguard

Interfering with the Keyguard


I am currently working on an app that can draw views over the statusbar.

Here is my code:

@Override
public void onCreate() {
    // TODO Auto-generated method stub
    super.onCreate();
    wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    v = new StatusView(this);

    lp = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            **WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL**,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
            PixelFormat.TRANSLUCENT);
    wm.addView(v, lp);
    Log.d(TAG, "Added view");
}

However I get a security exception saying I don't have permission to use this view type. So I tried adding several permissions. Here are the ones i've tried so far:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.INTERNAL_SYSTEM_WINDOW"/>
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.BIND_REMOTEVIEWS"/>
<uses-permission android:name="android.permission.STATUS_BAR"/>

Any suggestions? This may not be possible as the statusbar is not considered part of the window.

EDIT:

The specific error is:

android.view.WindowManager$BadTokenException: unable to add window
android.view.ViewRoot$W@40518c50 - permission denied for this window type

Solution

  • Nevermind, I solved it! The problem wasn't TYPE , but FLAGS.