使用StatusBarManagerService时出错 - 在android.permission.STATUS_BAR_SERVICE上使用java.lang.SecurityException

joa*_*gcd 4 java reflection permissions android

我想使用StatusBarManagerService,但它在SDK上不可用,所以我尝试"作弊",使用反射来访问它.

我能够访问它,但现在它在访问其中一个方法时给出了一个错误:

java.lang.SecurityException: StatusBarManagerService: Neither user 10139 nor current process has android.permission.STATUS_BAR_SERVICE.
Run Code Online (Sandbox Code Playgroud)

是否有可能获得此许可,或者根本不可能?

这是我的代码:

    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();
    }
Run Code Online (Sandbox Code Playgroud)

这就是我在AndroidManifest中添加的内容:

  <uses-permission android:name="android.permission.STATUS_BAR_SERVICE" />
Run Code Online (Sandbox Code Playgroud)

是否有可能获得此许可,或者根本不可能?

Tom*_*Tom 8

从平台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" />
Run Code Online (Sandbox Code Playgroud)

请注意该protectionLevel属性,其值为signaturethis表示只有使用平台签名签名的应用程序才能被授予对此权限的访问权限.您无法从使用SDK的自签名应用程序获取此权限.