Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0bda2e3c authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

screencap: Require display ID in -d switch

Remove undocumented fallback to layer stack, since virtual displays can
now be specified by their unambiguous IDs.

Bug: 182939859
Test: screencap -d <id>
Change-Id: I86a8e713d8076abe55aeeb327fd9d746c46e5a40
parent 73d71641
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -45,13 +45,13 @@ using namespace android;
#define COLORSPACE_SRGB       1
#define COLORSPACE_DISPLAY_P3 2

static void usage(const char* pname, PhysicalDisplayId displayId)
static void usage(const char* pname, DisplayId displayId)
{
    fprintf(stderr,
            "usage: %s [-hp] [-d display-id] [FILENAME]\n"
            "   -h: this message\n"
            "   -p: save the file as a png.\n"
            "   -d: specify the physical display ID to capture (default: %s)\n"
            "   -d: specify the display ID to capture (default: %s)\n"
            "       see \"dumpsys SurfaceFlinger --display-id\" for valid display IDs.\n"
            "If FILENAME ends with .png it will be saved as a png.\n"
            "If FILENAME is not given, the results will be printed to stdout.\n",
@@ -121,9 +121,9 @@ static status_t notifyMediaScanner(const char* fileName) {

int main(int argc, char** argv)
{
    std::optional<PhysicalDisplayId> displayId = SurfaceComposerClient::getInternalDisplayId();
    std::optional<DisplayId> displayId = SurfaceComposerClient::getInternalDisplayId();
    if (!displayId) {
        fprintf(stderr, "Failed to get token for internal display\n");
        fprintf(stderr, "Failed to get ID for internal display\n");
        return 1;
    }

@@ -136,7 +136,11 @@ int main(int argc, char** argv)
                png = true;
                break;
            case 'd':
                displayId = PhysicalDisplayId(atoll(optarg));
                displayId = DisplayId::fromValue(atoll(optarg));
                if (!displayId) {
                    fprintf(stderr, "Invalid display ID\n");
                    return 1;
                }
                break;
            case '?':
            case 'h':
@@ -182,7 +186,7 @@ int main(int argc, char** argv)
    ProcessState::self()->startThreadPool();

    sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener();
    status_t result = ScreenshotClient::captureDisplay(displayId->value, captureListener);
    status_t result = ScreenshotClient::captureDisplay(*displayId, captureListener);
    if (result != NO_ERROR) {
        close(fd);
        return 1;
+3 −2
Original line number Diff line number Diff line
@@ -840,8 +840,9 @@ static jlongArray nativeGetPhysicalDisplayIds(JNIEnv* env, jclass clazz) {
}

static jobject nativeGetPhysicalDisplayToken(JNIEnv* env, jclass clazz, jlong physicalDisplayId) {
    sp<IBinder> token =
            SurfaceComposerClient::getPhysicalDisplayToken(PhysicalDisplayId(physicalDisplayId));
    const auto id = DisplayId::fromValue<PhysicalDisplayId>(physicalDisplayId);
    if (!id) return nullptr;
    sp<IBinder> token = SurfaceComposerClient::getPhysicalDisplayToken(*id);
    return javaObjectForIBinder(env, token);
}