diff options
author | 2020-01-23 12:45:10 +0900 | |
---|---|---|
committer | 2020-02-24 00:22:20 +0000 | |
commit | 149be4a25ef423491c73dfc7bfd95e8177e9b4f8 (patch) | |
tree | a61aec984745d82d441098eea1deb83ecfafe9ad /libs/binder/IAppOpsService.cpp | |
parent | 818ac485917cf803ec72ae27979f06dea26dae4b (diff) |
Use std::optional for @nullable (AIDL)
Previously, nullable types were mapped to std::unique_ptr for C++
backend. But std::unique_ptr typically involves unnecessary alloc/dealloc.
For example, if nullable string is represented in unique_ptr<string>, we
should do "unique_ptr<string>(new string(value))" to set a value.
To avoid breaking all hand-written parcelables, only new read/write
functions are added to Parcel class and they are used only by
aidl-generated code and their implementations.
Bug: 144773267
Test: build/flash/boot
atest --test-mapping frameworks/native/libs/binder
Change-Id: I2c801e3b69f2f8ccf44267f15cbf79e1d8fbf19e
Exempt-From-Owner-Approval: already got ORV from smoreland
Diffstat (limited to 'libs/binder/IAppOpsService.cpp')
-rw-r--r-- | libs/binder/IAppOpsService.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index a5555a304f..50e23b50a7 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -22,6 +22,8 @@ #include <binder/Parcel.h> #include <utils/String8.h> +#include <optional> + namespace android { // ---------------------------------------------------------------------- @@ -47,7 +49,7 @@ public: } virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::unique_ptr<String16>& featureId, bool shouldCollectAsyncNotedOp, + const std::optional<String16>& featureId, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -64,7 +66,7 @@ public: } virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr<String16>& featureId, + const String16& packageName, const std::optional<String16>& featureId, bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -83,7 +85,7 @@ public: } virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr<String16>& featureId) { + const String16& packageName, const std::optional<String16>& featureId) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeStrongBinder(token); @@ -182,7 +184,7 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::unique_ptr<String16> featureId; + std::optional<String16> featureId; data.readString16(&featureId); bool shouldCollectAsyncNotedOp = data.readInt32() == 1; String16 message = data.readString16(); @@ -198,7 +200,7 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::unique_ptr<String16> featureId; + std::optional<String16> featureId; data.readString16(&featureId); bool startIfModeDefault = data.readInt32() == 1; bool shouldCollectAsyncNotedOp = data.readInt32() == 1; @@ -215,7 +217,7 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::unique_ptr<String16> featureId; + std::optional<String16> featureId; data.readString16(&featureId); finishOperation(token, code, uid, packageName, featureId); reply->writeNoException(); |