Skip to content

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

Closed
@Moderpach

Description

@Moderpach

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions