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/device3/Camera3FakeStream.cpp b/services/camera/libcameraservice/device3/Camera3FakeStream.cpp
index 8c0ac71..75162bf 100644
--- a/services/camera/libcameraservice/device3/Camera3FakeStream.cpp
+++ b/services/camera/libcameraservice/device3/Camera3FakeStream.cpp
@@ -20,13 +20,14 @@
#include <utils/Log.h>
#include <utils/Trace.h>
+#include <camera/StringUtils.h>
#include "Camera3FakeStream.h"
namespace android {
namespace camera3 {
-const String8 Camera3FakeStream::FAKE_ID;
+const std::string Camera3FakeStream::FAKE_ID;
Camera3FakeStream::Camera3FakeStream(int id) :
Camera3IOStreamBase(id, CAMERA_STREAM_OUTPUT, FAKE_WIDTH, FAKE_HEIGHT,
@@ -68,9 +69,9 @@
}
void Camera3FakeStream::dump(int fd, [[maybe_unused]] const Vector<String16> &args) const {
- String8 lines;
- lines.appendFormat(" Stream[%d]: Fake\n", mId);
- write(fd, lines.string(), lines.size());
+ std::string lines;
+ lines += fmt::sprintf(" Stream[%d]: Fake\n", mId);
+ write(fd, lines.c_str(), lines.size());
Camera3IOStreamBase::dump(fd, args);
}
@@ -115,7 +116,7 @@
return OK;
}
-const String8& Camera3FakeStream::getPhysicalCameraId() const {
+const std::string& Camera3FakeStream::getPhysicalCameraId() const {
return FAKE_ID;
}