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.
Bug: 265487852
Test: Presubmit, ran CtsCameraTestCases on Cuttlefish, adb shell dumpsys media camera and observed output
Change-Id: I2b258a8636030dc4b7751140db43981b39c64f0d
Merged-In: I59330ac03c8a52b6c21a2388bba0c143e68af4cf
diff --git a/camera/camera2/OutputConfiguration.cpp b/camera/camera2/OutputConfiguration.cpp
index 11d4960..7cd9fc7 100644
--- a/camera/camera2/OutputConfiguration.cpp
+++ b/camera/camera2/OutputConfiguration.cpp
@@ -21,6 +21,7 @@
#include <utils/Log.h>
#include <camera/camera2/OutputConfiguration.h>
+#include <camera/StringUtils.h>
#include <binder/Parcel.h>
#include <gui/view/Surface.h>
#include <system/camera_metadata.h>
@@ -65,7 +66,7 @@
return mIsShared;
}
-String16 OutputConfiguration::getPhysicalCameraId() const {
+std::string OutputConfiguration::getPhysicalCameraId() const {
return mPhysicalCameraId;
}
@@ -173,7 +174,9 @@
return err;
}
- parcel->readString16(&mPhysicalCameraId);
+ String16 physicalCameraId;
+ parcel->readString16(&physicalCameraId);
+ mPhysicalCameraId = toStdString(physicalCameraId);
int isMultiResolution = 0;
if ((err = parcel->readInt32(&isMultiResolution)) != OK) {
@@ -224,7 +227,7 @@
for (auto& surface : surfaceShims) {
ALOGV("%s: OutputConfiguration: %p, name %s", __FUNCTION__,
surface.graphicBufferProducer.get(),
- String8(surface.name).string());
+ toString8(surface.name).string());
mGbps.push_back(surface.graphicBufferProducer);
}
@@ -235,14 +238,14 @@
" physicalCameraId = %s, isMultiResolution = %d, streamUseCase = %" PRId64
", timestampBase = %d, mirrorMode = %d",
__FUNCTION__, mRotation, mSurfaceSetID, mSurfaceType,
- String8(mPhysicalCameraId).string(), mIsMultiResolution, mStreamUseCase, timestampBase,
+ mPhysicalCameraId.c_str(), mIsMultiResolution, mStreamUseCase, timestampBase,
mMirrorMode);
return err;
}
OutputConfiguration::OutputConfiguration(sp<IGraphicBufferProducer>& gbp, int rotation,
- const String16& physicalId,
+ const std::string& physicalId,
int surfaceSetID, bool isShared) {
mGbps.push_back(gbp);
mRotation = rotation;
@@ -259,7 +262,7 @@
OutputConfiguration::OutputConfiguration(
const std::vector<sp<IGraphicBufferProducer>>& gbps,
- int rotation, const String16& physicalCameraId, int surfaceSetID, int surfaceType,
+ int rotation, const std::string& physicalCameraId, int surfaceSetID, int surfaceType,
int width, int height, bool isShared)
: mGbps(gbps), mRotation(rotation), mSurfaceSetID(surfaceSetID), mSurfaceType(surfaceType),
mWidth(width), mHeight(height), mIsDeferred(false), mIsShared(isShared),
@@ -305,7 +308,8 @@
err = parcel->writeParcelableVector(surfaceShims);
if (err != OK) return err;
- err = parcel->writeString16(mPhysicalCameraId);
+ String16 physicalCameraId = toString16(mPhysicalCameraId);
+ err = parcel->writeString16(physicalCameraId);
if (err != OK) return err;
err = parcel->writeInt32(mIsMultiResolution ? 1 : 0);