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
Merged-In: I59330ac03c8a52b6c21a2388bba0c143e68af4cf
Bug: 265487852
Test: Presubmit, ran CtsCameraTestCases on Cuttlefish, adb shell dumpsys media camera and observed output
diff --git a/camera/ndk/impl/ACameraDevice.cpp b/camera/ndk/impl/ACameraDevice.cpp
index 1dae0f9..8bdb6d4 100644
--- a/camera/ndk/impl/ACameraDevice.cpp
+++ b/camera/ndk/impl/ACameraDevice.cpp
@@ -21,6 +21,7 @@
#include <inttypes.h>
#include <android/hardware/ICameraService.h>
#include <gui/Surface.h>
+#include <camera/StringUtils.h>
#include "ACameraDevice.h"
#include "ACameraMetadata.h"
#include "ACaptureRequest.h"
@@ -234,8 +235,7 @@
return ret;
}
- String16 physicalId16(output.mPhysicalCameraId.c_str());
- OutputConfiguration outConfig(iGBP, output.mRotation, physicalId16,
+ OutputConfiguration outConfig(iGBP, output.mRotation, output.mPhysicalCameraId,
OutputConfiguration::INVALID_SET_ID, true);
for (auto& anw : output.mSharedWindows) {
@@ -299,8 +299,7 @@
return ret;
}
- String16 physicalId16(output->mPhysicalCameraId.c_str());
- OutputConfiguration outConfig(iGBP, output->mRotation, physicalId16,
+ OutputConfiguration outConfig(iGBP, output->mRotation, output->mPhysicalCameraId,
OutputConfiguration::INVALID_SET_ID, true);
for (auto& anw : output->mSharedWindows) {
@@ -683,9 +682,8 @@
if (ret != ACAMERA_OK) {
return ret;
}
- String16 physicalId16(outConfig.mPhysicalCameraId.c_str());
outputSet.insert(std::make_pair(
- anw, OutputConfiguration(iGBP, outConfig.mRotation, physicalId16,
+ anw, OutputConfiguration(iGBP, outConfig.mRotation, outConfig.mPhysicalCameraId,
OutputConfiguration::INVALID_SET_ID, outConfig.mIsShared)));
}
auto addSet = outputSet;
@@ -919,7 +917,7 @@
msg->setObject(kSessionSpKey, session);
if (cbh.mIsLogicalCameraCallback) {
if (resultExtras.errorPhysicalCameraId.size() > 0) {
- String8 cameraId(resultExtras.errorPhysicalCameraId);
+ String8 cameraId = toString8(resultExtras.errorPhysicalCameraId);
msg->setString(kFailingPhysicalCameraId, cameraId.string(), cameraId.size());
}
msg->setPointer(kCallbackFpKey, (void*) cbh.mOnLogicalCameraCaptureFailed);
@@ -1215,7 +1213,7 @@
std::vector<std::string> physicalCameraIds;
std::vector<sp<ACameraMetadata>> physicalMetadataCopy;
for (size_t i = 0; i < physicalResultInfo.size(); i++) {
- String8 physicalId8(physicalResultInfo[i].mPhysicalCameraId);
+ String8 physicalId8 = toString8(physicalResultInfo[i].mPhysicalCameraId);
physicalCameraIds.push_back(physicalId8.c_str());
CameraMetadata clone = physicalResultInfo[i].mPhysicalCameraMetadata;