Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ask for help]ApplicationPackageManager cannot be cast to android.view.SurfaceControl #8

Closed
Moderpach opened this issue Feb 11, 2022 · 6 comments

Comments

@Moderpach
Copy link

I want to call a hidden api in android.view.SurfaceControl.
So I call this in my app module.

Refine.unsafeCast<SurfaceControlHidden>(context.packageManager).internalDisplayToken

And my "hidden-api" module is like

package android.view;

import dev.rikka.tools.refine.RefineAs;

@RefineAs(SurfaceControl.class)
public class SurfaceControlHidden {

    private native long[] nativeGetPhysicalDisplayIds();
    private native IBinder nativeGetPhysicalDisplayToken(long physicalDisplayId);

    public long[] getPhysicalDisplayIds() {
        return nativeGetPhysicalDisplayIds();
    }

    public IBinder getPhysicalDisplayToken(long physicalDisplayId) {
        return nativeGetPhysicalDisplayToken(physicalDisplayId);
    }

    public IBinder getInternalDisplayToken() {
        final long[] physicalDisplayIds = getPhysicalDisplayIds();
        if (physicalDisplayIds.length == 0) {
            return null;
        }
        return getPhysicalDisplayToken(physicalDisplayIds[0]);
    }

}

But when the app actually call the hidden api, it causes

java.lang.ClassCastException: android.app.ApplicationPackageManager cannot be cast to android.view.SurfaceControl

Did I make a mistake somewhere? Please help point it out. Thank you very much.

@RikkaW
Copy link
Member

RikkaW commented Feb 11, 2022

Refine.unsafeCast<SurfaceControlHidden>(context.packageManager)

You are casting context.packageManager (android.content.pm.PackageManager) to android.view.SurfaceControl which is obviously wrong.

Method getInternalDisplayToken is a static method, so correct your stub class and call SurfaceControlHidden.getInternalDisplayToken directly.

@RikkaW RikkaW closed this as completed Feb 11, 2022
@Moderpach
Copy link
Author

很抱歉又来叨扰您了。
如果我直接调用SurfaceControlHidden.getInternalDisplayToken会出现错误
java.lang.NoSuchMethodError: No static method getInternalDisplayToken()Landroid/os/IBinder; in class Landroid/view/SurfaceControl; or its super classes (declaration of 'android.view.SurfaceControl' appears in /system/framework/framework.jar!classes3.dex)我对此毫无头绪,请问如何解决。

另外是只要获取了Shizuku权限就可以只通过HiddenApiRefinePlugin中的方法就可以直接访问到Hidden-API了吗?还是要继续使用Shizuku-API里的"Using Shizuku APIs: Remote binder call"中的方法。

@Kr328
Copy link
Collaborator

Kr328 commented Feb 12, 2022

很抱歉又来叨扰您了。 如果我直接调用SurfaceControlHidden.getInternalDisplayToken会出现错误 java.lang.NoSuchMethodError: No static method getInternalDisplayToken()Landroid/os/IBinder; in class Landroid/view/SurfaceControl; or its super classes (declaration of 'android.view.SurfaceControl' appears in /system/framework/framework.jar!classes3.dex)我对此毫无头绪,请问如何解决。

另外是只要获取了Shizuku权限就可以只通过HiddenApiRefinePlugin中的方法就可以直接访问到Hidden-API了吗?还是要继续使用Shizuku-API里的"Using Shizuku APIs: Remote binder call"中的方法。

这个 API 可能是受到 Android 非 SDK API 限制

你有在使用绕过该限制的库吗 类似 AndroidHiddenApiBypass

@Moderpach
Copy link
Author

@Kr328 非常感谢,通过 https://github.com/LSPosed/AndroidHiddenApiBypass 我已经可以调用到API。
但是像 SurfaceControl.setDisplayBrightness()等这些设定类的方法,调用他们并没有任何作用,请问android是对这些方法有什么限制吗?

@Kr328
Copy link
Collaborator

Kr328 commented Feb 13, 2022

@Kr328 非常感谢,通过 https://github.com/LSPosed/AndroidHiddenApiBypass 我已经可以调用到API。 但是像 SurfaceControl.setDisplayBrightness()等这些设定类的方法,调用他们并没有任何作用,请问android是对这些方法有什么限制吗?

这类操作一般仅有系统进程或者特权应用拥有权限访问

你可以使用 SuiShizuku 来在特权进程下调用 API

具体可以在这俩仓库的 README.md 了解如何使用

在使用时可能会需要了解 API 的具体逻辑 可以使用 Code Search 阅读源代码

再具体的我无法提供帮助

@RikkaW
Copy link
Member

RikkaW commented Feb 13, 2022

Binder 是 Client/Server 的结构,SurfaceControl.setDisplayBrightness() 是客户端,所以要自己找服务端的实现来看有什么权限检查。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants