screenrecord: Use DisplayId::fromValue
Bug: 182939859
Test: screenrecord -d <id>
Change-Id: I905348bd2fe31a505cf0ec84001ea8979874590a
diff --git a/cmds/screenrecord/screenrecord.cpp b/cmds/screenrecord/screenrecord.cpp
index e6e3473..cd8fe97 100644
--- a/cmds/screenrecord/screenrecord.cpp
+++ b/cmds/screenrecord/screenrecord.cpp
@@ -1067,7 +1067,7 @@
std::optional<PhysicalDisplayId> 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;
}
@@ -1168,17 +1168,14 @@
}
break;
case 'd':
- gPhysicalDisplayId = PhysicalDisplayId(atoll(optarg));
- if (gPhysicalDisplayId.value == 0) {
- fprintf(stderr, "Please specify a valid physical display id\n");
- return 2;
- } else if (SurfaceComposerClient::
- getPhysicalDisplayToken(gPhysicalDisplayId) == nullptr) {
- fprintf(stderr, "Invalid physical display id: %s\n",
- to_string(gPhysicalDisplayId).c_str());
- return 2;
+ if (const auto id = android::DisplayId::fromValue<PhysicalDisplayId>(atoll(optarg));
+ id && SurfaceComposerClient::getPhysicalDisplayToken(*id)) {
+ gPhysicalDisplayId = *id;
+ break;
}
- break;
+
+ fprintf(stderr, "Invalid physical display ID\n");
+ return 2;
default:
if (ic != '?') {
fprintf(stderr, "getopt_long returned unexpected value 0x%x\n", ic);