8000 what is the possible reason of " Unable to initialize SurfaceComposerClient " ? · Issue #26 · openstf/minicap · GitHub
[go: up one dir, main page]

Skip to content

what is the possible reason of " Unable to initialize SurfaceComposerClient " ? #26

Closed

Description

@workzj

my jni code :

android::spandroid::SurfaceComposerClient sc = new android::SurfaceComposerClient();

is failed .

i don't know why ??
look up the android source , i wirte the test code like this :

//test code
sp<ISurfaceComposer> sm(ComposerService::getComposerService());
if (sm != 0) {
    sp<ISurfaceComposerClient> conn = sm->createConnection();
    if (conn != 0) {
        LOG("init success ... ");
        return 1;
    }
    LOG("conn == 0");
    return -1;
}

the run result is : conn == 0 .
my question is why createConnection is failed ?
is authority ? is thread ?

i use the code in apk with JNI .

Activity

  1. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    Normal applications don't have permission to access SurfaceComposerClient. Only system apps can do it, or you can try rooting your device. Alternatively, if you're OK with supporting only Android 5.0+, try adding the CAPTURE_VIDEO_OUTPUT permission. I haven't tried it myself but it might work. Although if you're OK with 5.0+, you should use the official public APIs instead.

  2. workzj commented on Mar 23, 2016

    @workzj
    Author

    but,my device is root . and i run app on android 4.4. is any other reason?

  3. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    Does your app run as root?

  4. workzj commented on Mar 23, 2016

    @workzj
    Author

    yes, this is my test code:

    JNIEXPORT jint JNICALL Java_com_hupo_Screenshot(JNIEnv *jPE, jobject jo, jint jiX, jint jiY)
    {
        int result = system("su");
        if (result == -1)
        {
            return -1;
        }
    
        ProcessState::self()->startThreadPool();
    
        ScreenshotClient mScreenshotClient;
    
        sp<android::CpuConsumer> mConsumer;
        sp<android::IBinder> mVirtualDisplay;
        CpuConsumer::LockedBuffer mBuffer;
        sp<FrameProxy> mFrameProxy;
        status_t err;
    
        DisplayInfo dinfo;
        /*
        sp<android::IBinder> dpy = SurfaceComposerClient::getBuiltInDisplay(DEFAULT_DISPLAY_ID);
        err = SurfaceComposerClient::getDisplayInfo(dpy, &dinfo);
    
        if (err != NO_ERROR) {
            LOGD("SurfaceComposerClient::getDisplayInfo() failed: %s (%d)\n", error_name(err), err);
            return err;
        }*/
    
        //test code
        sp<ISurfaceComposer> sm(ComposerService::getComposerService());
        if (sm != 0) {
            sp<ISurfaceComposerClient> conn = sm->createConnection();
            if (conn != 0) {
                LOG("init success ... ");
                return 1;
            }
            LOG("conn == 0");
            return -1;
        }
    
        return -1;
    }
    
  5. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    That's not how su works... you only get root permissions inside su's child processes. Your code doesn't do anything.

  6. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    Also what does this have to do with minicap?

  7. workzj commented on Mar 23, 2016

    @workzj
    Author

    this is my test code , because of my original code :
    // Create a Surface for the virtual display to write to.
    LOG("Creating SurfaceComposerClient");
    android::spandroid::SurfaceComposerClient sc = new android::SurfaceComposerClient();

    LOG("Performing SurfaceComposerClient init check");
    if ((err = sc->initCheck()) != android::NO_ERROR) {
        LOGD("Unable to initialize SurfaceComposerClient failed: %s (%d)", error_name(err), err);
        return err;
    }
    

    is " Unable to initialize SurfaceComposerClient ".so i write this test.

  8. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    I see. Well, you need to fix your su usage somehow, but if you get that fixed I think it will work.

  9. workzj commented on Mar 23, 2016

    @workzj
    Author

    i don't understand ... you means , my app has not get the root authority ?

  10. sorccu commented on Mar 23, 2016

    @sorccu
    Member

    Yes, because that's not how su works.

  11. workzj commented on Mar 23, 2016

    @workzj
    Author

    thank you ~! i try

  12. added a commit that references this issue on Nov 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      0