Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error using StatusBarManagerService - java.lang.SecurityException on android.permission.STATUS_BAR_SERVICE

I wanted to use the StatusBarManagerService, but it's not available on the SDK, so I tried "cheating", using reflection to access it.

I was able to access it, but now it's giving me an error when accessing one of its methods:

java.lang.SecurityException: StatusBarManagerService: Neither user 10139 nor current process has android.permission.STATUS_BAR_SERVICE.

Is it possible to be granted this permission, or is it simply not possible?

This is my code:

    try {
        Class serviceManagerClass = Class.forName("android.os.ServiceManager");
        Method getService = serviceManagerClass.getMethod("getService", String.class);
        IBinder retbinder = (IBinder) getService.invoke(serviceManagerClass, "statusbar");
        Class statusBarClass = Class.forName(retbinder.getInterfaceDescriptor());
        Object statusBarObject = statusBarClass.getClasses()[0].getMethod("asInterface", IBinder.class).invoke(null, new Object[] { retbinder });
        Method clearAll = statusBarClass.getMethod("onClearAllNotifications");
        clearAll.setAccessible(true);
        clearAll.invoke(statusBarObject);
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RemoteException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

And this is what I added in the AndroidManifest:

  <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />

Is it possible to be granted this permission, or is it simply not possible?

like image 640
joaomgcd Avatar asked Oct 19 '11 12:10

joaomgcd


1 Answers

From the platform AndroidManifest.xml:

<!-- Allows an application to be the status bar.  Currently used only by SystemUI.apk
@hide -->
<permission android:name="android.permission.STATUS_BAR_SERVICE"
    android:label="@string/permlab_statusBarService"
    android:description="@string/permdesc_statusBarService"
    android:protectionLevel="signature" />

Notice the protectionLevel attribute, with a value of signature this means that only applications signed with the platform signature and thus part of the device's ROM can be granted access to this permission. You cannot obtain this permission from a self-signed application utilizing the SDK.

like image 112
Tom Avatar answered Oct 06 '22 00:10

Tom