Migrate from android::String path functions to std::filesystem
Bug: 295394788
Test: m checkbuild
Change-Id: I57d0752e0579776308571c3a77a0072041ed68c5
diff --git a/drm/drmserver/Android.bp b/drm/drmserver/Android.bp
index cee44b9..81c2003 100644
--- a/drm/drmserver/Android.bp
+++ b/drm/drmserver/Android.bp
@@ -78,6 +78,9 @@
"libselinux",
"libstagefright_foundation",
],
+ whole_static_libs: [
+ "libc++fs",
+ ],
cflags: [
"-Wall",
@@ -124,6 +127,7 @@
],
static_libs: [
+ "libc++fs",
"libmediautils",
"liblog",
"libdrmframeworkcommon",
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index f7989bd..f37375f 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -39,6 +39,7 @@
#include "ReadWriteUtils.h"
#include <algorithm>
+#include <filesystem>
#define DECRYPT_FILE_ERROR (-1)
@@ -114,7 +115,7 @@
std::unique_ptr<DrmSupportInfo> info(engine.getSupportInfo(0));
uid_t callingUid = IPCThreadState::self()->getCallingUid();
- std::string plugInId(plugInId8.getPathLeaf().getBasePath().c_str());
+ std::string plugInId = std::filesystem::path(plugInId8.c_str()).stem();
ALOGV("%d calling %s %s", callingUid, plugInId.c_str(), func);
Mutex::Autolock _l(mMetricsLock);
@@ -316,8 +317,8 @@
IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId);
result = rDrmEngine.canHandle(uniqueId, path);
} else {
- String8 extension = path.getPathExtension();
- if (String8("") != extension) {
+ const auto extension = std::filesystem::path(path.c_str()).extension();
+ if (!extension.empty()) {
result = canHandle(uniqueId, path);
}
}
@@ -745,7 +746,7 @@
String8 DrmManager::getSupportedPlugInIdFromPath(int uniqueId, const String8& path) {
String8 plugInId("");
- const String8 fileSuffix = path.getPathExtension();
+ const String8 fileSuffix(std::filesystem::path(path.c_str()).extension().c_str());
for (size_t index = 0; index < mSupportInfoToPlugInIdMap.size(); index++) {
const DrmSupportInfo& drmSupportInfo = mSupportInfoToPlugInIdMap.keyAt(index);
diff --git a/drm/drmserver/PlugInManager.h b/drm/drmserver/PlugInManager.h
index df40476..8a60b78 100644
--- a/drm/drmserver/PlugInManager.h
+++ b/drm/drmserver/PlugInManager.h
@@ -25,6 +25,8 @@
#include <utils/Vector.h>
#include <utils/KeyedVector.h>
+#include <filesystem>
+
namespace android {
const char* const PLUGIN_MANAGER_CREATE = "create";
@@ -227,10 +229,9 @@
* True if the input name denotes plug-in
*/
bool isPlugIn(const struct dirent* pEntry) const {
- String8 sName(pEntry->d_name);
- String8 extension(sName.getPathExtension());
+ const auto extension = std::filesystem::path(pEntry->d_name).extension();
// Note that the plug-in extension must exactly match case
- return extension == String8(PLUGIN_EXTENSION);
+ return extension.string() == PLUGIN_EXTENSION;
}
/**
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp
index 6e55a16..16ea15e 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/Android.bp
@@ -64,6 +64,10 @@
"libfwdlock-decoder",
],
+ whole_static_libs: [
+ "libc++fs",
+ ],
+
local_include_dirs: ["include"],
relative_install_path: "drm",
diff --git a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
index 1d8c724..1ade2f7 100644
--- a/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
+++ b/drm/libdrmframework/plugins/forward-lock/FwdLockEngine/src/FwdLockEngine.cpp
@@ -37,6 +37,8 @@
#include "FwdLockGlue.h"
#include "MimeTypeUtil.h"
+#include <filesystem>
+
#undef LOG_TAG
#define LOG_TAG "FwdLockEngine"
@@ -227,7 +229,7 @@
bool FwdLockEngine::onCanHandle(int /* uniqueId */, const String8& path) {
bool result = false;
- String8 extString = path.getPathExtension();
+ String8 extString(std::filesystem::path(path.c_str()).extension().c_str());
return IsFileSuffixSupported(extString);
}
diff --git a/drm/libdrmframework/plugins/passthru/Android.bp b/drm/libdrmframework/plugins/passthru/Android.bp
index 6dffd49..0a6cd47 100644
--- a/drm/libdrmframework/plugins/passthru/Android.bp
+++ b/drm/libdrmframework/plugins/passthru/Android.bp
@@ -39,11 +39,15 @@
srcs: ["src/DrmPassthruPlugIn.cpp"],
shared_libs: [
+ "libbase",
"libutils",
"liblog",
"libdl",
"libdrmframeworkcommon",
],
+ whole_static_libs: [
+ "libc++fs",
+ ],
local_include_dirs: ["include"],
diff --git a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
index 44b4438..55b4b08 100644
--- a/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
+++ b/drm/libdrmframework/plugins/passthru/src/DrmPassthruPlugIn.cpp
@@ -18,6 +18,7 @@
#define LOG_TAG "DrmPassthruPlugIn"
#include <utils/Log.h>
+#include <android-base/strings.h>
#include <drm/DrmRights.h>
#include <drm/DrmConstraints.h>
#include <drm/DrmMetadata.h>
@@ -29,6 +30,8 @@
#include <drm/DrmSupportInfo.h>
#include <DrmPassthruPlugIn.h>
+#include <filesystem>
+
using namespace android;
@@ -159,9 +162,8 @@
bool DrmPassthruPlugIn::onCanHandle(int /*uniqueId*/, const String8& path) {
ALOGV("DrmPassthruPlugIn::canHandle: %s ", path.c_str());
- String8 extension = path.getPathExtension();
- extension.toLower();
- return (String8(".passthru") == extension);
+ const auto extension = std::filesystem::path(path.c_str()).extension();
+ return base::EqualsIgnoreCase(extension.string(), ".passthru");
}
String8 DrmPassthruPlugIn::onGetOriginalMimeType(int uniqueId,