Use optional for nullable types
AIDL generates optional<T> for nullable T types for C++, which is more
efficient and idomatic and easy to use.
Bug: 144773267
Test: build/flash/boot
Merged-In: I98549c8614c9152d5d45e2f1f33f2f3c31a9bbbf
Change-Id: I98549c8614c9152d5d45e2f1f33f2f3c31a9bbbf
(cherry picked from commit 0568fd287cfc0affc8e985f21da3793cdda286a3)
diff --git a/VoldNativeService.cpp b/VoldNativeService.cpp
index 905407b..800d602 100644
--- a/VoldNativeService.cpp
+++ b/VoldNativeService.cpp
@@ -795,7 +795,7 @@
return translateBool(fscrypt_lock_user_key(userId));
}
-binder::Status VoldNativeService::prepareUserStorage(const std::unique_ptr<std::string>& uuid,
+binder::Status VoldNativeService::prepareUserStorage(const std::optional<std::string>& uuid,
int32_t userId, int32_t userSerial,
int32_t flags) {
ENFORCE_SYSTEM_OR_ROOT;
@@ -807,7 +807,7 @@
return translateBool(fscrypt_prepare_user_storage(uuid_, userId, userSerial, flags));
}
-binder::Status VoldNativeService::destroyUserStorage(const std::unique_ptr<std::string>& uuid,
+binder::Status VoldNativeService::destroyUserStorage(const std::optional<std::string>& uuid,
int32_t userId, int32_t flags) {
ENFORCE_SYSTEM_OR_ROOT;
std::string empty_string = "";
@@ -944,9 +944,9 @@
<< result.logFd;
using ParcelFileDescriptor = ::android::os::ParcelFileDescriptor;
using unique_fd = ::android::base::unique_fd;
- _aidl_return->cmd = std::make_unique<ParcelFileDescriptor>(unique_fd(result.cmdFd));
+ _aidl_return->cmd = ParcelFileDescriptor(unique_fd(result.cmdFd));
if (result.logFd >= 0) {
- _aidl_return->log = std::make_unique<ParcelFileDescriptor>(unique_fd(result.logFd));
+ _aidl_return->log = ParcelFileDescriptor(unique_fd(result.logFd));
}
return ok();
}
diff --git a/VoldNativeService.h b/VoldNativeService.h
index 18551f2..213c48d 100644
--- a/VoldNativeService.h
+++ b/VoldNativeService.h
@@ -120,9 +120,9 @@
const std::string& secret);
binder::Status lockUserKey(int32_t userId);
- binder::Status prepareUserStorage(const std::unique_ptr<std::string>& uuid, int32_t userId,
+ binder::Status prepareUserStorage(const std::optional<std::string>& uuid, int32_t userId,
int32_t userSerial, int32_t flags);
- binder::Status destroyUserStorage(const std::unique_ptr<std::string>& uuid, int32_t userId,
+ binder::Status destroyUserStorage(const std::optional<std::string>& uuid, int32_t userId,
int32_t flags);
binder::Status prepareSandboxForApp(const std::string& packageName, int32_t appId,