如何在PIE下使用私有创建者(例如EGLContext)创建对象?

lok*_*oki 5 java reflection android android-9.0-pie

此类是在Android下定义的:

public abstract class EGLObjectHandle {
    private final long mHandle;

    protected EGLObjectHandle(long handle) {
        mHandle = handle;
    }


    public long getNativeHandle() {
        return mHandle;
    }

}
Run Code Online (Sandbox Code Playgroud)

并且

public class EGLContext extends EGLObjectHandle {
    private EGLContext(long handle) {
        super(handle);
    }

} 
Run Code Online (Sandbox Code Playgroud)

现在我的问题是我想用我的手柄创建一个EGLContext。这该怎么做?在我使用下面的功能之前,但它在PIE上不再起作用

  private android.opengl.EGLContext createSharedEGLContextObj(long handle) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    Class<?> classType =Class.forName("android.opengl.EGLContext"); 
    Class<?>[] types = new Class[] { long.class };
    Constructor constructor=classType.getDeclaredConstructor(types);
    constructor.setAccessible(true);     
    Object object=constructor.newInstance(handle);
    return (android.opengl.EGLContext) object;
  }
Run Code Online (Sandbox Code Playgroud)

我需要一个EGLContext因为我需要将其传递给需要EGLContext参数的过程,例如:createEgl14( android.opengl.EGLContext sharedContext)

Oug*_*ail 2

你几乎不能。根据Android 限制,他们将 JNI 和反射限制为仅 SDK 接口。

我认为您的最终选择是请求一个新功能,他们将把构造函数的可见性更改为公众。