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/camera/camera2/ConcurrentCamera.cpp b/camera/camera2/ConcurrentCamera.cpp
index 01a695c..67aa876 100644
--- a/camera/camera2/ConcurrentCamera.cpp
+++ b/camera/camera2/ConcurrentCamera.cpp
@@ -20,6 +20,7 @@
#include <utils/String16.h>
#include <camera/camera2/ConcurrentCamera.h>
+#include <camera/StringUtils.h>
#include <binder/Parcel.h>
@@ -53,7 +54,7 @@
ALOGE("%s: Failed to read camera id!", __FUNCTION__);
return err;
}
- mConcurrentCameraIds.push_back(std::string(String8(id).string()));
+ mConcurrentCameraIds.push_back(toStdString(id));
}
return OK;
}
@@ -73,7 +74,7 @@
}
for (const auto &it : mConcurrentCameraIds) {
- if ((err = parcel->writeString16(String16(it.c_str()))) != OK) {
+ if ((err = parcel->writeString16(toString16(it))) != OK) {
ALOGE("%s: Failed to write the camera id string to parcel: %d", __FUNCTION__, err);
return err;
}
@@ -99,7 +100,7 @@
ALOGE("%s: Failed to read sessionConfiguration!", __FUNCTION__);
return err;
}
- mCameraId = std::string(String8(id).string());
+ mCameraId = toStdString(id);
return OK;
}
@@ -111,7 +112,7 @@
}
status_t err = OK;
- if ((err = parcel->writeString16(String16(mCameraId.c_str()))) != OK) {
+ if ((err = parcel->writeString16(toString16(mCameraId))) != OK) {
ALOGE("%s: Failed to write camera id!", __FUNCTION__);
return err;
}