cameraservice: Migrate all internal String8/String16s to std::string
String8 and String16 are deprecated classes. It is recommended to use
std::string or std::u16string wherever possible. String16 is the native
string class for aidl, but Strings marked @utf8InCpp can use std::string
directly.
This patch standardizes libcameraservice's use of strings to
std::string, which is capable of storing utf-8 strings. This makes the
code more readable and potentially reduces the number of string copies
to a minimum.
A new set of string utils is added to frameworks/av/camera to aid this
migration.
Change-Id: I59330ac03c8a52b6c21a2388bba0c143e68af4cf
Bug: 265487852
Test: Presubmit, ran CtsCameraTestCases on Cuttlefish, adb shell dumpsys media camera and observed output
diff --git a/services/camera/libcameraservice/aidl/AidlUtils.cpp b/services/camera/libcameraservice/aidl/AidlUtils.cpp
index 1b8e53b..7291c5f 100644
--- a/services/camera/libcameraservice/aidl/AidlUtils.cpp
+++ b/services/camera/libcameraservice/aidl/AidlUtils.cpp
@@ -22,6 +22,7 @@
#include <device3/Camera3StreamInterface.h>
#include <gui/bufferqueue/1.0/H2BGraphicBufferProducer.h>
#include <mediautils/AImageReaderUtils.h>
+#include <camera/StringUtils.h>
namespace android::hardware::cameraservice::utils::conversion::aidl {
@@ -80,9 +81,8 @@
iGBPs.push_back(new H2BGraphicBufferProducer(AImageReader_getHGBPFromHandle(nh)));
native_handle_delete(nh);
}
- String16 physicalCameraId16(src.physicalCameraId.c_str());
UOutputConfiguration outputConfiguration(
- iGBPs, convertFromAidl(src.rotation), physicalCameraId16,
+ iGBPs, convertFromAidl(src.rotation), src.physicalCameraId,
src.windowGroupId, OutputConfiguration::SURFACE_TYPE_UNKNOWN, 0, 0,
(windowHandles.size() > 1));
return outputConfiguration;
@@ -175,7 +175,7 @@
dst.frameNumber = src.frameNumber;
dst.partialResultCount = src.partialResultCount;
dst.errorStreamId = src.errorStreamId;
- dst.errorPhysicalCameraId = String8(src.errorPhysicalCameraId).string();
+ dst.errorPhysicalCameraId = src.errorPhysicalCameraId;
return dst;
}
@@ -217,7 +217,7 @@
SPhysicalCaptureResultInfo convertToAidl(const UPhysicalCaptureResultInfo & src,
std::shared_ptr<CaptureResultMetadataQueue> & fmq) {
SPhysicalCaptureResultInfo dst;
- dst.physicalCameraId = String8(src.mPhysicalCameraId).string();
+ dst.physicalCameraId = src.mPhysicalCameraId;
const camera_metadata_t *rawMetadata = src.mPhysicalCameraMetadata.getAndLock();
// Try using fmq at first.
@@ -242,12 +242,12 @@
size_t i = 0;
for (const auto &statusAndId : src) {
auto &a = (*dst)[i++];
- a.cameraId = statusAndId.cameraId.c_str();
+ a.cameraId = statusAndId.cameraId;
a.deviceStatus = convertCameraStatusToAidl(statusAndId.status);
size_t numUnvailPhysicalCameras = statusAndId.unavailablePhysicalIds.size();
a.unavailPhysicalCameraIds.resize(numUnvailPhysicalCameras);
for (size_t j = 0; j < numUnvailPhysicalCameras; j++) {
- a.unavailPhysicalCameraIds[j] = statusAndId.unavailablePhysicalIds[j].c_str();
+ a.unavailPhysicalCameraIds[j] = statusAndId.unavailablePhysicalIds[j];
}
}
}
@@ -302,4 +302,4 @@
return OK;
}
-} // namespace android::hardware::cameraservice::utils::conversion::aidl
\ No newline at end of file
+} // namespace android::hardware::cameraservice::utils::conversion::aidl