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

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

Closed
workzj opened this issue Mar 23, 2016 · 11 comments
Closed

Comments

@workzj
Copy link

workzj commented Mar 23, 2016

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 .

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

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.

@sorccu sorccu closed this as completed Mar 23, 2016
@workzj
Copy link
Author

workzj commented Mar 23, 2016

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

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

Does your app run as root?

@workzj
Copy link
Author

workzj commented Mar 23, 2016

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;
}

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

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

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

Also what does this have to do with minicap?

@workzj
Copy link
Author

workzj commented Mar 23, 2016

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.

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

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

@workzj
Copy link
Author

workzj commented Mar 23, 2016

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

@sorccu
Copy link
Member

sorccu commented Mar 23, 2016

Yes, because that's not how su works.

@workzj
Copy link
Author

workzj commented Mar 23, 2016

thank you ~! i try

stoefln pushed a commit to stoefln/minicap that referenced this issue Nov 10, 2021
Support  Android 12 (preview),and resolve black screen problem
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

2 participants