How to create an Object with private creator (like EGLContext) under PIE?

耗尽温柔 提交于 2019-12-10 14:55:25

问题


This class is defined under Android:

public abstract class EGLObjectHandle {
    private final long mHandle;

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


    public long getNativeHandle() {
        return mHandle;
    }

}

and also

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

} 

now my problem is that I want to create an EGLContext with my handle. How to do this? before I do it with the function below but it's not working anymore on 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;
  }

I need an EGLContext because I need to pass it to a procedure who require an EGLContext parameter, like for example: createEgl14( android.opengl.EGLContext sharedContext)


回答1:


You pretty much can't. According to Android Restrictions they have restricted JNI and reflection to only SDK interfaces.

I think your final option is request a new feature where they will change the constructor visibility to public.



来源:https://stackoverflow.com/questions/55619029/how-to-create-an-object-with-private-creator-like-eglcontext-under-pie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!