From 66a877723cc8019ec828a3fc8372d364f02384df Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Mon, 24 Jun 2019 16:30:00 -0700 Subject: Support noted appops collection in native code With change I96ded4a8d8d9bcb37a4555d9b1281cb57945ffa9 the system now allows apps to collect all app-ops that are noted for them. Native code can also note app-op. Unfortunately there is no guaranteed way how an app's native code can interact with java code that might or might not be running in the same process. Hence we cannot support sending the noted app-ops back to the caller over binders. Hence all notes app-ops will need to be collected as AsyncNotedOps Test: atest CtsAppOpsTestCases (includes tests that note app-ops natively) Bug: 136505050 Change-Id: I5dc479468c8dae3b10f071123b0535a288bf8662 --- libs/binder/AppOpsManager.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 2 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 525685c35e..48b218e78b 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -21,10 +21,18 @@ #include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "AppOpsManager" + namespace android { namespace { +#ifndef __ANDROID_VNDK__ #if defined(__BRILLO__) // Because Brillo has no application model, security policy is managed // statically (at build time) with SELinux controls. @@ -33,13 +41,17 @@ const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED; #else const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; #endif // defined(__BRILLO__) +#endif // __ANDROID_VNDK__ } // namespace static String16 _appops("appops"); +#ifndef __ANDROID_VNDK__ static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER; +#endif // __ANDROID_VNDK__ static sp gToken; +#ifndef __ANDROID_VNDK__ static const sp& getToken(const sp& service) { pthread_mutex_lock(&gTokenMutex); if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) { @@ -48,6 +60,17 @@ static const sp& getToken(const sp& service) { pthread_mutex_unlock(&gTokenMutex); return gToken; } +#endif // __ANDROID_VNDK__ + +thread_local uint64_t notedAppOpsInThisBinderTransaction[2]; +thread_local int32_t uidOfThisBinderTransaction = -1; + +// Whether an appop should be collected: 0 == not initialized, 1 == don't note, 2 == note +#ifndef __ANDROID_VNDK__ +uint8_t appOpsToNote[AppOpsManager::_NUM_OP] = {0}; +#else +uint8_t appOpsToNote[128] = {0}; +#endif // __ANDROID_VNDK__ AppOpsManager::AppOpsManager() { @@ -85,6 +108,7 @@ sp AppOpsManager::getService() } #endif // defined(__BRILLO__) +#ifndef __ANDROID_VNDK__ int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage) { sp service = getService(); @@ -102,18 +126,41 @@ int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t ui } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { + return noteOp(op, uid, callingPackage, String16("noteOp from native code")); +} + +int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage, + const String16& message) { sp service = getService(); - return service != nullptr + int32_t mode = service != nullptr ? service->noteOperation(op, uid, callingPackage) : APP_OPS_MANAGER_UNAVAILABLE_MODE; + + if (mode == AppOpsManager::MODE_ALLOWED) { + markAppOpNoted(uid, callingPackage, op, message); + } + + return mode; } int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault) { + return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, + String16("startOpNoThrow from native code")); +} + +int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, + bool startIfModeDefault, const String16& message) { sp service = getService(); - return service != nullptr + int32_t mode = service != nullptr ? service->startOperation(getToken(service), op, uid, callingPackage, startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; + + if (mode == AppOpsManager::MODE_ALLOWED) { + markAppOpNoted(uid, callingPackage, op, message); + } + + return mode; } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) { @@ -146,5 +193,40 @@ int32_t AppOpsManager::permissionToOpCode(const String16& permission) { return -1; } +#endif // __ANDROID_VNDK__ + +bool AppOpsManager::shouldCollectNotes(int32_t opcode) { + sp service = getService(); + if (service != nullptr) { + return service->shouldCollectNotes(opcode); + } + return false; +} + +void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, + const String16& message) { + // check it the appops needs to be collected and cache result + if (appOpsToNote[opCode] == 0) { + if (shouldCollectNotes(opCode)) { + appOpsToNote[opCode] = 2; + } else { + appOpsToNote[opCode] = 1; + } + } + + if (appOpsToNote[opCode] != 2) { + return; + } + + noteAsyncOp(String16(), uid, packageName, opCode, message); +} + +void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid, + const String16& packageName, int32_t opCode, const String16& message) { + sp service = getService(); + if (service != nullptr) { + return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, message); + } +} }; // namespace android -- cgit v1.2.3-59-g8ed1b From 8e95ee87a96bcacab17a4b49a8150fb42565ac8c Mon Sep 17 00:00:00 2001 From: Yin-Chia Yeh Date: Tue, 13 Aug 2019 12:24:25 -0700 Subject: Camera: add camera audio restriction binder call Also add the API to AppOpsManager Test: new CTS tests Bug: 135676184 Change-Id: I8bcdd34a4b6bb0fba5151677db38f8c35b7ae97e --- libs/binder/AppOpsManager.cpp | 7 +++++++ libs/binder/IAppOpsService.cpp | 14 ++++++++++++++ libs/binder/include/binder/AppOpsManager.h | 2 ++ libs/binder/include/binder/IAppOpsService.h | 5 +++++ 4 files changed, 28 insertions(+) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 48b218e78b..e2af01c161 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -193,6 +193,13 @@ int32_t AppOpsManager::permissionToOpCode(const String16& permission) { return -1; } +void AppOpsManager::setCameraAudioRestriction(int32_t mode) { + sp service = getService(); + if (service != nullptr) { + service->setCameraAudioRestriction(mode); + } +} + #endif // __ANDROID_VNDK__ bool AppOpsManager::shouldCollectNotes(int32_t opcode) { diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 8840990824..b6360cbffd 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -138,6 +138,13 @@ public: return reply.readInt32(); } + virtual void setCameraAudioRestriction(int32_t mode) { + Parcel data, reply; + data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); + data.writeInt32(mode); + remote()->transact(SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION, data, &reply); + } + #endif virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message) { @@ -274,6 +281,13 @@ status_t BnAppOpsService::onTransact( reply->writeInt32(res); return NO_ERROR; } break; + case SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION: { + CHECK_INTERFACE(IAppOpsService, data, reply); + const int32_t mode = data.readInt32(); + setCameraAudioRestriction(mode); + reply->writeNoException(); + return NO_ERROR; + } break; #endif // __ANDROID_VNDK__ case NOTE_ASYNC_OP_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index 7a99396eef..dff4d49596 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -144,9 +144,11 @@ public: const sp& callback); void stopWatchingMode(const sp& callback); int32_t permissionToOpCode(const String16& permission); + void setCameraAudioRestriction(int32_t mode); #endif // __ANDROID_VNDK__ void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message); + private: Mutex mLock; sp mService; diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 9d02370015..009ef6c7a7 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -46,6 +46,7 @@ public: virtual int32_t permissionToOpCode(const String16& permission) = 0; virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, const String16& packageName) = 0; + virtual void setCameraAudioRestriction(int32_t mode) = 0; #endif // __ANDROID_VNDK__ virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message) = 0; @@ -65,6 +66,10 @@ public: #endif // __ANDROID_VNDK__ NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10, +#ifndef __ANDROID_VNDK__ + SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+11, +#endif // __ANDROID_VNDK__ + }; enum { -- cgit v1.2.3-59-g8ed1b From c326a94d15828aee6a9261763bb40b82824f0c6c Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Mon, 9 Sep 2019 16:07:52 -0700 Subject: libbinder: Hide AppOpsManager/Service from vendor. Vendor apps can still use these behind stable SDK or NDK APIs as applicable, but native code on the vendor image can't use these APIs because they are using /dev/vndbinder and have an incompatible copy of libbinder. Since no vendor binary is serving this, removing extra pound defines and making the vendor version of this library slightly smaller. Bug: 124524556 Test: builds (no vendor code has added dependencies on this yet) Change-Id: Idf01641d4b340ca6fe33c181969507ec071ef930 --- libs/binder/Android.bp | 2 ++ libs/binder/AppOpsManager.cpp | 13 ------------- libs/binder/IAppOpsService.cpp | 4 ---- libs/binder/include/binder/AppOpsManager.h | 8 ++++---- libs/binder/include/binder/IAppOpsService.h | 13 ++++--------- 5 files changed, 10 insertions(+), 30 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index 6ece4a2162..86f19c5873 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -86,8 +86,10 @@ cc_library_shared { vendor: { exclude_srcs: [ "ActivityManager.cpp", + "AppOpsManager.cpp", "IActivityManager.cpp", "IAppOpsCallback.cpp", + "IAppOpsService.cpp", "IBatteryStats.cpp", "IMediaResourceMonitor.cpp", "IPermissionController.cpp", diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index e2af01c161..711fed96a1 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -32,7 +32,6 @@ namespace android { namespace { -#ifndef __ANDROID_VNDK__ #if defined(__BRILLO__) // Because Brillo has no application model, security policy is managed // statically (at build time) with SELinux controls. @@ -41,17 +40,13 @@ const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED; #else const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; #endif // defined(__BRILLO__) -#endif // __ANDROID_VNDK__ } // namespace static String16 _appops("appops"); -#ifndef __ANDROID_VNDK__ static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER; -#endif // __ANDROID_VNDK__ static sp gToken; -#ifndef __ANDROID_VNDK__ static const sp& getToken(const sp& service) { pthread_mutex_lock(&gTokenMutex); if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) { @@ -60,17 +55,12 @@ static const sp& getToken(const sp& service) { pthread_mutex_unlock(&gTokenMutex); return gToken; } -#endif // __ANDROID_VNDK__ thread_local uint64_t notedAppOpsInThisBinderTransaction[2]; thread_local int32_t uidOfThisBinderTransaction = -1; // Whether an appop should be collected: 0 == not initialized, 1 == don't note, 2 == note -#ifndef __ANDROID_VNDK__ uint8_t appOpsToNote[AppOpsManager::_NUM_OP] = {0}; -#else -uint8_t appOpsToNote[128] = {0}; -#endif // __ANDROID_VNDK__ AppOpsManager::AppOpsManager() { @@ -108,7 +98,6 @@ sp AppOpsManager::getService() } #endif // defined(__BRILLO__) -#ifndef __ANDROID_VNDK__ int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage) { sp service = getService(); @@ -200,8 +189,6 @@ void AppOpsManager::setCameraAudioRestriction(int32_t mode) { } } -#endif // __ANDROID_VNDK__ - bool AppOpsManager::shouldCollectNotes(int32_t opcode) { sp service = getService(); if (service != nullptr) { diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index b6360cbffd..c58ea029b3 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -34,7 +34,6 @@ public: { } -#ifndef __ANDROID_VNDK__ virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -145,7 +144,6 @@ public: remote()->transact(SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION, data, &reply); } -#endif virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message) { Parcel data, reply; @@ -195,7 +193,6 @@ status_t BnAppOpsService::onTransact( { //printf("AppOpsService received: "); data.print(); switch(code) { -#ifndef __ANDROID_VNDK__ case CHECK_OPERATION_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); int32_t code = data.readInt32(); @@ -288,7 +285,6 @@ status_t BnAppOpsService::onTransact( reply->writeNoException(); return NO_ERROR; } break; -#endif // __ANDROID_VNDK__ case NOTE_ASYNC_OP_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); String16 callingPackageName = data.readString16(); diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index dff4d49596..f5a54cea4c 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -21,6 +21,10 @@ #include +#ifdef __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif + // --------------------------------------------------------------------------- namespace android { @@ -33,7 +37,6 @@ public: MODE_ERRORED = IAppOpsService::MODE_ERRORED }; -#ifndef __ANDROID_VNDK__ enum { OP_NONE = -1, OP_COARSE_LOCATION = 0, @@ -121,11 +124,9 @@ public: OP_READ_DEVICE_IDENTIFIERS = 89, _NUM_OP = 90 }; -#endif // __ANDROID_VNDK__ AppOpsManager(); -#ifndef __ANDROID_VNDK__ int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid, const String16& callingPackage); @@ -145,7 +146,6 @@ public: void stopWatchingMode(const sp& callback); int32_t permissionToOpCode(const String16& permission); void setCameraAudioRestriction(int32_t mode); -#endif // __ANDROID_VNDK__ void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message); diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 009ef6c7a7..978400304e 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -18,11 +18,13 @@ #ifndef ANDROID_IAPP_OPS_SERVICE_H #define ANDROID_IAPP_OPS_SERVICE_H -#ifndef __ANDROID_VNDK__ #include -#endif #include +#ifdef __ANDROID_VNDK__ +#error "This header is not visible to vendors" +#endif + namespace android { // ---------------------------------------------------------------------- @@ -32,7 +34,6 @@ class IAppOpsService : public IInterface public: DECLARE_META_INTERFACE(AppOpsService) -#ifndef __ANDROID_VNDK__ virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, @@ -47,13 +48,11 @@ public: virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, const String16& packageName) = 0; virtual void setCameraAudioRestriction(int32_t mode) = 0; -#endif // __ANDROID_VNDK__ virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, int32_t opCode, const String16& message) = 0; virtual bool shouldCollectNotes(int32_t opCode) = 0; enum { -#ifndef __ANDROID_VNDK__ CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION, NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1, START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2, @@ -63,13 +62,9 @@ public: GET_TOKEN_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6, PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7, CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, -#endif // __ANDROID_VNDK__ NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10, -#ifndef __ANDROID_VNDK__ SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+11, -#endif // __ANDROID_VNDK__ - }; enum { -- cgit v1.2.3-59-g8ed1b From 6511af57870adc67363664edd10fc35cf9f01128 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Thu, 26 Sep 2019 16:05:45 -0700 Subject: Remove extraneous semicolon. Bug: N/A Test: build w/o -Wno-c++98-compat-extra-semi Change-Id: I632d6df9a03485e547a6e7f14df0f1c068066c1e --- libs/binder/ActivityManager.cpp | 2 +- libs/binder/AppOpsManager.cpp | 2 +- libs/binder/Binder.cpp | 2 +- libs/binder/BpBinder.cpp | 2 +- libs/binder/BufferedTextOutput.cpp | 2 +- libs/binder/Debug.cpp | 2 +- libs/binder/IActivityManager.cpp | 2 +- libs/binder/IAppOpsCallback.cpp | 2 +- libs/binder/IAppOpsService.cpp | 2 +- libs/binder/IBatteryStats.cpp | 2 +- libs/binder/IInterface.cpp | 2 +- libs/binder/IMediaResourceMonitor.cpp | 2 +- libs/binder/IMemory.cpp | 2 +- libs/binder/IPCThreadState.cpp | 2 +- libs/binder/IPermissionController.cpp | 2 +- libs/binder/IProcessInfoService.cpp | 2 +- libs/binder/IResultReceiver.cpp | 2 +- libs/binder/IServiceManager.cpp | 2 +- libs/binder/IShellCallback.cpp | 2 +- libs/binder/IUidObserver.cpp | 2 +- libs/binder/MemoryBase.cpp | 2 +- libs/binder/MemoryDealer.cpp | 2 +- libs/binder/MemoryHeapBase.cpp | 2 +- libs/binder/Parcel.cpp | 2 +- libs/binder/PermissionCache.cpp | 2 +- libs/binder/PermissionController.cpp | 2 +- libs/binder/ProcessInfoService.cpp | 2 +- libs/binder/ProcessState.cpp | 2 +- libs/binder/TextOutput.cpp | 2 +- libs/binder/include/binder/ActivityManager.h | 2 +- libs/binder/include/binder/AppOpsManager.h | 2 +- libs/binder/include/binder/Binder.h | 2 +- libs/binder/include/binder/BinderService.h | 2 +- libs/binder/include/binder/BpBinder.h | 2 +- libs/binder/include/binder/BufferedTextOutput.h | 2 +- libs/binder/include/binder/Debug.h | 2 +- libs/binder/include/binder/IActivityManager.h | 2 +- libs/binder/include/binder/IAppOpsCallback.h | 2 +- libs/binder/include/binder/IAppOpsService.h | 2 +- libs/binder/include/binder/IBatteryStats.h | 2 +- libs/binder/include/binder/IBinder.h | 2 +- libs/binder/include/binder/IInterface.h | 2 +- libs/binder/include/binder/IMediaResourceMonitor.h | 2 +- libs/binder/include/binder/IMemory.h | 2 +- libs/binder/include/binder/IPCThreadState.h | 2 +- libs/binder/include/binder/IPermissionController.h | 2 +- libs/binder/include/binder/IProcessInfoService.h | 2 +- libs/binder/include/binder/IResultReceiver.h | 2 +- libs/binder/include/binder/IServiceManager.h | 2 +- libs/binder/include/binder/IShellCallback.h | 2 +- libs/binder/include/binder/IUidObserver.h | 2 +- libs/binder/include/binder/MemoryBase.h | 2 +- libs/binder/include/binder/MemoryDealer.h | 2 +- libs/binder/include/binder/MemoryHeapBase.h | 2 +- libs/binder/include/binder/Parcel.h | 2 +- libs/binder/include/binder/PermissionCache.h | 2 +- libs/binder/include/binder/PermissionController.h | 2 +- libs/binder/include/binder/ProcessInfoService.h | 2 +- libs/binder/include/binder/ProcessState.h | 2 +- libs/binder/include/binder/TextOutput.h | 2 +- 60 files changed, 60 insertions(+), 60 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/ActivityManager.cpp b/libs/binder/ActivityManager.cpp index 49a94146db..5e4c98fc7a 100644 --- a/libs/binder/ActivityManager.cpp +++ b/libs/binder/ActivityManager.cpp @@ -114,4 +114,4 @@ status_t ActivityManager::unlinkToDeath(const sp& recip return INVALID_OPERATION; } -}; // namespace android +} // namespace android diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 711fed96a1..9da9c13e54 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -223,4 +223,4 @@ void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid, } } -}; // namespace android +} // namespace android diff --git a/libs/binder/Binder.cpp b/libs/binder/Binder.cpp index 34b6ea5385..2f6e9c3a1b 100644 --- a/libs/binder/Binder.cpp +++ b/libs/binder/Binder.cpp @@ -419,4 +419,4 @@ bool BpRefBase::onIncStrongAttempted(uint32_t /*flags*/, const void* /*id*/) // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/BpBinder.cpp b/libs/binder/BpBinder.cpp index c5aa0075ab..50c7053b13 100644 --- a/libs/binder/BpBinder.cpp +++ b/libs/binder/BpBinder.cpp @@ -491,4 +491,4 @@ void BpBinder::setBinderProxyCountWatermarks(int high, int low) { // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/BufferedTextOutput.cpp b/libs/binder/BufferedTextOutput.cpp index a7d52409f6..fb424fdcfb 100644 --- a/libs/binder/BufferedTextOutput.cpp +++ b/libs/binder/BufferedTextOutput.cpp @@ -280,4 +280,4 @@ BufferedTextOutput::BufferState* BufferedTextOutput::getBuffer() const return mGlobalState; } -}; // namespace android +} // namespace android diff --git a/libs/binder/Debug.cpp b/libs/binder/Debug.cpp index a1c2a8be08..64c1ff68c0 100644 --- a/libs/binder/Debug.cpp +++ b/libs/binder/Debug.cpp @@ -308,5 +308,5 @@ ssize_t getBinderKernelReferences(size_t count, uintptr_t* buf) { return proc->getKernelReferences(count, buf); } -}; // namespace android +} // namespace android diff --git a/libs/binder/IActivityManager.cpp b/libs/binder/IActivityManager.cpp index 377f604d44..1eb5363ae2 100644 --- a/libs/binder/IActivityManager.cpp +++ b/libs/binder/IActivityManager.cpp @@ -110,4 +110,4 @@ public: IMPLEMENT_META_INTERFACE(ActivityManager, "android.app.IActivityManager"); -}; // namespace android +} // namespace android diff --git a/libs/binder/IAppOpsCallback.cpp b/libs/binder/IAppOpsCallback.cpp index 4c151e7a65..0ce1dd59cf 100644 --- a/libs/binder/IAppOpsCallback.cpp +++ b/libs/binder/IAppOpsCallback.cpp @@ -66,4 +66,4 @@ status_t BnAppOpsCallback::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index c58ea029b3..6c16c2d044 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -309,4 +309,4 @@ status_t BnAppOpsService::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IBatteryStats.cpp b/libs/binder/IBatteryStats.cpp index cc0022a875..a47dbaccfe 100644 --- a/libs/binder/IBatteryStats.cpp +++ b/libs/binder/IBatteryStats.cpp @@ -240,4 +240,4 @@ status_t BnBatteryStats::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IInterface.cpp b/libs/binder/IInterface.cpp index 59d51ed94a..b19004d454 100644 --- a/libs/binder/IInterface.cpp +++ b/libs/binder/IInterface.cpp @@ -46,4 +46,4 @@ sp IInterface::asBinder(const sp& iface) // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/IMediaResourceMonitor.cpp b/libs/binder/IMediaResourceMonitor.cpp index 77e3d239bc..4198e49259 100644 --- a/libs/binder/IMediaResourceMonitor.cpp +++ b/libs/binder/IMediaResourceMonitor.cpp @@ -59,4 +59,4 @@ status_t BnMediaResourceMonitor::onTransact( uint32_t code, const Parcel& data, // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp index a7662e9fd2..c2bb811e9f 100644 --- a/libs/binder/IMemory.cpp +++ b/libs/binder/IMemory.cpp @@ -512,4 +512,4 @@ void HeapCache::dump_heaps() // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index c6660973f8..4981d7a111 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -1325,4 +1325,4 @@ void IPCThreadState::freeBuffer(Parcel* parcel, const uint8_t* data, state->mOut.writePointer((uintptr_t)data); } -}; // namespace android +} // namespace android diff --git a/libs/binder/IPermissionController.cpp b/libs/binder/IPermissionController.cpp index bf2f20aa0b..d9bf3cc7b6 100644 --- a/libs/binder/IPermissionController.cpp +++ b/libs/binder/IPermissionController.cpp @@ -172,4 +172,4 @@ status_t BnPermissionController::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IProcessInfoService.cpp b/libs/binder/IProcessInfoService.cpp index 96e1a8c239..a38a27ad39 100644 --- a/libs/binder/IProcessInfoService.cpp +++ b/libs/binder/IProcessInfoService.cpp @@ -88,4 +88,4 @@ IMPLEMENT_META_INTERFACE(ProcessInfoService, "android.os.IProcessInfoService"); // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/IResultReceiver.cpp b/libs/binder/IResultReceiver.cpp index 1e11941023..556288c5dd 100644 --- a/libs/binder/IResultReceiver.cpp +++ b/libs/binder/IResultReceiver.cpp @@ -65,4 +65,4 @@ status_t BnResultReceiver::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index f3e8f45909..ee637e24bf 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -285,4 +285,4 @@ private: IMPLEMENT_META_INTERFACE(ServiceManager, "android.os.IServiceManager"); -}; // namespace android +} // namespace android diff --git a/libs/binder/IShellCallback.cpp b/libs/binder/IShellCallback.cpp index 88cc603b6f..a3e2b67bc6 100644 --- a/libs/binder/IShellCallback.cpp +++ b/libs/binder/IShellCallback.cpp @@ -85,4 +85,4 @@ status_t BnShellCallback::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/IUidObserver.cpp b/libs/binder/IUidObserver.cpp index 82f9047595..038e6bf6ea 100644 --- a/libs/binder/IUidObserver.cpp +++ b/libs/binder/IUidObserver.cpp @@ -112,4 +112,4 @@ status_t BnUidObserver::onTransact( } } -}; // namespace android +} // namespace android diff --git a/libs/binder/MemoryBase.cpp b/libs/binder/MemoryBase.cpp index 033066bea3..32300dfbb6 100644 --- a/libs/binder/MemoryBase.cpp +++ b/libs/binder/MemoryBase.cpp @@ -43,4 +43,4 @@ MemoryBase::~MemoryBase() } // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/MemoryDealer.cpp b/libs/binder/MemoryDealer.cpp index eacad3b6b3..ebf91f925e 100644 --- a/libs/binder/MemoryDealer.cpp +++ b/libs/binder/MemoryDealer.cpp @@ -481,4 +481,4 @@ void SimpleBestFitAllocator::dump_l(String8& result, } -}; // namespace android +} // namespace android diff --git a/libs/binder/MemoryHeapBase.cpp b/libs/binder/MemoryHeapBase.cpp index 4c300b47c6..e4ea60f699 100644 --- a/libs/binder/MemoryHeapBase.cpp +++ b/libs/binder/MemoryHeapBase.cpp @@ -181,4 +181,4 @@ off_t MemoryHeapBase::getOffset() const { } // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 36dc810d51..d0f20fe4a7 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -2793,4 +2793,4 @@ void Parcel::Blob::clear() { mMutable = false; } -}; // namespace android +} // namespace android diff --git a/libs/binder/PermissionCache.cpp b/libs/binder/PermissionCache.cpp index a4c28ad74e..75a6d22969 100644 --- a/libs/binder/PermissionCache.cpp +++ b/libs/binder/PermissionCache.cpp @@ -110,4 +110,4 @@ bool PermissionCache::checkPermission( } // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android diff --git a/libs/binder/PermissionController.cpp b/libs/binder/PermissionController.cpp index 34b2ca5170..0c8924503d 100644 --- a/libs/binder/PermissionController.cpp +++ b/libs/binder/PermissionController.cpp @@ -85,4 +85,4 @@ int PermissionController::getPackageUid(const String16& package, int flags) return service != nullptr ? service->getPackageUid(package, flags) : -1; } -}; // namespace android +} // namespace android diff --git a/libs/binder/ProcessInfoService.cpp b/libs/binder/ProcessInfoService.cpp index 5cb2033b07..00d6eefabe 100644 --- a/libs/binder/ProcessInfoService.cpp +++ b/libs/binder/ProcessInfoService.cpp @@ -101,4 +101,4 @@ void ProcessInfoService::updateBinderLocked() { ANDROID_SINGLETON_STATIC_INSTANCE(ProcessInfoService); -}; // namespace android +} // namespace android diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp index eb828c3ce4..0336d3ebd4 100644 --- a/libs/binder/ProcessState.cpp +++ b/libs/binder/ProcessState.cpp @@ -387,4 +387,4 @@ ProcessState::~ProcessState() mDriverFD = -1; } -}; // namespace android +} // namespace android diff --git a/libs/binder/TextOutput.cpp b/libs/binder/TextOutput.cpp index 101eba318f..684a7dcc51 100644 --- a/libs/binder/TextOutput.cpp +++ b/libs/binder/TextOutput.cpp @@ -69,4 +69,4 @@ TextOutput& operator<<(TextOutput& to, const HexDump& val) return to; } -}; // namespace android +} // namespace android diff --git a/libs/binder/include/binder/ActivityManager.h b/libs/binder/include/binder/ActivityManager.h index 5f324c7965..9108e31758 100644 --- a/libs/binder/include/binder/ActivityManager.h +++ b/libs/binder/include/binder/ActivityManager.h @@ -89,7 +89,7 @@ private: }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index f5a54cea4c..0ab40b8627 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -160,7 +160,7 @@ private: }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/Binder.h b/libs/binder/include/binder/Binder.h index 5673d5a871..3be61f9409 100644 --- a/libs/binder/include/binder/Binder.h +++ b/libs/binder/include/binder/Binder.h @@ -114,7 +114,7 @@ private: std::atomic mState; }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/BinderService.h b/libs/binder/include/binder/BinderService.h index 9230e89cdf..c17ae6f5fe 100644 --- a/libs/binder/include/binder/BinderService.h +++ b/libs/binder/include/binder/BinderService.h @@ -62,6 +62,6 @@ private: }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- #endif // ANDROID_BINDER_SERVICE_H diff --git a/libs/binder/include/binder/BpBinder.h b/libs/binder/include/binder/BpBinder.h index 28599f4fc2..7dca733b52 100644 --- a/libs/binder/include/binder/BpBinder.h +++ b/libs/binder/include/binder/BpBinder.h @@ -144,7 +144,7 @@ private: static bool sBinderProxyThrottleCreate; }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/BufferedTextOutput.h b/libs/binder/include/binder/BufferedTextOutput.h index feae93dea1..1b27bb2249 100644 --- a/libs/binder/include/binder/BufferedTextOutput.h +++ b/libs/binder/include/binder/BufferedTextOutput.h @@ -62,6 +62,6 @@ private: }; // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_BUFFEREDTEXTOUTPUT_H diff --git a/libs/binder/include/binder/Debug.h b/libs/binder/include/binder/Debug.h index 58e2b32b3a..324e5c1c81 100644 --- a/libs/binder/include/binder/Debug.h +++ b/libs/binder/include/binder/Debug.h @@ -44,6 +44,6 @@ ssize_t getBinderKernelReferences(size_t count, uintptr_t* buf); __END_DECLS // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_BINDER_DEBUG_H diff --git a/libs/binder/include/binder/IActivityManager.h b/libs/binder/include/binder/IActivityManager.h index 6abc071c45..e0248f6624 100644 --- a/libs/binder/include/binder/IActivityManager.h +++ b/libs/binder/include/binder/IActivityManager.h @@ -51,7 +51,7 @@ public: // ------------------------------------------------------------------------------------ -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IAppOpsCallback.h b/libs/binder/include/binder/IAppOpsCallback.h index b500219e37..76642606fc 100644 --- a/libs/binder/include/binder/IAppOpsCallback.h +++ b/libs/binder/include/binder/IAppOpsCallback.h @@ -52,7 +52,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 978400304e..8b8a3c21ce 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -88,6 +88,6 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_IAPP_OPS_SERVICE_H diff --git a/libs/binder/include/binder/IBatteryStats.h b/libs/binder/include/binder/IBatteryStats.h index 48da865702..b786f89f74 100644 --- a/libs/binder/include/binder/IBatteryStats.h +++ b/libs/binder/include/binder/IBatteryStats.h @@ -77,7 +77,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IBinder.h b/libs/binder/include/binder/IBinder.h index b12723446d..64f305274b 100644 --- a/libs/binder/include/binder/IBinder.h +++ b/libs/binder/include/binder/IBinder.h @@ -242,7 +242,7 @@ protected: private: }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/IInterface.h b/libs/binder/include/binder/IInterface.h index 0d305608ca..5793a1cf6b 100644 --- a/libs/binder/include/binder/IInterface.h +++ b/libs/binder/include/binder/IInterface.h @@ -168,6 +168,6 @@ inline IBinder* BpInterface::onAsBinder() // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_IINTERFACE_H diff --git a/libs/binder/include/binder/IMediaResourceMonitor.h b/libs/binder/include/binder/IMediaResourceMonitor.h index 213ee63ea8..da2b7cf62d 100644 --- a/libs/binder/include/binder/IMediaResourceMonitor.h +++ b/libs/binder/include/binder/IMediaResourceMonitor.h @@ -52,7 +52,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IMemory.h b/libs/binder/include/binder/IMemory.h index 8791741f48..1a36eb0436 100644 --- a/libs/binder/include/binder/IMemory.h +++ b/libs/binder/include/binder/IMemory.h @@ -123,6 +123,6 @@ protected: // ---------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_IMEMORY_H diff --git a/libs/binder/include/binder/IPCThreadState.h b/libs/binder/include/binder/IPCThreadState.h index b810f7e8ee..ff9244e08a 100644 --- a/libs/binder/include/binder/IPCThreadState.h +++ b/libs/binder/include/binder/IPCThreadState.h @@ -196,7 +196,7 @@ private: ProcessState::CallRestriction mCallRestriction; }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/IPermissionController.h b/libs/binder/include/binder/IPermissionController.h index 26a1b23a9a..4b66df8d6e 100644 --- a/libs/binder/include/binder/IPermissionController.h +++ b/libs/binder/include/binder/IPermissionController.h @@ -65,7 +65,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IProcessInfoService.h b/libs/binder/include/binder/IProcessInfoService.h index 033c145363..ca30ad3b95 100644 --- a/libs/binder/include/binder/IProcessInfoService.h +++ b/libs/binder/include/binder/IProcessInfoService.h @@ -46,7 +46,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/IResultReceiver.h b/libs/binder/include/binder/IResultReceiver.h index 00b3d8954c..70e99e7c38 100644 --- a/libs/binder/include/binder/IResultReceiver.h +++ b/libs/binder/include/binder/IResultReceiver.h @@ -50,7 +50,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_IRESULT_RECEIVER_H diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h index 8ae860df38..def1bea974 100644 --- a/libs/binder/include/binder/IServiceManager.h +++ b/libs/binder/include/binder/IServiceManager.h @@ -104,7 +104,7 @@ bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t* outUid); bool checkPermission(const String16& permission, pid_t pid, uid_t uid); -}; // namespace android +} // namespace android #endif // ANDROID_ISERVICE_MANAGER_H diff --git a/libs/binder/include/binder/IShellCallback.h b/libs/binder/include/binder/IShellCallback.h index 67156787d3..b7ab6eab88 100644 --- a/libs/binder/include/binder/IShellCallback.h +++ b/libs/binder/include/binder/IShellCallback.h @@ -51,7 +51,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_ISHELL_CALLBACK_H diff --git a/libs/binder/include/binder/IUidObserver.h b/libs/binder/include/binder/IUidObserver.h index a1f530dc71..09e50a9de8 100644 --- a/libs/binder/include/binder/IUidObserver.h +++ b/libs/binder/include/binder/IUidObserver.h @@ -58,7 +58,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/MemoryBase.h b/libs/binder/include/binder/MemoryBase.h index 463e26d977..4dd363808c 100644 --- a/libs/binder/include/binder/MemoryBase.h +++ b/libs/binder/include/binder/MemoryBase.h @@ -46,6 +46,6 @@ private: }; // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_MEMORY_BASE_H diff --git a/libs/binder/include/binder/MemoryDealer.h b/libs/binder/include/binder/MemoryDealer.h index b483be0fd5..6c1c4122d8 100644 --- a/libs/binder/include/binder/MemoryDealer.h +++ b/libs/binder/include/binder/MemoryDealer.h @@ -59,6 +59,6 @@ private: // ---------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_MEMORY_DEALER_H diff --git a/libs/binder/include/binder/MemoryHeapBase.h b/libs/binder/include/binder/MemoryHeapBase.h index 100d784a83..3fccddcc59 100644 --- a/libs/binder/include/binder/MemoryHeapBase.h +++ b/libs/binder/include/binder/MemoryHeapBase.h @@ -98,6 +98,6 @@ private: }; // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_MEMORY_HEAP_BASE_H diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index 3471e1356d..87266819e6 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -921,7 +921,7 @@ inline TextOutput& operator<<(TextOutput& to, const Parcel& parcel) return to; } -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/PermissionCache.h b/libs/binder/include/binder/PermissionCache.h index 95eabff7ac..c2582150df 100644 --- a/libs/binder/include/binder/PermissionCache.h +++ b/libs/binder/include/binder/PermissionCache.h @@ -77,7 +77,7 @@ public: }; // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/PermissionController.h b/libs/binder/include/binder/PermissionController.h index d81f5142bc..4db522ab1f 100644 --- a/libs/binder/include/binder/PermissionController.h +++ b/libs/binder/include/binder/PermissionController.h @@ -60,7 +60,7 @@ private: }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/ProcessInfoService.h b/libs/binder/include/binder/ProcessInfoService.h index a03aae98ee..6bfd1bc17d 100644 --- a/libs/binder/include/binder/ProcessInfoService.h +++ b/libs/binder/include/binder/ProcessInfoService.h @@ -78,7 +78,7 @@ public: // ---------------------------------------------------------------------- -}; // namespace android +} // namespace android #else // __ANDROID_VNDK__ #error "This header is not visible to vendors" diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h index 8339976567..f7c38f418d 100644 --- a/libs/binder/include/binder/ProcessState.h +++ b/libs/binder/include/binder/ProcessState.h @@ -126,7 +126,7 @@ private: CallRestriction mCallRestriction; }; -}; // namespace android +} // namespace android // --------------------------------------------------------------------------- diff --git a/libs/binder/include/binder/TextOutput.h b/libs/binder/include/binder/TextOutput.h index 5b5f76688b..f66406f7d4 100644 --- a/libs/binder/include/binder/TextOutput.h +++ b/libs/binder/include/binder/TextOutput.h @@ -199,6 +199,6 @@ inline size_t HexDump::alignment() const { return mAlignment; } inline bool HexDump::carrayStyle() const { return mCArrayStyle; } // --------------------------------------------------------------------------- -}; // namespace android +} // namespace android #endif // ANDROID_TEXTOUTPUT_H -- cgit v1.2.3-59-g8ed1b From b13018865ef7b1a7b4f59bafe70b6d93069e97ab Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Fri, 6 Sep 2019 11:01:18 -0700 Subject: Note appOps with featureIds from native code Test: atest CtsAppOpsTestCases Bug: 136595429 Change-Id: I31cc35134035d19aa7b98567fd998ff7f406b271 --- libs/binder/AppOpsManager.cpp | 33 +++++++++++++++++++---------- libs/binder/IAppOpsService.cpp | 14 ++++++++++-- libs/binder/include/binder/AppOpsManager.h | 15 +++++++------ libs/binder/include/binder/IAppOpsService.h | 3 ++- 4 files changed, 44 insertions(+), 21 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 9da9c13e54..60f047fd90 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -115,18 +115,23 @@ int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t ui } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { - return noteOp(op, uid, callingPackage, String16("noteOp from native code")); + return noteOp(op, uid, callingPackage, String16(), String16()); } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const String16& message) { + const String16& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr ? service->noteOperation(op, uid, callingPackage) : APP_OPS_MANAGER_UNAVAILABLE_MODE; if (mode == AppOpsManager::MODE_ALLOWED) { - markAppOpNoted(uid, callingPackage, op, message); + if (message.size() == 0) { + markAppOpNoted(uid, callingPackage, op, featureId, + String16("noteOp from native code")); + } else { + markAppOpNoted(uid, callingPackage, op, featureId, message); + } } return mode; @@ -134,19 +139,23 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault) { - return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, - String16("startOpNoThrow from native code")); + return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, String16(), String16()); } int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const String16& message) { + bool startIfModeDefault, const String16& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr ? service->startOperation(getToken(service), op, uid, callingPackage, startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; if (mode == AppOpsManager::MODE_ALLOWED) { - markAppOpNoted(uid, callingPackage, op, message); + if (message.size() == 0) { + markAppOpNoted(uid, callingPackage, op, featureId, + String16("startOp from native code")); + } else { + markAppOpNoted(uid, callingPackage, op, featureId, message); + } } return mode; @@ -198,7 +207,7 @@ bool AppOpsManager::shouldCollectNotes(int32_t opcode) { } void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const String16& message) { + const String16& featureId, const String16& message) { // check it the appops needs to be collected and cache result if (appOpsToNote[opCode] == 0) { if (shouldCollectNotes(opCode)) { @@ -212,14 +221,16 @@ void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int return; } - noteAsyncOp(String16(), uid, packageName, opCode, message); + noteAsyncOp(String16(), uid, packageName, opCode, featureId, message); } void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& message) { + const String16& packageName, int32_t opCode, const String16& featureId, + const String16& message) { sp service = getService(); if (service != nullptr) { - return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, message); + return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, + message); } } diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 6c16c2d044..9760e135a1 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -145,7 +145,8 @@ public: } virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& message) { + const String16& packageName, int32_t opCode, const String16& featureId, + const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -166,6 +167,14 @@ public: } data.writeInt32(opCode); + + // Convert empty featureId into null string + if (featureId.size() != 0) { + data.writeString16(featureId); + } else { + data.writeString16(nullptr, 0); + } + data.writeString16(message); remote()->transact(NOTE_ASYNC_OP_TRANSACTION, data, &reply); } @@ -291,8 +300,9 @@ status_t BnAppOpsService::onTransact( int32_t uid = data.readInt32(); String16 packageName = data.readString16(); int32_t opCode = data.readInt32(); + String16 featureId = data.readString16(); String16 message = data.readString16(); - noteAsyncOp(callingPackageName, uid, packageName, opCode, message); + noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, message); reply->writeNoException(); return NO_ERROR; } break; diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index 0ab40b8627..2744ce126d 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -130,16 +130,17 @@ public: int32_t checkOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid, const String16& callingPackage); - // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&) instead + // @Deprecated, use noteOp(int32_t, int32_t uid, const String16&, const String16&, + // const String16&) instead int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const String16& message); - // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&) - // instead + const String16& featureId, const String16& message); + // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&, + // const String16&) instead int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault); int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const String16& message); + bool startIfModeDefault, const String16& featureId, const String16& message); void finishOp(int32_t op, int32_t uid, const String16& callingPackage); void startWatchingMode(int32_t op, const String16& packageName, const sp& callback); @@ -147,7 +148,7 @@ public: int32_t permissionToOpCode(const String16& permission); void setCameraAudioRestriction(int32_t mode); void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, - int32_t opCode, const String16& message); + int32_t opCode, const String16& featureId, const String16& message); private: Mutex mLock; @@ -155,7 +156,7 @@ private: sp getService(); void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const String16& message); + const String16& featureId, const String16& message); bool shouldCollectNotes(int32_t opCode); }; diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 8b8a3c21ce..ad34bc5692 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -49,7 +49,8 @@ public: const String16& packageName) = 0; virtual void setCameraAudioRestriction(int32_t mode) = 0; virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& message) = 0; + const String16& packageName, int32_t opCode, const String16& featureId, + const String16& message) = 0; virtual bool shouldCollectNotes(int32_t opCode) = 0; enum { -- cgit v1.2.3-59-g8ed1b From aeaaf1c2805dd4e51dedbafb705db0f7b44b443a Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Tue, 5 Nov 2019 12:34:36 -0800 Subject: Allow null featureIds in AppOpsService binder calls Bug: 136595429 Test: atest CtsAppOpsTestCases Change-Id: I48713e962e3c3b60bd31ef134712a1d2f3da7cf5 --- libs/binder/AppOpsManager.cpp | 44 ++++++++++----------- libs/binder/IAppOpsService.cpp | 61 +++++++++++++---------------- libs/binder/include/binder/AppOpsManager.h | 15 ++++--- libs/binder/include/binder/IAppOpsService.h | 12 +++--- 4 files changed, 65 insertions(+), 67 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 60f047fd90..4f0b7d31a2 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -115,23 +115,19 @@ int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t ui } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { - return noteOp(op, uid, callingPackage, String16(), String16()); + return noteOp(op, uid, callingPackage, std::unique_ptr(), + String16("Legacy AppOpsManager.noteOp call")); } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const String16& featureId, const String16& message) { + const std::unique_ptr& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr - ? service->noteOperation(op, uid, callingPackage) + ? service->noteOperation(op, uid, callingPackage, featureId) : APP_OPS_MANAGER_UNAVAILABLE_MODE; if (mode == AppOpsManager::MODE_ALLOWED) { - if (message.size() == 0) { - markAppOpNoted(uid, callingPackage, op, featureId, - String16("noteOp from native code")); - } else { - markAppOpNoted(uid, callingPackage, op, featureId, message); - } + markAppOpNoted(uid, callingPackage, op, featureId, message); } return mode; @@ -139,32 +135,34 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault) { - return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, String16(), String16()); + return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, std::unique_ptr(), + String16("Legacy AppOpsManager.startOpNoThrow call")); } int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const String16& featureId, const String16& message) { + bool startIfModeDefault, const std::unique_ptr& featureId, + const String16& message) { sp service = getService(); int32_t mode = service != nullptr ? service->startOperation(getToken(service), op, uid, callingPackage, - startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; + featureId, startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; if (mode == AppOpsManager::MODE_ALLOWED) { - if (message.size() == 0) { - markAppOpNoted(uid, callingPackage, op, featureId, - String16("startOp from native code")); - } else { - markAppOpNoted(uid, callingPackage, op, featureId, message); - } + markAppOpNoted(uid, callingPackage, op, featureId, message); } return mode; } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) { + finishOp(op, uid, callingPackage, std::unique_ptr()); +} + +void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage, + const std::unique_ptr& callingFeatureId) { sp service = getService(); if (service != nullptr) { - service->finishOperation(getToken(service), op, uid, callingPackage); + service->finishOperation(getToken(service), op, uid, callingPackage, callingFeatureId); } } @@ -207,7 +205,7 @@ bool AppOpsManager::shouldCollectNotes(int32_t opcode) { } void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const String16& featureId, const String16& message) { + const std::unique_ptr& featureId, const String16& message) { // check it the appops needs to be collected and cache result if (appOpsToNote[opCode] == 0) { if (shouldCollectNotes(opCode)) { @@ -221,11 +219,11 @@ void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int return; } - noteAsyncOp(String16(), uid, packageName, opCode, featureId, message); + noteAsyncOp(std::unique_ptr(), uid, packageName, opCode, featureId, message); } -void AppOpsManager::noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& featureId, +void AppOpsManager::noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, + const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, const String16& message) { sp service = getService(); if (service != nullptr) { diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 9760e135a1..b85a5f298e 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -46,12 +46,14 @@ public: return reply.readInt32(); } - virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) { + virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, + const std::unique_ptr& featureId) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); + data.writeString16(featureId); remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply); // fail on exception if (reply.readExceptionCode() != 0) return MODE_ERRORED; @@ -59,13 +61,15 @@ public: } virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, bool startIfModeDefault) { + const String16& packageName, const std::unique_ptr& featureId, + bool startIfModeDefault) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeStrongBinder(token); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); + data.writeString16(featureId); data.writeInt32(startIfModeDefault ? 1 : 0); remote()->transact(START_OPERATION_TRANSACTION, data, &reply); // fail on exception @@ -74,13 +78,14 @@ public: } virtual void finishOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName) { + const String16& packageName, const std::unique_ptr& featureId) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeStrongBinder(token); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); + data.writeString16(featureId); remote()->transact(FINISH_OPERATION_TRANSACTION, data, &reply); } @@ -144,37 +149,16 @@ public: remote()->transact(SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION, data, &reply); } - virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& featureId, + virtual void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, + const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); - - // Convert empty callingPackage into null string - if (callingPackageName.size() != 0) { - data.writeString16(callingPackageName); - } else { - data.writeString16(nullptr, 0); - } - + data.writeString16(callingPackageName); data.writeInt32(uid); - - // Convert empty packageName into null string - if (packageName.size() != 0) { - data.writeString16(packageName); - } else { - data.writeString16(nullptr, 0); - } - + data.writeString16(packageName); data.writeInt32(opCode); - - // Convert empty featureId into null string - if (featureId.size() != 0) { - data.writeString16(featureId); - } else { - data.writeString16(nullptr, 0); - } - + data.writeString16(featureId); data.writeString16(message); remote()->transact(NOTE_ASYNC_OP_TRANSACTION, data, &reply); } @@ -217,7 +201,9 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - int32_t res = noteOperation(code, uid, packageName); + std::unique_ptr featureId; + data.readString16(&featureId); + int32_t res = noteOperation(code, uid, packageName, featureId); reply->writeNoException(); reply->writeInt32(res); return NO_ERROR; @@ -228,8 +214,11 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); + std::unique_ptr featureId; + data.readString16(&featureId); bool startIfModeDefault = data.readInt32() == 1; - int32_t res = startOperation(token, code, uid, packageName, startIfModeDefault); + int32_t res = startOperation(token, code, uid, packageName, featureId, + startIfModeDefault); reply->writeNoException(); reply->writeInt32(res); return NO_ERROR; @@ -240,7 +229,9 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - finishOperation(token, code, uid, packageName); + std::unique_ptr featureId; + data.readString16(&featureId); + finishOperation(token, code, uid, packageName, featureId); reply->writeNoException(); return NO_ERROR; } break; @@ -296,11 +287,13 @@ status_t BnAppOpsService::onTransact( } break; case NOTE_ASYNC_OP_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); - String16 callingPackageName = data.readString16(); + std::unique_ptr callingPackageName; + data.readString16(&callingPackageName); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); int32_t opCode = data.readInt32(); - String16 featureId = data.readString16(); + std::unique_ptr featureId; + data.readString16(&featureId); String16 message = data.readString16(); noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, message); reply->writeNoException(); diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index 2744ce126d..22a017941e 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -134,21 +134,26 @@ public: // const String16&) instead int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const String16& featureId, const String16& message); + const std::unique_ptr& featureId, const String16& message); // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&, // const String16&) instead int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault); int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const String16& featureId, const String16& message); + bool startIfModeDefault, const std::unique_ptr& featureId, + const String16& message); + // @Deprecated, use finishOp(int32_t, int32_t, const String16&, bool, const String16&) instead void finishOp(int32_t op, int32_t uid, const String16& callingPackage); + void finishOp(int32_t op, int32_t uid, const String16& callingPackage, + const std::unique_ptr& featureId); void startWatchingMode(int32_t op, const String16& packageName, const sp& callback); void stopWatchingMode(const sp& callback); int32_t permissionToOpCode(const String16& permission); void setCameraAudioRestriction(int32_t mode); - void noteAsyncOp(const String16& callingPackageName, int32_t uid, const String16& packageName, - int32_t opCode, const String16& featureId, const String16& message); + void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, + const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, + const String16& message); private: Mutex mLock; @@ -156,7 +161,7 @@ private: sp getService(); void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const String16& featureId, const String16& message); + const std::unique_ptr& featureId, const String16& message); bool shouldCollectNotes(int32_t opCode); }; diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index ad34bc5692..15ba005cec 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -35,11 +35,13 @@ public: DECLARE_META_INTERFACE(AppOpsService) virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; - virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName) = 0; + virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, + const std::unique_ptr& featureId) = 0; virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, bool startIfModeDefault) = 0; + const String16& packageName, const std::unique_ptr& featureId, + bool startIfModeDefault) = 0; virtual void finishOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName) = 0; + const String16& packageName, const std::unique_ptr& featureId) = 0; virtual void startWatchingMode(int32_t op, const String16& packageName, const sp& callback) = 0; virtual void stopWatchingMode(const sp& callback) = 0; @@ -48,8 +50,8 @@ public: virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, const String16& packageName) = 0; virtual void setCameraAudioRestriction(int32_t mode) = 0; - virtual void noteAsyncOp(const String16& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const String16& featureId, + virtual void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, + const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, const String16& message) = 0; virtual bool shouldCollectNotes(int32_t opCode) = 0; -- cgit v1.2.3-59-g8ed1b From c52e1fcc8b91801831da53ed474c33fa1eef2c00 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Tue, 26 Nov 2019 15:18:09 -0800 Subject: Create local clientId instead of sharing one Bug: 144997947 Test: TH Change-Id: I767036b0acd3e5b6fb866dfef6ef5fdceb8f12de --- libs/binder/AppOpsManager.cpp | 20 ++++++++++---------- libs/binder/IAppOpsService.cpp | 18 ------------------ libs/binder/include/binder/IAppOpsService.h | 12 +++++------- 3 files changed, 15 insertions(+), 35 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index 4f0b7d31a2..ca9c6087c9 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -44,16 +44,16 @@ const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; } // namespace static String16 _appops("appops"); -static pthread_mutex_t gTokenMutex = PTHREAD_MUTEX_INITIALIZER; -static sp gToken; +static pthread_mutex_t gClientIdMutex = PTHREAD_MUTEX_INITIALIZER; +static sp gClientId; -static const sp& getToken(const sp& service) { - pthread_mutex_lock(&gTokenMutex); - if (gToken == nullptr || gToken->pingBinder() != NO_ERROR) { - gToken = service->getToken(new BBinder()); +static const sp& getClientId() { + pthread_mutex_lock(&gClientIdMutex); + if (gClientId == nullptr) { + gClientId = new BBinder(); } - pthread_mutex_unlock(&gTokenMutex); - return gToken; + pthread_mutex_unlock(&gClientIdMutex); + return gClientId; } thread_local uint64_t notedAppOpsInThisBinderTransaction[2]; @@ -144,7 +144,7 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c const String16& message) { sp service = getService(); int32_t mode = service != nullptr - ? service->startOperation(getToken(service), op, uid, callingPackage, + ? service->startOperation(getClientId(), op, uid, callingPackage, featureId, startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; if (mode == AppOpsManager::MODE_ALLOWED) { @@ -162,7 +162,7 @@ void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPac const std::unique_ptr& callingFeatureId) { sp service = getService(); if (service != nullptr) { - service->finishOperation(getToken(service), op, uid, callingPackage, callingFeatureId); + service->finishOperation(getClientId(), op, uid, callingPackage, callingFeatureId); } } diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index b85a5f298e..7384466b55 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -106,16 +106,6 @@ public: remote()->transact(STOP_WATCHING_MODE_TRANSACTION, data, &reply); } - virtual sp getToken(const sp& clientToken) { - Parcel data, reply; - data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); - data.writeStrongBinder(clientToken); - remote()->transact(GET_TOKEN_TRANSACTION, data, &reply); - // fail on exception - if (reply.readExceptionCode() != 0) return nullptr; - return reply.readStrongBinder(); - } - virtual int32_t permissionToOpCode(const String16& permission) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -251,14 +241,6 @@ status_t BnAppOpsService::onTransact( reply->writeNoException(); return NO_ERROR; } break; - case GET_TOKEN_TRANSACTION: { - CHECK_INTERFACE(IAppOpsService, data, reply); - sp clientToken = data.readStrongBinder(); - sp token = getToken(clientToken); - reply->writeNoException(); - reply->writeStrongBinder(token); - return NO_ERROR; - } break; case PERMISSION_TO_OP_CODE_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); String16 permission = data.readString16(); diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 15ba005cec..68a917e471 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -45,7 +45,6 @@ public: virtual void startWatchingMode(int32_t op, const String16& packageName, const sp& callback) = 0; virtual void stopWatchingMode(const sp& callback) = 0; - virtual sp getToken(const sp& clientToken) = 0; virtual int32_t permissionToOpCode(const String16& permission) = 0; virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, const String16& packageName) = 0; @@ -62,12 +61,11 @@ public: FINISH_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+3, START_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+4, STOP_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+5, - GET_TOKEN_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6, - PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7, - CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, - NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, - SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10, - SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+11, + PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6, + CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7, + NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, + SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, + SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10, }; enum { -- cgit v1.2.3-59-g8ed1b From 3879cf6939e5fb177ff08328a000dd1ec4c6ffc8 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Fri, 20 Dec 2019 11:22:37 -0800 Subject: Collect AsyncNotedAppOp in same call as native noteOp This reduces the overhead of collecting noted app-ops Exempt-From-Owner-Approval: minor change Bug: 136505050 Test: atest CtsAppOpsTestCases Change-Id: I05a186b772b337219f9e70123a89a15f1e88dd15 --- libs/binder/AppOpsManager.cpp | 49 ++++++----------------------- libs/binder/IAppOpsService.cpp | 46 +++++++++------------------ libs/binder/include/binder/AppOpsManager.h | 5 --- libs/binder/include/binder/IAppOpsService.h | 13 +++----- 4 files changed, 29 insertions(+), 84 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index ca9c6087c9..aeca12b582 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -123,13 +123,10 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa const std::unique_ptr& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr - ? service->noteOperation(op, uid, callingPackage, featureId) + ? service->noteOperation(op, uid, callingPackage, featureId, shouldCollectNotes(op), + message) : APP_OPS_MANAGER_UNAVAILABLE_MODE; - if (mode == AppOpsManager::MODE_ALLOWED) { - markAppOpNoted(uid, callingPackage, op, featureId, message); - } - return mode; } @@ -145,11 +142,8 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c sp service = getService(); int32_t mode = service != nullptr ? service->startOperation(getClientId(), op, uid, callingPackage, - featureId, startIfModeDefault) : APP_OPS_MANAGER_UNAVAILABLE_MODE; - - if (mode == AppOpsManager::MODE_ALLOWED) { - markAppOpNoted(uid, callingPackage, op, featureId, message); - } + featureId, startIfModeDefault, shouldCollectNotes(op), message) + : APP_OPS_MANAGER_UNAVAILABLE_MODE; return mode; } @@ -196,40 +190,17 @@ void AppOpsManager::setCameraAudioRestriction(int32_t mode) { } } +// check it the appops needs to be collected and cache result bool AppOpsManager::shouldCollectNotes(int32_t opcode) { - sp service = getService(); - if (service != nullptr) { - return service->shouldCollectNotes(opcode); - } - return false; -} - -void AppOpsManager::markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const std::unique_ptr& featureId, const String16& message) { - // check it the appops needs to be collected and cache result - if (appOpsToNote[opCode] == 0) { - if (shouldCollectNotes(opCode)) { - appOpsToNote[opCode] = 2; + if (appOpsToNote[opcode] == 0) { + if (getService()->shouldCollectNotes(opcode)) { + appOpsToNote[opcode] = 2; } else { - appOpsToNote[opCode] = 1; + appOpsToNote[opcode] = 1; } } - if (appOpsToNote[opCode] != 2) { - return; - } - - noteAsyncOp(std::unique_ptr(), uid, packageName, opCode, featureId, message); -} - -void AppOpsManager::noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, - const String16& message) { - sp service = getService(); - if (service != nullptr) { - return service->noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, - message); - } + return appOpsToNote[opcode] == 2; } } // namespace android diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 7384466b55..a5555a304f 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -47,13 +47,16 @@ public: } virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::unique_ptr& featureId) { + const std::unique_ptr& featureId, bool shouldCollectAsyncNotedOp, + const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); data.writeString16(featureId); + data.writeInt32(shouldCollectAsyncNotedOp ? 1 : 0); + data.writeString16(message); remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply); // fail on exception if (reply.readExceptionCode() != 0) return MODE_ERRORED; @@ -62,7 +65,7 @@ public: virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr& featureId, - bool startIfModeDefault) { + bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeStrongBinder(token); @@ -71,6 +74,8 @@ public: data.writeString16(packageName); data.writeString16(featureId); data.writeInt32(startIfModeDefault ? 1 : 0); + data.writeInt32(shouldCollectAsyncNotedOp ? 1 : 0); + data.writeString16(message); remote()->transact(START_OPERATION_TRANSACTION, data, &reply); // fail on exception if (reply.readExceptionCode() != 0) return MODE_ERRORED; @@ -139,20 +144,6 @@ public: remote()->transact(SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION, data, &reply); } - virtual void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, - const String16& message) { - Parcel data, reply; - data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); - data.writeString16(callingPackageName); - data.writeInt32(uid); - data.writeString16(packageName); - data.writeInt32(opCode); - data.writeString16(featureId); - data.writeString16(message); - remote()->transact(NOTE_ASYNC_OP_TRANSACTION, data, &reply); - } - virtual bool shouldCollectNotes(int32_t opCode) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -193,7 +184,10 @@ status_t BnAppOpsService::onTransact( String16 packageName = data.readString16(); std::unique_ptr featureId; data.readString16(&featureId); - int32_t res = noteOperation(code, uid, packageName, featureId); + bool shouldCollectAsyncNotedOp = data.readInt32() == 1; + String16 message = data.readString16(); + int32_t res = noteOperation(code, uid, packageName, featureId, + shouldCollectAsyncNotedOp, message); reply->writeNoException(); reply->writeInt32(res); return NO_ERROR; @@ -207,8 +201,10 @@ status_t BnAppOpsService::onTransact( std::unique_ptr featureId; data.readString16(&featureId); bool startIfModeDefault = data.readInt32() == 1; + bool shouldCollectAsyncNotedOp = data.readInt32() == 1; + String16 message = data.readString16(); int32_t res = startOperation(token, code, uid, packageName, featureId, - startIfModeDefault); + startIfModeDefault, shouldCollectAsyncNotedOp, message); reply->writeNoException(); reply->writeInt32(res); return NO_ERROR; @@ -267,20 +263,6 @@ status_t BnAppOpsService::onTransact( reply->writeNoException(); return NO_ERROR; } break; - case NOTE_ASYNC_OP_TRANSACTION: { - CHECK_INTERFACE(IAppOpsService, data, reply); - std::unique_ptr callingPackageName; - data.readString16(&callingPackageName); - int32_t uid = data.readInt32(); - String16 packageName = data.readString16(); - int32_t opCode = data.readInt32(); - std::unique_ptr featureId; - data.readString16(&featureId); - String16 message = data.readString16(); - noteAsyncOp(callingPackageName, uid, packageName, opCode, featureId, message); - reply->writeNoException(); - return NO_ERROR; - } break; case SHOULD_COLLECT_NOTES_TRANSACTION: { CHECK_INTERFACE(IAppOpsService, data, reply); int32_t opCode = data.readInt32(); diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index 22a017941e..5b6eb6863e 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -151,17 +151,12 @@ public: void stopWatchingMode(const sp& callback); int32_t permissionToOpCode(const String16& permission); void setCameraAudioRestriction(int32_t mode); - void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, - const String16& message); private: Mutex mLock; sp mService; sp getService(); - void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const std::unique_ptr& featureId, const String16& message); bool shouldCollectNotes(int32_t opCode); }; diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 68a917e471..1b4bcce20f 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -36,10 +36,11 @@ public: virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::unique_ptr& featureId) = 0; + const std::unique_ptr& featureId, bool shouldCollectAsyncNotedOp, + const String16& message) = 0; virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr& featureId, - bool startIfModeDefault) = 0; + bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual void finishOperation(const sp& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr& featureId) = 0; virtual void startWatchingMode(int32_t op, const String16& packageName, @@ -49,9 +50,6 @@ public: virtual int32_t checkAudioOperation(int32_t code, int32_t usage,int32_t uid, const String16& packageName) = 0; virtual void setCameraAudioRestriction(int32_t mode) = 0; - virtual void noteAsyncOp(const std::unique_ptr& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr& featureId, - const String16& message) = 0; virtual bool shouldCollectNotes(int32_t opCode) = 0; enum { @@ -63,9 +61,8 @@ public: STOP_WATCHING_MODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+5, PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6, CHECK_AUDIO_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+7, - NOTE_ASYNC_OP_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, - SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, - SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+10, + SHOULD_COLLECT_NOTES_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+8, + SET_CAMERA_AUDIO_RESTRICTION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+9, }; enum { -- cgit v1.2.3-59-g8ed1b From 2d5878e69b6df009a936ab29710ef00673bb7b0a Mon Sep 17 00:00:00 2001 From: Jooyung Han Date: Thu, 23 Jan 2020 12:45:10 +0900 Subject: 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, we should do "unique_ptr(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 Merged-In: I2c801e3b69f2f8ccf44267f15cbf79e1d8fbf19e Change-Id: I2c801e3b69f2f8ccf44267f15cbf79e1d8fbf19e (cherry picked from commit 149be4a25ef423491c73dfc7bfd95e8177e9b4f8) Exempt-From-Owner-Approval: CP from master --- cmds/installd/CrateManager.cpp | 24 +-- cmds/installd/CrateManager.h | 10 +- cmds/installd/InstalldNativeService.cpp | 129 ++++++----- cmds/installd/InstalldNativeService.h | 78 +++---- cmds/installd/dexopt.cpp | 12 +- cmds/installd/dexopt.h | 8 +- cmds/installd/tests/installd_cache_test.cpp | 5 +- cmds/installd/tests/installd_dexopt_test.cpp | 64 +++--- cmds/installd/tests/installd_service_test.cpp | 39 ++-- libs/binder/AppOpsManager.cpp | 12 +- libs/binder/IAppOpsService.cpp | 14 +- libs/binder/Parcel.cpp | 207 ++++++++++++++++++ libs/binder/include/binder/AppOpsManager.h | 8 +- libs/binder/include/binder/IAppOpsService.h | 8 +- libs/binder/include/binder/Parcel.h | 250 +++++++++++++++++++++- libs/binder/include/binder/ParcelFileDescriptor.h | 1 + 16 files changed, 658 insertions(+), 211 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/cmds/installd/CrateManager.cpp b/cmds/installd/CrateManager.cpp index 6e079ebbf3..b17cba15d5 100644 --- a/cmds/installd/CrateManager.cpp +++ b/cmds/installd/CrateManager.cpp @@ -86,7 +86,7 @@ void CrateManager::traverseChildDir(const std::string& targetDir, } void CrateManager::traverseAllPackagesForUser( - const std::unique_ptr& uuid, userid_t userId, + const std::optional& uuid, userid_t userId, std::function& onHandlingPackage) { const char* uuid_ = uuid ? uuid->c_str() : nullptr; @@ -96,21 +96,21 @@ void CrateManager::traverseAllPackagesForUser( void CrateManager::createCrate( CratedFolder cratedFolder, - std::function&)>& onCreateCrate) { + std::function& onCreateCrate) { const char* path = cratedFolder->fts_path; if (path == nullptr || *path == '\0') { return; } - std::unique_ptr crateMetadata = std::make_unique(); - crateMetadata->uid = cratedFolder->fts_statp->st_uid; - crateMetadata->packageName = mPackageName; - crateMetadata->id = getValidatedCratedPath(path); + CrateMetadata crateMetadata; + crateMetadata.uid = cratedFolder->fts_statp->st_uid; + crateMetadata.packageName = mPackageName; + crateMetadata.id = getValidatedCratedPath(path); - onCreateCrate(cratedFolder, crateMetadata); + onCreateCrate(cratedFolder, std::move(crateMetadata)); } -void CrateManager::traverseAllCrates(std::function&)>& onCreateCrate) { +void CrateManager::traverseAllCrates(std::function& onCreateCrate) { std::function onVisitCrateDir = [&](FTSENT* cratedFolder) -> void { createCrate(cratedFolder, onCreateCrate); }; @@ -118,11 +118,11 @@ void CrateManager::traverseAllCrates(std::function& CrateMetadata) { +void CrateManager::dump(const CrateMetadata& CrateMetadata) { LOG(DEBUG) << "CrateMetadata = {" - << "uid : \"" << CrateMetadata->uid - << "\", packageName : \"" << CrateMetadata->packageName - << "\", id : \"" << CrateMetadata->id + << "uid : \"" << CrateMetadata.uid + << "\", packageName : \"" << CrateMetadata.packageName + << "\", id : \"" << CrateMetadata.id << "\"}"; } #endif diff --git a/cmds/installd/CrateManager.h b/cmds/installd/CrateManager.h index 4332d4cbc9..1f30b5dc79 100644 --- a/cmds/installd/CrateManager.h +++ b/cmds/installd/CrateManager.h @@ -25,7 +25,7 @@ #include #include -#include +#include #include #include @@ -55,18 +55,18 @@ public: CrateManager(const char* uuid, userid_t userId, const std::string& packageName); ~CrateManager(); - void traverseAllCrates(std::function&)>& onCreateCrate); + void traverseAllCrates(std::function& onCreateCrate); static void traverseChildDir(const std::string& targetDir, std::function& onVisitChildDir); static void traverseAllPackagesForUser( - const std::unique_ptr& uuid, + const std::optional& uuid, userid_t userId, std::function& onHandlingPackage); #if CRATE_DEBUG - static void dump(std::unique_ptr& CrateMetadata); + static void dump(const CrateMetadata& CrateMetadata); #endif private: std::string mRoot; @@ -75,7 +75,7 @@ private: void createCrate( CratedFolder cratedFolder, - std::function&)>& onCreateCrate); + std::function& onCreateCrate); }; } // namespace installd diff --git a/cmds/installd/InstalldNativeService.cpp b/cmds/installd/InstalldNativeService.cpp index c9b51b597f..26f9d79cd4 100644 --- a/cmds/installd/InstalldNativeService.cpp +++ b/cmds/installd/InstalldNativeService.cpp @@ -164,7 +164,7 @@ binder::Status checkUid(uid_t expectedUid) { } } -binder::Status checkArgumentUuid(const std::unique_ptr& uuid) { +binder::Status checkArgumentUuid(const std::optional& uuid) { if (!uuid || is_valid_filename(*uuid)) { return ok(); } else { @@ -173,7 +173,7 @@ binder::Status checkArgumentUuid(const std::unique_ptr& uuid) { } } -binder::Status checkArgumentUuidTestOrNull(const std::unique_ptr& uuid) { +binder::Status checkArgumentUuidTestOrNull(const std::optional& uuid) { if (!uuid || strcmp(uuid->c_str(), kTestUuid) == 0) { return ok(); } else { @@ -212,7 +212,7 @@ binder::Status checkArgumentPath(const std::string& path) { return ok(); } -binder::Status checkArgumentPath(const std::unique_ptr& path) { +binder::Status checkArgumentPath(const std::optional& path) { if (path) { return checkArgumentPath(*path); } else { @@ -418,7 +418,7 @@ static bool prepare_app_profile_dir(const std::string& packageName, int32_t appI return true; } -binder::Status InstalldNativeService::createAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::createAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return) { ENFORCE_UID(AID_SYSTEM); @@ -499,7 +499,7 @@ binder::Status InstalldNativeService::createAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::migrateAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -560,7 +560,7 @@ binder::Status InstalldNativeService::clearAppProfiles(const std::string& packag return res; } -binder::Status InstalldNativeService::clearAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::clearAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -680,7 +680,7 @@ binder::Status InstalldNativeService::destroyAppProfiles(const std::string& pack return res; } -binder::Status InstalldNativeService::destroyAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::destroyAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -752,7 +752,7 @@ static gid_t get_cache_gid(uid_t uid) { return (gid != -1) ? gid : uid; } -binder::Status InstalldNativeService::fixupAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::fixupAppData(const std::optional& uuid, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -872,7 +872,7 @@ static int32_t copy_directory_recursive(const char* from, const char* to) { } binder::Status InstalldNativeService::snapshotAppData( - const std::unique_ptr& volumeUuid, + const std::optional& volumeUuid, const std::string& packageName, int32_t user, int32_t snapshotId, int32_t storageFlags, int64_t* _aidl_return) { ENFORCE_UID(AID_SYSTEM); @@ -999,7 +999,7 @@ binder::Status InstalldNativeService::snapshotAppData( } binder::Status InstalldNativeService::restoreAppDataSnapshot( - const std::unique_ptr& volumeUuid, const std::string& packageName, + const std::optional& volumeUuid, const std::string& packageName, const int32_t appId, const std::string& seInfo, const int32_t user, const int32_t snapshotId, int32_t storageFlags) { ENFORCE_UID(AID_SYSTEM); @@ -1069,7 +1069,7 @@ binder::Status InstalldNativeService::restoreAppDataSnapshot( } binder::Status InstalldNativeService::destroyAppDataSnapshot( - const std::unique_ptr &volumeUuid, const std::string& packageName, + const std::optional &volumeUuid, const std::string& packageName, const int32_t user, const int64_t ceSnapshotInode, const int32_t snapshotId, int32_t storageFlags) { ENFORCE_UID(AID_SYSTEM); @@ -1102,8 +1102,8 @@ binder::Status InstalldNativeService::destroyAppDataSnapshot( } -binder::Status InstalldNativeService::moveCompleteApp(const std::unique_ptr& fromUuid, - const std::unique_ptr& toUuid, const std::string& packageName, +binder::Status InstalldNativeService::moveCompleteApp(const std::optional& fromUuid, + const std::optional& toUuid, const std::string& packageName, int32_t appId, const std::string& seInfo, int32_t targetSdkVersion, const std::string& fromCodePath) { ENFORCE_UID(AID_SYSTEM); @@ -1210,7 +1210,7 @@ fail: return res; } -binder::Status InstalldNativeService::createUserData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::createUserData(const std::optional& uuid, int32_t userId, int32_t userSerial ATTRIBUTE_UNUSED, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -1228,7 +1228,7 @@ binder::Status InstalldNativeService::createUserData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::destroyUserData(const std::optional& uuid, int32_t userId, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -1265,13 +1265,13 @@ binder::Status InstalldNativeService::destroyUserData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::freeCache(const std::optional& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard lock(mLock); - auto uuidString = uuid ? *uuid : ""; + auto uuidString = uuid.value_or(""); const char* uuid_ = uuid ? uuid->c_str() : nullptr; auto data_path = create_data_path(uuid_); auto noop = (flags & FLAG_FREE_CACHE_NOOP); @@ -1669,7 +1669,7 @@ static void collectManualExternalStatsForUser(const std::string& path, struct st fts_close(fts); } -binder::Status InstalldNativeService::getAppSize(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::getAppSize(const std::optional& uuid, const std::vector& packageNames, int32_t userId, int32_t flags, int32_t appId, const std::vector& ceDataInodes, const std::vector& codePaths, std::vector* _aidl_return) { @@ -1709,7 +1709,7 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptrc_str() : nullptr; if (!IsQuotaSupported(uuidString)) { @@ -1896,7 +1896,7 @@ static external_sizes getExternalSizesForUserWithQuota(const std::string& uuid, return sizes; } -binder::Status InstalldNativeService::getUserSize(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::getUserSize(const std::optional& uuid, int32_t userId, int32_t flags, const std::vector& appIds, std::vector* _aidl_return) { ENFORCE_UID(AID_SYSTEM); @@ -1916,7 +1916,7 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptrc_str() : nullptr; if (!IsQuotaSupported(uuidString)) { @@ -2028,7 +2028,7 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::getExternalSize(const std::optional& uuid, int32_t userId, int32_t flags, const std::vector& appIds, std::vector* _aidl_return) { ENFORCE_UID(AID_SYSTEM); @@ -2043,7 +2043,7 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptrc_str() : nullptr; int64_t totalSize = 0; @@ -2145,9 +2145,9 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptr& uuid, + const std::optional& uuid, const std::vector& packageNames, int32_t userId, - std::unique_ptr>>* _aidl_return) { + std::optional>>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); for (const auto& packageName : packageNames) { @@ -2156,15 +2156,15 @@ binder::Status InstalldNativeService::getAppCrates( #ifdef ENABLE_STORAGE_CRATES std::lock_guard lock(mLock); - auto retVector = std::make_unique>>(); + auto retVector = std::vector>(); const char* uuid_ = uuid ? uuid->c_str() : nullptr; - std::function &)> onCreateCrate = - [&](CratedFolder cratedFolder, std::unique_ptr &crateMetadata) -> void { + std::function onCreateCrate = + [&](CratedFolder cratedFolder, CrateMetadata&& crateMetadata) -> void { if (cratedFolder == nullptr) { return; } - retVector->push_back(std::move(crateMetadata)); + retVector.push_back(std::move(crateMetadata)); }; for (const auto& packageName : packageNames) { @@ -2176,15 +2176,15 @@ binder::Status InstalldNativeService::getAppCrates( } #if CRATE_DEBUG - LOG(WARNING) << "retVector->size() =" << retVector->size(); - for (auto iter = retVector->begin(); iter != retVector->end(); ++iter) { - CrateManager::dump(*iter); + LOG(WARNING) << "retVector.size() =" << retVector.size(); + for (auto& item : retVector) { + CrateManager::dump(item); } #endif *_aidl_return = std::move(retVector); #else // ENABLE_STORAGE_CRATES - *_aidl_return = nullptr; + _aidl_return->reset(); /* prevent compile warning fail */ if (userId < 0) { @@ -2195,18 +2195,18 @@ binder::Status InstalldNativeService::getAppCrates( } binder::Status InstalldNativeService::getUserCrates( - const std::unique_ptr& uuid, int32_t userId, - std::unique_ptr>>* _aidl_return) { + const std::optional& uuid, int32_t userId, + std::optional>>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); #ifdef ENABLE_STORAGE_CRATES std::lock_guard lock(mLock); const char* uuid_ = uuid ? uuid->c_str() : nullptr; - auto retVector = std::make_unique>>(); + auto retVector = std::vector>(); - std::function &)> onCreateCrate = - [&](CratedFolder cratedFolder, std::unique_ptr &crateMetadata) -> void { + std::function onCreateCrate = + [&](CratedFolder cratedFolder, CrateMetadata&& crateMetadata) -> void { if (cratedFolder == nullptr) { return; } @@ -2220,15 +2220,15 @@ binder::Status InstalldNativeService::getUserCrates( CrateManager::traverseAllPackagesForUser(uuid, userId, onHandingPackage); #if CRATE_DEBUG - LOG(DEBUG) << "retVector->size() =" << retVector->size(); - for (auto iter = retVector->begin(); iter != retVector->end(); ++iter) { - CrateManager::dump(*iter); + LOG(DEBUG) << "retVector.size() =" << retVector.size(); + for (auto& item : retVector) { + CrateManager::dump(item); } #endif *_aidl_return = std::move(retVector); #else // ENABLE_STORAGE_CRATES - *_aidl_return = nullptr; + _aidl_return->reset(); /* prevent compile warning fail */ if (userId < 0) { @@ -2238,7 +2238,7 @@ binder::Status InstalldNativeService::getUserCrates( return ok(); } -binder::Status InstalldNativeService::setAppQuota(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::setAppQuota(const std::optional& uuid, int32_t userId, int32_t appId, int64_t cacheQuota) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -2309,19 +2309,19 @@ binder::Status InstalldNativeService::destroyProfileSnapshot(const std::string& return ok(); } -static const char* getCStr(const std::unique_ptr& data, +static const char* getCStr(const std::optional& data, const char* default_value = nullptr) { - return data == nullptr ? default_value : data->c_str(); + return data ? data->c_str() : default_value; } binder::Status InstalldNativeService::dexopt(const std::string& apkPath, int32_t uid, - const std::unique_ptr& packageName, const std::string& instructionSet, - int32_t dexoptNeeded, const std::unique_ptr& outputPath, int32_t dexFlags, - const std::string& compilerFilter, const std::unique_ptr& uuid, - const std::unique_ptr& classLoaderContext, - const std::unique_ptr& seInfo, bool downgrade, int32_t targetSdkVersion, - const std::unique_ptr& profileName, - const std::unique_ptr& dexMetadataPath, - const std::unique_ptr& compilationReason) { + const std::optional& packageName, const std::string& instructionSet, + int32_t dexoptNeeded, const std::optional& outputPath, int32_t dexFlags, + const std::string& compilerFilter, const std::optional& uuid, + const std::optional& classLoaderContext, + const std::optional& seInfo, bool downgrade, int32_t targetSdkVersion, + const std::optional& profileName, + const std::optional& dexMetadataPath, + const std::optional& compilationReason) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); CHECK_ARGUMENT_PATH(apkPath); @@ -2367,7 +2367,7 @@ binder::Status InstalldNativeService::compileLayouts(const std::string& apkPath, } binder::Status InstalldNativeService::linkNativeLibraryDirectory( - const std::unique_ptr& uuid, const std::string& packageName, + const std::optional& uuid, const std::string& packageName, const std::string& nativeLibPath32, int32_t userId) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); @@ -2458,7 +2458,7 @@ out: return res; } -binder::Status InstalldNativeService::restoreconAppData(const std::unique_ptr& uuid, +binder::Status InstalldNativeService::restoreconAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, const std::string& seInfo) { ENFORCE_UID(AID_SYSTEM); @@ -2576,7 +2576,7 @@ binder::Status InstalldNativeService::moveAb(const std::string& apkPath, } binder::Status InstalldNativeService::deleteOdex(const std::string& apkPath, - const std::string& instructionSet, const std::unique_ptr& outputPath) { + const std::string& instructionSet, const std::optional& outputPath) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_PATH(apkPath); CHECK_ARGUMENT_PATH(outputPath); @@ -2728,7 +2728,7 @@ binder::Status InstalldNativeService::assertFsverityRootHashMatches(const std::s binder::Status InstalldNativeService::reconcileSecondaryDexFile( const std::string& dexPath, const std::string& packageName, int32_t uid, - const std::vector& isas, const std::unique_ptr& volumeUuid, + const std::vector& isas, const std::optional& volumeUuid, int32_t storage_flag, bool* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(volumeUuid); @@ -2743,7 +2743,7 @@ binder::Status InstalldNativeService::reconcileSecondaryDexFile( binder::Status InstalldNativeService::hashSecondaryDexFile( const std::string& dexPath, const std::string& packageName, int32_t uid, - const std::unique_ptr& volumeUuid, int32_t storageFlag, + const std::optional& volumeUuid, int32_t storageFlag, std::vector* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(volumeUuid); @@ -2802,7 +2802,7 @@ binder::Status InstalldNativeService::invalidateMounts() { // Mount volume's CE and DE storage to mirror binder::Status InstalldNativeService::tryMountDataMirror( - const std::unique_ptr& uuid) { + const std::optional& uuid) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); if (!sAppDataIsolationEnabled) { @@ -2866,7 +2866,7 @@ binder::Status InstalldNativeService::tryMountDataMirror( // Unmount volume's CE and DE storage from mirror binder::Status InstalldNativeService::onPrivateVolumeRemoved( - const std::unique_ptr& uuid) { + const std::optional& uuid) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); if (!sAppDataIsolationEnabled) { @@ -2910,7 +2910,7 @@ binder::Status InstalldNativeService::onPrivateVolumeRemoved( } std::string InstalldNativeService::findDataMediaPath( - const std::unique_ptr& uuid, userid_t userid) { + const std::optional& uuid, userid_t userid) { std::lock_guard lock(mMountsLock); const char* uuid_ = uuid ? uuid->c_str() : nullptr; auto path = StringPrintf("%s/media", create_data_path(uuid_).c_str()); @@ -2923,15 +2923,14 @@ std::string InstalldNativeService::findDataMediaPath( } binder::Status InstalldNativeService::isQuotaSupported( - const std::unique_ptr& uuid, bool* _aidl_return) { - auto uuidString = uuid ? *uuid : ""; - *_aidl_return = IsQuotaSupported(uuidString); + const std::optional& uuid, bool* _aidl_return) { + *_aidl_return = IsQuotaSupported(uuid.value_or("")); return ok(); } binder::Status InstalldNativeService::prepareAppProfile(const std::string& packageName, int32_t userId, int32_t appId, const std::string& profileName, const std::string& codePath, - const std::unique_ptr& dexMetadata, bool* _aidl_return) { + const std::optional& dexMetadata, bool* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_PACKAGE_NAME(packageName); CHECK_ARGUMENT_PATH(codePath); diff --git a/cmds/installd/InstalldNativeService.h b/cmds/installd/InstalldNativeService.h index df01c3ca85..8e22c3e5d9 100644 --- a/cmds/installd/InstalldNativeService.h +++ b/cmds/installd/InstalldNativeService.h @@ -40,74 +40,74 @@ public: static char const* getServiceName() { return "installd"; } virtual status_t dump(int fd, const Vector &args) override; - binder::Status createUserData(const std::unique_ptr& uuid, int32_t userId, + binder::Status createUserData(const std::optional& uuid, int32_t userId, int32_t userSerial, int32_t flags); - binder::Status destroyUserData(const std::unique_ptr& uuid, int32_t userId, + binder::Status destroyUserData(const std::optional& uuid, int32_t userId, int32_t flags); - binder::Status createAppData(const std::unique_ptr& uuid, + binder::Status createAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, const std::string& seInfo, int32_t targetSdkVersion, int64_t* _aidl_return); - binder::Status restoreconAppData(const std::unique_ptr& uuid, + binder::Status restoreconAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int32_t appId, const std::string& seInfo); - binder::Status migrateAppData(const std::unique_ptr& uuid, + binder::Status migrateAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags); - binder::Status clearAppData(const std::unique_ptr& uuid, + binder::Status clearAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); - binder::Status destroyAppData(const std::unique_ptr& uuid, + binder::Status destroyAppData(const std::optional& uuid, const std::string& packageName, int32_t userId, int32_t flags, int64_t ceDataInode); - binder::Status fixupAppData(const std::unique_ptr& uuid, int32_t flags); + binder::Status fixupAppData(const std::optional& uuid, int32_t flags); - binder::Status snapshotAppData(const std::unique_ptr& volumeUuid, + binder::Status snapshotAppData(const std::optional& volumeUuid, const std::string& packageName, const int32_t user, const int32_t snapshotId, int32_t storageFlags, int64_t* _aidl_return); - binder::Status restoreAppDataSnapshot(const std::unique_ptr& volumeUuid, + binder::Status restoreAppDataSnapshot(const std::optional& volumeUuid, const std::string& packageName, const int32_t appId, const std::string& seInfo, const int32_t user, const int32_t snapshotId, int32_t storageFlags); - binder::Status destroyAppDataSnapshot(const std::unique_ptr &volumeUuid, + binder::Status destroyAppDataSnapshot(const std::optional &volumeUuid, const std::string& packageName, const int32_t user, const int64_t ceSnapshotInode, const int32_t snapshotId, int32_t storageFlags); - binder::Status getAppSize(const std::unique_ptr& uuid, + binder::Status getAppSize(const std::optional& uuid, const std::vector& packageNames, int32_t userId, int32_t flags, int32_t appId, const std::vector& ceDataInodes, const std::vector& codePaths, std::vector* _aidl_return); - binder::Status getUserSize(const std::unique_ptr& uuid, + binder::Status getUserSize(const std::optional& uuid, int32_t userId, int32_t flags, const std::vector& appIds, std::vector* _aidl_return); - binder::Status getExternalSize(const std::unique_ptr& uuid, + binder::Status getExternalSize(const std::optional& uuid, int32_t userId, int32_t flags, const std::vector& appIds, std::vector* _aidl_return); - binder::Status getAppCrates(const std::unique_ptr& uuid, + binder::Status getAppCrates(const std::optional& uuid, const std::vector& packageNames, int32_t userId, - std::unique_ptr>>* + std::optional>>* _aidl_return); binder::Status getUserCrates( - const std::unique_ptr& uuid, int32_t userId, - std::unique_ptr>>* + const std::optional& uuid, int32_t userId, + std::optional>>* _aidl_return); - binder::Status setAppQuota(const std::unique_ptr& uuid, + binder::Status setAppQuota(const std::optional& uuid, int32_t userId, int32_t appId, int64_t cacheQuota); - binder::Status moveCompleteApp(const std::unique_ptr& fromUuid, - const std::unique_ptr& toUuid, const std::string& packageName, + binder::Status moveCompleteApp(const std::optional& fromUuid, + const std::optional& toUuid, const std::string& packageName, int32_t appId, const std::string& seInfo, int32_t targetSdkVersion, const std::string& fromCodePath); binder::Status dexopt(const std::string& apkPath, int32_t uid, - const std::unique_ptr& packageName, const std::string& instructionSet, - int32_t dexoptNeeded, const std::unique_ptr& outputPath, int32_t dexFlags, - const std::string& compilerFilter, const std::unique_ptr& uuid, - const std::unique_ptr& classLoaderContext, - const std::unique_ptr& seInfo, bool downgrade, - int32_t targetSdkVersion, const std::unique_ptr& profileName, - const std::unique_ptr& dexMetadataPath, - const std::unique_ptr& compilationReason); + const std::optional& packageName, const std::string& instructionSet, + int32_t dexoptNeeded, const std::optional& outputPath, int32_t dexFlags, + const std::string& compilerFilter, const std::optional& uuid, + const std::optional& classLoaderContext, + const std::optional& seInfo, bool downgrade, + int32_t targetSdkVersion, const std::optional& profileName, + const std::optional& dexMetadataPath, + const std::optional& compilationReason); binder::Status compileLayouts(const std::string& apkPath, const std::string& packageName, const std::string& outDexFile, int uid, bool* _aidl_return); @@ -130,9 +130,9 @@ public: const std::string& profileName); binder::Status rmPackageDir(const std::string& packageDir); - binder::Status freeCache(const std::unique_ptr& uuid, int64_t targetFreeBytes, + binder::Status freeCache(const std::optional& uuid, int64_t targetFreeBytes, int64_t cacheReservedBytes, int32_t flags); - binder::Status linkNativeLibraryDirectory(const std::unique_ptr& uuid, + binder::Status linkNativeLibraryDirectory(const std::optional& uuid, const std::string& packageName, const std::string& nativeLibPath32, int32_t userId); binder::Status createOatDir(const std::string& oatDir, const std::string& instructionSet); binder::Status linkFile(const std::string& relativePath, const std::string& fromBase, @@ -140,27 +140,27 @@ public: binder::Status moveAb(const std::string& apkPath, const std::string& instructionSet, const std::string& outputPath); binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet, - const std::unique_ptr& outputPath); + const std::optional& outputPath); binder::Status installApkVerity(const std::string& filePath, android::base::unique_fd verityInput, int32_t contentSize); binder::Status assertFsverityRootHashMatches(const std::string& filePath, const std::vector& expectedHash); binder::Status reconcileSecondaryDexFile(const std::string& dexPath, const std::string& packageName, int32_t uid, const std::vector& isa, - const std::unique_ptr& volumeUuid, int32_t storage_flag, bool* _aidl_return); + const std::optional& volumeUuid, int32_t storage_flag, bool* _aidl_return); binder::Status hashSecondaryDexFile(const std::string& dexPath, - const std::string& packageName, int32_t uid, const std::unique_ptr& volumeUuid, + const std::string& packageName, int32_t uid, const std::optional& volumeUuid, int32_t storageFlag, std::vector* _aidl_return); binder::Status invalidateMounts(); - binder::Status isQuotaSupported(const std::unique_ptr& volumeUuid, + binder::Status isQuotaSupported(const std::optional& volumeUuid, bool* _aidl_return); - binder::Status tryMountDataMirror(const std::unique_ptr& volumeUuid); - binder::Status onPrivateVolumeRemoved(const std::unique_ptr& volumeUuid); + binder::Status tryMountDataMirror(const std::optional& volumeUuid); + binder::Status onPrivateVolumeRemoved(const std::optional& volumeUuid); binder::Status prepareAppProfile(const std::string& packageName, int32_t userId, int32_t appId, const std::string& profileName, - const std::string& codePath, const std::unique_ptr& dexMetadata, + const std::string& codePath, const std::optional& dexMetadata, bool* _aidl_return); binder::Status migrateLegacyObbData(); @@ -177,7 +177,7 @@ private: /* Map from UID to cache quota size */ std::unordered_map mCacheQuotas; - std::string findDataMediaPath(const std::unique_ptr& uuid, userid_t userid); + std::string findDataMediaPath(const std::optional& uuid, userid_t userid); }; } // namespace installd diff --git a/cmds/installd/dexopt.cpp b/cmds/installd/dexopt.cpp index 70bbc33b42..ebb8f0f90e 100644 --- a/cmds/installd/dexopt.cpp +++ b/cmds/installd/dexopt.cpp @@ -2277,7 +2277,7 @@ enum ReconcileSecondaryDexResult { // out_secondary_dex_exists will be set to false. bool reconcile_secondary_dex_file(const std::string& dex_path, const std::string& pkgname, int uid, const std::vector& isas, - const std::unique_ptr& volume_uuid, int storage_flag, + const std::optional& volume_uuid, int storage_flag, /*out*/bool* out_secondary_dex_exists) { *out_secondary_dex_exists = false; // start by assuming the file does not exist. if (isas.size() == 0) { @@ -2298,7 +2298,7 @@ bool reconcile_secondary_dex_file(const std::string& dex_path, /* child -- drop privileges before continuing */ drop_capabilities(uid); - const char* volume_uuid_cstr = volume_uuid == nullptr ? nullptr : volume_uuid->c_str(); + const char* volume_uuid_cstr = volume_uuid ? volume_uuid->c_str() : nullptr; if (!validate_secondary_dex_path(pkgname, dex_path, volume_uuid_cstr, uid, storage_flag)) { LOG(ERROR) << "Could not validate secondary dex path " << dex_path; @@ -2399,11 +2399,11 @@ bool reconcile_secondary_dex_file(const std::string& dex_path, // the app. // For any other errors (e.g. if any of the parameters are invalid) returns false. bool hash_secondary_dex_file(const std::string& dex_path, const std::string& pkgname, int uid, - const std::unique_ptr& volume_uuid, int storage_flag, + const std::optional& volume_uuid, int storage_flag, std::vector* out_secondary_dex_hash) { out_secondary_dex_hash->clear(); - const char* volume_uuid_cstr = volume_uuid == nullptr ? nullptr : volume_uuid->c_str(); + const char* volume_uuid_cstr = volume_uuid ? volume_uuid->c_str() : nullptr; if (storage_flag != FLAG_STORAGE_CE && storage_flag != FLAG_STORAGE_DE) { LOG(ERROR) << "hash_secondary_dex_file called with invalid storage_flag: " @@ -2924,7 +2924,7 @@ bool prepare_app_profile(const std::string& package_name, appid_t app_id, const std::string& profile_name, const std::string& code_path, - const std::unique_ptr& dex_metadata) { + const std::optional& dex_metadata) { // Prepare the current profile. std::string cur_profile = create_current_profile_path(user_id, package_name, profile_name, /*is_secondary_dex*/ false); @@ -2935,7 +2935,7 @@ bool prepare_app_profile(const std::string& package_name, } // Check if we need to install the profile from the dex metadata. - if (dex_metadata == nullptr) { + if (!dex_metadata) { return true; } diff --git a/cmds/installd/dexopt.h b/cmds/installd/dexopt.h index ef739bafd4..92b13c79c1 100644 --- a/cmds/installd/dexopt.h +++ b/cmds/installd/dexopt.h @@ -21,6 +21,8 @@ #include +#include + #include namespace android { @@ -98,17 +100,17 @@ bool prepare_app_profile(const std::string& package_name, appid_t app_id, const std::string& profile_name, const std::string& code_path, - const std::unique_ptr& dex_metadata); + const std::optional& dex_metadata); bool delete_odex(const char* apk_path, const char* instruction_set, const char* output_path); bool reconcile_secondary_dex_file(const std::string& dex_path, const std::string& pkgname, int uid, const std::vector& isas, - const std::unique_ptr& volumeUuid, int storage_flag, + const std::optional& volumeUuid, int storage_flag, /*out*/bool* out_secondary_dex_exists); bool hash_secondary_dex_file(const std::string& dex_path, - const std::string& pkgname, int uid, const std::unique_ptr& volume_uuid, + const std::string& pkgname, int uid, const std::optional& volume_uuid, int storage_flag, std::vector* out_secondary_dex_hash); int dexopt(const char *apk_path, uid_t uid, const char *pkgName, const char *instruction_set, diff --git a/cmds/installd/tests/installd_cache_test.cpp b/cmds/installd/tests/installd_cache_test.cpp index 5a5cb53431..863cdfe55b 100644 --- a/cmds/installd/tests/installd_cache_test.cpp +++ b/cmds/installd/tests/installd_cache_test.cpp @@ -114,15 +114,14 @@ static void setxattr(const char* path, const char* key) { class CacheTest : public testing::Test { protected: InstalldNativeService* service; - std::unique_ptr testUuid; + std::optional testUuid; virtual void SetUp() { setenv("ANDROID_LOG_TAGS", "*:v", 1); android::base::InitLogging(nullptr); service = new InstalldNativeService(); - testUuid = std::make_unique(); - *testUuid = std::string(kTestUuid); + testUuid = kTestUuid; system("mkdir -p /data/local/tmp/user/0"); } diff --git a/cmds/installd/tests/installd_dexopt_test.cpp b/cmds/installd/tests/installd_dexopt_test.cpp index 69fefa199b..7d8cf1f9e5 100644 --- a/cmds/installd/tests/installd_dexopt_test.cpp +++ b/cmds/installd/tests/installd_dexopt_test.cpp @@ -193,7 +193,7 @@ protected: const uid_t kTestAppGid = multiuser_get_shared_gid(kTestUserId, kTestAppId); InstalldNativeService* service_; - std::unique_ptr volume_uuid_; + std::optional volume_uuid_; std::string package_name_; std::string apk_path_; std::string empty_dm_file_; @@ -221,7 +221,7 @@ protected: ASSERT_TRUE(init_selinux()); service_ = new InstalldNativeService(); - volume_uuid_ = nullptr; + volume_uuid_ = std::nullopt; package_name_ = "com.installd.test.dexopt"; se_info_ = "default"; app_apk_dir_ = android_app_dir + package_name_; @@ -294,7 +294,7 @@ protected: } // Create a secondary dex file on CE storage - const char* volume_uuid_cstr = volume_uuid_ == nullptr ? nullptr : volume_uuid_->c_str(); + const char* volume_uuid_cstr = volume_uuid_ ? volume_uuid_->c_str() : nullptr; app_private_dir_ce_ = create_data_user_ce_package_path( volume_uuid_cstr, kTestUserId, package_name_.c_str()); secondary_dex_ce_ = app_private_dir_ce_ + "/secondary_ce.jar"; @@ -353,36 +353,32 @@ protected: if (class_loader_context == nullptr) { class_loader_context = "&"; } - std::unique_ptr package_name_ptr(new std::string(package_name_)); int32_t dexopt_needed = 0; // does not matter; - std::unique_ptr out_path = nullptr; // does not matter + std::optional out_path; // does not matter int32_t dex_flags = DEXOPT_SECONDARY_DEX | dex_storage_flag; std::string compiler_filter = "speed-profile"; - std::unique_ptr class_loader_context_ptr( - new std::string(class_loader_context)); - std::unique_ptr se_info_ptr(new std::string(se_info_)); bool downgrade = false; int32_t target_sdk_version = 0; // default - std::unique_ptr profile_name_ptr = nullptr; - std::unique_ptr dm_path_ptr = nullptr; - std::unique_ptr compilation_reason_ptr = nullptr; + std::optional profile_name; + std::optional dm_path; + std::optional compilation_reason; binder::Status result = service_->dexopt(path, uid, - package_name_ptr, + package_name_, kRuntimeIsa, dexopt_needed, out_path, dex_flags, compiler_filter, volume_uuid_, - class_loader_context_ptr, - se_info_ptr, + class_loader_context, + se_info_, downgrade, target_sdk_version, - profile_name_ptr, - dm_path_ptr, - compilation_reason_ptr); + profile_name, + dm_path, + compilation_reason); ASSERT_EQ(should_binder_call_succeed, result.isOk()) << result.toString8().c_str(); int expected_access = should_dex_be_compiled ? 0 : -1; std::string odex = GetSecondaryDexArtifact(path, "odex"); @@ -481,41 +477,35 @@ protected: bool downgrade, bool should_binder_call_succeed, /*out */ binder::Status* binder_result) { - std::unique_ptr package_name_ptr(new std::string(package_name_)); - std::unique_ptr out_path( - oat_dir == nullptr ? nullptr : new std::string(oat_dir)); - std::unique_ptr class_loader_context_ptr(new std::string("&")); - std::unique_ptr se_info_ptr(new std::string(se_info_)); + std::optional out_path = oat_dir ? std::make_optional(oat_dir) : std::nullopt; + std::string class_loader_context = "&"; int32_t target_sdk_version = 0; // default - std::unique_ptr profile_name_ptr(new std::string("primary.prof")); - std::unique_ptr dm_path_ptr = nullptr; - if (dm_path != nullptr) { - dm_path_ptr.reset(new std::string(dm_path)); - } - std::unique_ptr compilation_reason_ptr(new std::string("test-reason")); + std::string profile_name = "primary.prof"; + std::optional dm_path_opt = dm_path ? std::make_optional(dm_path) : std::nullopt; + std::string compilation_reason = "test-reason"; bool prof_result; ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( - package_name_, kTestUserId, kTestAppId, *profile_name_ptr, apk_path_, - dm_path_ptr, &prof_result)); + package_name_, kTestUserId, kTestAppId, profile_name, apk_path_, + dm_path_opt, &prof_result)); ASSERT_TRUE(prof_result); binder::Status result = service_->dexopt(apk_path_, uid, - package_name_ptr, + package_name_, kRuntimeIsa, dexopt_needed, out_path, dex_flags, compiler_filter, volume_uuid_, - class_loader_context_ptr, - se_info_ptr, + class_loader_context, + se_info_, downgrade, target_sdk_version, - profile_name_ptr, - dm_path_ptr, - compilation_reason_ptr); + profile_name, + dm_path_opt, + compilation_reason); ASSERT_EQ(should_binder_call_succeed, result.isOk()) << result.toString8().c_str(); if (!should_binder_call_succeed) { @@ -953,7 +943,7 @@ class ProfileTest : public DexoptTest { bool result; ASSERT_BINDER_SUCCESS(service_->prepareAppProfile( package_name, kTestUserId, kTestAppId, profile_name, apk_path_, - /*dex_metadata*/ nullptr, &result)); + /*dex_metadata*/ {}, &result)); ASSERT_EQ(expected_result, result); if (!expected_result) { diff --git a/cmds/installd/tests/installd_service_test.cpp b/cmds/installd/tests/installd_service_test.cpp index a31d510565..727867720d 100644 --- a/cmds/installd/tests/installd_service_test.cpp +++ b/cmds/installd/tests/installd_service_test.cpp @@ -99,15 +99,14 @@ static int stat_mode(const char* path) { class ServiceTest : public testing::Test { protected: InstalldNativeService* service; - std::unique_ptr testUuid; + std::optional testUuid; virtual void SetUp() { setenv("ANDROID_LOG_TAGS", "*:v", 1); android::base::InitLogging(nullptr); service = new InstalldNativeService(); - testUuid = std::make_unique(); - *testUuid = std::string(kTestUuid); + testUuid = kTestUuid; system("mkdir -p /data/local/tmp/user/0"); init_globals_from_data_and_root(); @@ -322,7 +321,7 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot) { // Request a snapshot of the CE content but not the DE content. int64_t ce_snapshot_inode; - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 37, FLAG_STORAGE_CE, &ce_snapshot_inode)); struct stat buf; memset(&buf, 0, sizeof(buf)); @@ -344,7 +343,7 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot) { 0700, 10000, 20000, false /* follow_symlinks */)); // Request a snapshot of the DE content but not the CE content. - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 37, FLAG_STORAGE_DE, &ce_snapshot_inode)); // Only DE content snapshot was requested. ASSERT_EQ(ce_snapshot_inode, 0); @@ -365,7 +364,7 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot) { 0700, 10000, 20000, false /* follow_symlinks */)); // Request a snapshot of both the CE as well as the DE content. - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 37, FLAG_STORAGE_DE | FLAG_STORAGE_CE, nullptr)); ASSERT_TRUE(android::base::ReadFileToString( @@ -407,10 +406,10 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot_TwoSnapshotsWithTheSameId) { 0700, 10000, 20000, false /* follow_symlinks */)); // Request snapshot for the package com.foo. - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 67, FLAG_STORAGE_DE | FLAG_STORAGE_CE, nullptr)); // Now request snapshot with the same id for the package com.bar - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.bar", 0, 67, FLAG_STORAGE_DE | FLAG_STORAGE_CE, nullptr)); // Check that both snapshots have correct data in them. @@ -439,9 +438,9 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot_AppDataAbsent) { ASSERT_EQ(0, delete_dir_contents_and_dir(fake_package_de_path, true)); int64_t ce_snapshot_inode; - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 73, FLAG_STORAGE_CE, &ce_snapshot_inode)); - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 73, FLAG_STORAGE_DE, nullptr)); // No CE content snapshot was performed. ASSERT_EQ(ce_snapshot_inode, 0); @@ -476,7 +475,7 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot_ClearsExistingSnapshot) { "TEST_CONTENT_2_DE", fake_package_de_path + "/file2", 0700, 10000, 20000, false /* follow_symlinks */)); - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 13, FLAG_STORAGE_DE | FLAG_STORAGE_CE, nullptr)); // Previous snapshot (with data for file1) must be cleared. @@ -497,7 +496,7 @@ TEST_F(AppDataSnapshotTest, SnapshotAppData_WrongVolumeUuid) { ASSERT_TRUE(mkdirs(rollback_ce_dir, 0700)); ASSERT_TRUE(mkdirs(rollback_de_dir, 0700)); - EXPECT_BINDER_FAIL(service->snapshotAppData(std::make_unique("FOO"), + EXPECT_BINDER_FAIL(service->snapshotAppData(std::make_optional("FOO"), "com.foo", 0, 17, FLAG_STORAGE_DE, nullptr)); } @@ -524,7 +523,7 @@ TEST_F(AppDataSnapshotTest, CreateAppDataSnapshot_ClearsCache) { ASSERT_TRUE(android::base::WriteStringToFile( "TEST_CONTENT_DE", fake_package_de_code_cache_path + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); - ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 23, FLAG_STORAGE_CE | FLAG_STORAGE_DE, nullptr)); // The snapshot call must clear cache. struct stat sb; @@ -558,7 +557,7 @@ TEST_F(AppDataSnapshotTest, RestoreAppDataSnapshot) { "TEST_CONTENT_DE", fake_package_de_path + "/file1", 0700, 10000, 20000, false /* follow_symlinks */)); - ASSERT_BINDER_SUCCESS(service->restoreAppDataSnapshot(std::make_unique("TEST"), + ASSERT_BINDER_SUCCESS(service->restoreAppDataSnapshot(std::make_optional("TEST"), "com.foo", 10000, "", 0, 239, FLAG_STORAGE_DE | FLAG_STORAGE_CE)); std::string ce_content, de_content; @@ -584,7 +583,7 @@ TEST_F(AppDataSnapshotTest, CreateSnapshotThenDestroyIt) { int64_t ce_snapshot_inode; // Request a snapshot of both the CE as well as the DE content. - ASSERT_TRUE(service->snapshotAppData(std::make_unique("TEST"), + ASSERT_TRUE(service->snapshotAppData(std::make_optional("TEST"), "com.foo", 0, 57, FLAG_STORAGE_DE | FLAG_STORAGE_CE, &ce_snapshot_inode).isOk()); // Because CE data snapshot was requested, ce_snapshot_inode can't be null. ASSERT_NE(0, ce_snapshot_inode); @@ -594,7 +593,7 @@ TEST_F(AppDataSnapshotTest, CreateSnapshotThenDestroyIt) { ASSERT_EQ(0, stat((rollback_de_dir + "/com.foo").c_str(), &sb)); - ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_unique("TEST"), + ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_optional("TEST"), "com.foo", 0, ce_snapshot_inode, 57, FLAG_STORAGE_DE | FLAG_STORAGE_CE).isOk()); // Check snapshot is deleted. ASSERT_EQ(-1, stat((rollback_ce_dir + "/com.foo").c_str(), &sb)); @@ -615,7 +614,7 @@ TEST_F(AppDataSnapshotTest, DestroyAppDataSnapshot_CeSnapshotInodeIsZero) { "DE_RESTORE_CONTENT", rollback_de_dir + "/com.foo/file1", 0700, 10000, 20000, false /* follow_symlinks */)); - ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_unique("TEST"), + ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_optional("TEST"), "com.foo", 0, 0, 1543, FLAG_STORAGE_DE | FLAG_STORAGE_CE).isOk()); // Check snapshot is deleted. @@ -624,7 +623,7 @@ TEST_F(AppDataSnapshotTest, DestroyAppDataSnapshot_CeSnapshotInodeIsZero) { ASSERT_EQ(-1, stat((rollback_de_dir + "/com.foo").c_str(), &sb)); // Check that deleting already deleted snapshot is no-op. - ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_unique("TEST"), + ASSERT_TRUE(service->destroyAppDataSnapshot(std::make_optional("TEST"), "com.foo", 0, 0, 1543, FLAG_STORAGE_DE | FLAG_STORAGE_CE).isOk()); } @@ -637,7 +636,7 @@ TEST_F(AppDataSnapshotTest, DestroyAppDataSnapshot_WrongVolumeUuid) { ASSERT_TRUE(mkdirs(rollback_ce_dir, 0700)); ASSERT_TRUE(mkdirs(rollback_de_dir, 0700)); - ASSERT_FALSE(service->destroyAppDataSnapshot(std::make_unique("BAR"), + ASSERT_FALSE(service->destroyAppDataSnapshot(std::make_optional("BAR"), "com.foo", 0, 0, 43, FLAG_STORAGE_DE).isOk()); } @@ -650,7 +649,7 @@ TEST_F(AppDataSnapshotTest, RestoreAppDataSnapshot_WrongVolumeUuid) { ASSERT_TRUE(mkdirs(rollback_ce_dir, 0700)); ASSERT_TRUE(mkdirs(rollback_de_dir, 0700)); - EXPECT_BINDER_FAIL(service->restoreAppDataSnapshot(std::make_unique("BAR"), + EXPECT_BINDER_FAIL(service->restoreAppDataSnapshot(std::make_optional("BAR"), "com.foo", 10000, "", 0, 41, FLAG_STORAGE_DE)); } diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index aeca12b582..4ab144bdf1 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -115,12 +115,12 @@ int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t ui } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { - return noteOp(op, uid, callingPackage, std::unique_ptr(), + return noteOp(op, uid, callingPackage, {}, String16("Legacy AppOpsManager.noteOp call")); } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::unique_ptr& featureId, const String16& message) { + const std::optional& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr ? service->noteOperation(op, uid, callingPackage, featureId, shouldCollectNotes(op), @@ -132,12 +132,12 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault) { - return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, std::unique_ptr(), + return startOpNoThrow(op, uid, callingPackage, startIfModeDefault, {}, String16("Legacy AppOpsManager.startOpNoThrow call")); } int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const std::unique_ptr& featureId, + bool startIfModeDefault, const std::optional& featureId, const String16& message) { sp service = getService(); int32_t mode = service != nullptr @@ -149,11 +149,11 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) { - finishOp(op, uid, callingPackage, std::unique_ptr()); + finishOp(op, uid, callingPackage, {}); } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::unique_ptr& callingFeatureId) { + const std::optional& callingFeatureId) { sp service = getService(); if (service != nullptr) { service->finishOperation(getClientId(), op, uid, callingPackage, callingFeatureId); 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 #include +#include + namespace android { // ---------------------------------------------------------------------- @@ -47,7 +49,7 @@ public: } virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::unique_ptr& featureId, bool shouldCollectAsyncNotedOp, + const std::optional& featureId, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -64,7 +66,7 @@ public: } virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr& featureId, + const String16& packageName, const std::optional& 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& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr& featureId) { + const String16& packageName, const std::optional& 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 featureId; + std::optional 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 featureId; + std::optional 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 featureId; + std::optional featureId; data.readString16(&featureId); finishOperation(token, code, uid, packageName, featureId); reply->writeNoException(); diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index beab270387..5f1f682a5b 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -751,6 +751,13 @@ status_t Parcel::writeUtf8AsUtf16(const std::string& str) { return NO_ERROR; } +status_t Parcel::writeUtf8AsUtf16(const std::optional& str) { + if (!str) { + return writeInt32(-1); + } + return writeUtf8AsUtf16(*str); +} + status_t Parcel::writeUtf8AsUtf16(const std::unique_ptr& str) { if (!str) { return writeInt32(-1); @@ -775,6 +782,12 @@ status_t Parcel::writeByteVector(const std::vector& val) { return writeByteVectorInternal(val.data(), val.size()); } +status_t Parcel::writeByteVector(const std::optional>& val) +{ + if (!val) return writeInt32(-1); + return writeByteVectorInternal(val->data(), val->size()); +} + status_t Parcel::writeByteVector(const std::unique_ptr>& val) { if (!val) return writeInt32(-1); @@ -785,6 +798,12 @@ status_t Parcel::writeByteVector(const std::vector& val) { return writeByteVectorInternal(reinterpret_cast(val.data()), val.size()); } +status_t Parcel::writeByteVector(const std::optional>& val) +{ + if (!val) return writeInt32(-1); + return writeByteVectorInternal(reinterpret_cast(val->data()), val->size()); +} + status_t Parcel::writeByteVector(const std::unique_ptr>& val) { if (!val) return writeInt32(-1); @@ -796,6 +815,11 @@ status_t Parcel::writeInt32Vector(const std::vector& val) return writeTypedVector(val, &Parcel::writeInt32); } +status_t Parcel::writeInt32Vector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeInt32); +} + status_t Parcel::writeInt32Vector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeInt32); @@ -806,6 +830,11 @@ status_t Parcel::writeInt64Vector(const std::vector& val) return writeTypedVector(val, &Parcel::writeInt64); } +status_t Parcel::writeInt64Vector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeInt64); +} + status_t Parcel::writeInt64Vector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeInt64); @@ -816,6 +845,11 @@ status_t Parcel::writeUint64Vector(const std::vector& val) return writeTypedVector(val, &Parcel::writeUint64); } +status_t Parcel::writeUint64Vector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeUint64); +} + status_t Parcel::writeUint64Vector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeUint64); @@ -826,6 +860,11 @@ status_t Parcel::writeFloatVector(const std::vector& val) return writeTypedVector(val, &Parcel::writeFloat); } +status_t Parcel::writeFloatVector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeFloat); +} + status_t Parcel::writeFloatVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeFloat); @@ -836,6 +875,11 @@ status_t Parcel::writeDoubleVector(const std::vector& val) return writeTypedVector(val, &Parcel::writeDouble); } +status_t Parcel::writeDoubleVector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeDouble); +} + status_t Parcel::writeDoubleVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeDouble); @@ -846,6 +890,11 @@ status_t Parcel::writeBoolVector(const std::vector& val) return writeTypedVector(val, &Parcel::writeBool); } +status_t Parcel::writeBoolVector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeBool); +} + status_t Parcel::writeBoolVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeBool); @@ -856,6 +905,11 @@ status_t Parcel::writeCharVector(const std::vector& val) return writeTypedVector(val, &Parcel::writeChar); } +status_t Parcel::writeCharVector(const std::optional>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeChar); +} + status_t Parcel::writeCharVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeChar); @@ -866,12 +920,23 @@ status_t Parcel::writeString16Vector(const std::vector& val) return writeTypedVector(val, &Parcel::writeString16); } +status_t Parcel::writeString16Vector( + const std::optional>>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeString16); +} + status_t Parcel::writeString16Vector( const std::unique_ptr>>& val) { return writeNullableTypedVector(val, &Parcel::writeString16); } +status_t Parcel::writeUtf8VectorAsUtf16Vector( + const std::optional>>& val) { + return writeNullableTypedVector(val, &Parcel::writeUtf8AsUtf16); +} + status_t Parcel::writeUtf8VectorAsUtf16Vector( const std::unique_ptr>>& val) { return writeNullableTypedVector(val, &Parcel::writeUtf8AsUtf16); @@ -997,6 +1062,15 @@ status_t Parcel::writeString8(const String8& str) return err; } +status_t Parcel::writeString16(const std::optional& str) +{ + if (!str) { + return writeInt32(-1); + } + + return writeString16(*str); +} + status_t Parcel::writeString16(const std::unique_ptr& str) { if (!str) { @@ -1039,11 +1113,20 @@ status_t Parcel::writeStrongBinderVector(const std::vector>& val) return writeTypedVector(val, &Parcel::writeStrongBinder); } +status_t Parcel::writeStrongBinderVector(const std::optional>>& val) +{ + return writeNullableTypedVector(val, &Parcel::writeStrongBinder); +} + status_t Parcel::writeStrongBinderVector(const std::unique_ptr>>& val) { return writeNullableTypedVector(val, &Parcel::writeStrongBinder); } +status_t Parcel::readStrongBinderVector(std::optional>>* val) const { + return readNullableTypedVector(val, &Parcel::readNullableStrongBinder); +} + status_t Parcel::readStrongBinderVector(std::unique_ptr>>* val) const { return readNullableTypedVector(val, &Parcel::readNullableStrongBinder); } @@ -1142,6 +1225,10 @@ status_t Parcel::writeUniqueFileDescriptorVector(const std::vector>& val) { + return writeNullableTypedVector(val, &Parcel::writeUniqueFileDescriptor); +} + status_t Parcel::writeUniqueFileDescriptorVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeUniqueFileDescriptor); } @@ -1475,6 +1562,17 @@ status_t Parcel::readByteVector(std::vector* val) const { return readByteVectorInternal(val, size); } +status_t Parcel::readByteVector(std::optional>* val) const { + size_t size; + if (status_t status = reserveOutVector(val, &size); status != OK) return status; + if (!*val) { + // reserveOutVector does not create the out vector if size is < 0. + // This occurs when writing a null byte vector. + return OK; + } + return readByteVectorInternal(&**val, size); +} + status_t Parcel::readByteVector(std::unique_ptr>* val) const { size_t size; if (status_t status = reserveOutVector(val, &size); status != OK) return status; @@ -1486,6 +1584,17 @@ status_t Parcel::readByteVector(std::unique_ptr>* val) const return readByteVectorInternal(val->get(), size); } +status_t Parcel::readByteVector(std::optional>* val) const { + size_t size; + if (status_t status = reserveOutVector(val, &size); status != OK) return status; + if (!*val) { + // reserveOutVector does not create the out vector if size is < 0. + // This occurs when writing a null byte vector. + return OK; + } + return readByteVectorInternal(&**val, size); +} + status_t Parcel::readByteVector(std::unique_ptr>* val) const { size_t size; if (status_t status = reserveOutVector(val, &size); status != OK) return status; @@ -1497,6 +1606,10 @@ status_t Parcel::readByteVector(std::unique_ptr>* val) cons return readByteVectorInternal(val->get(), size); } +status_t Parcel::readInt32Vector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readInt32); +} + status_t Parcel::readInt32Vector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readInt32); } @@ -1505,6 +1618,10 @@ status_t Parcel::readInt32Vector(std::vector* val) const { return readTypedVector(val, &Parcel::readInt32); } +status_t Parcel::readInt64Vector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readInt64); +} + status_t Parcel::readInt64Vector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readInt64); } @@ -1513,6 +1630,10 @@ status_t Parcel::readInt64Vector(std::vector* val) const { return readTypedVector(val, &Parcel::readInt64); } +status_t Parcel::readUint64Vector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readUint64); +} + status_t Parcel::readUint64Vector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readUint64); } @@ -1521,6 +1642,10 @@ status_t Parcel::readUint64Vector(std::vector* val) const { return readTypedVector(val, &Parcel::readUint64); } +status_t Parcel::readFloatVector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readFloat); +} + status_t Parcel::readFloatVector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readFloat); } @@ -1529,6 +1654,10 @@ status_t Parcel::readFloatVector(std::vector* val) const { return readTypedVector(val, &Parcel::readFloat); } +status_t Parcel::readDoubleVector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readDouble); +} + status_t Parcel::readDoubleVector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readDouble); } @@ -1537,6 +1666,28 @@ status_t Parcel::readDoubleVector(std::vector* val) const { return readTypedVector(val, &Parcel::readDouble); } +status_t Parcel::readBoolVector(std::optional>* val) const { + const int32_t start = dataPosition(); + int32_t size; + status_t status = readInt32(&size); + val->reset(); + + if (status != OK || size < 0) { + return status; + } + + setDataPosition(start); + val->emplace(); + + status = readBoolVector(&**val); + + if (status != OK) { + val->reset(); + } + + return status; +} + status_t Parcel::readBoolVector(std::unique_ptr>* val) const { const int32_t start = dataPosition(); int32_t size; @@ -1589,6 +1740,10 @@ status_t Parcel::readBoolVector(std::vector* val) const { return OK; } +status_t Parcel::readCharVector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readChar); +} + status_t Parcel::readCharVector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readChar); } @@ -1597,6 +1752,11 @@ status_t Parcel::readCharVector(std::vector* val) const { return readTypedVector(val, &Parcel::readChar); } +status_t Parcel::readString16Vector( + std::optional>>* val) const { + return readNullableTypedVector(val, &Parcel::readString16); +} + status_t Parcel::readString16Vector( std::unique_ptr>>* val) const { return readNullableTypedVector(val, &Parcel::readString16); @@ -1606,6 +1766,11 @@ status_t Parcel::readString16Vector(std::vector* val) const { return readTypedVector(val, &Parcel::readString16); } +status_t Parcel::readUtf8VectorFromUtf16Vector( + std::optional>>* val) const { + return readNullableTypedVector(val, &Parcel::readUtf8FromUtf16); +} + status_t Parcel::readUtf8VectorFromUtf16Vector( std::unique_ptr>>* val) const { return readNullableTypedVector(val, &Parcel::readUtf8FromUtf16); @@ -1798,6 +1963,21 @@ status_t Parcel::readUtf8FromUtf16(std::string* str) const { return NO_ERROR; } +status_t Parcel::readUtf8FromUtf16(std::optional* str) const { + const int32_t start = dataPosition(); + int32_t size; + status_t status = readInt32(&size); + str->reset(); + + if (status != OK || size < 0) { + return status; + } + + setDataPosition(start); + str->emplace(); + return readUtf8FromUtf16(&**str); +} + status_t Parcel::readUtf8FromUtf16(std::unique_ptr* str) const { const int32_t start = dataPosition(); int32_t size; @@ -1874,6 +2054,29 @@ String16 Parcel::readString16() const return String16(); } +status_t Parcel::readString16(std::optional* pArg) const +{ + const int32_t start = dataPosition(); + int32_t size; + status_t status = readInt32(&size); + pArg->reset(); + + if (status != OK || size < 0) { + return status; + } + + setDataPosition(start); + pArg->emplace(); + + status = readString16(&**pArg); + + if (status != OK) { + pArg->reset(); + } + + return status; +} + status_t Parcel::readString16(std::unique_ptr* pArg) const { const int32_t start = dataPosition(); @@ -2079,6 +2282,10 @@ status_t Parcel::readUniqueParcelFileDescriptor(base::unique_fd* val) const return OK; } +status_t Parcel::readUniqueFileDescriptorVector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readUniqueFileDescriptor); +} + status_t Parcel::readUniqueFileDescriptorVector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readUniqueFileDescriptor); } diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index 5b6eb6863e..e4641822ad 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -21,6 +21,8 @@ #include +#include + #ifdef __ANDROID_VNDK__ #error "This header is not visible to vendors" #endif @@ -134,18 +136,18 @@ public: // const String16&) instead int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::unique_ptr& featureId, const String16& message); + const std::optional& featureId, const String16& message); // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&, // const String16&) instead int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault); int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const std::unique_ptr& featureId, + bool startIfModeDefault, const std::optional& featureId, const String16& message); // @Deprecated, use finishOp(int32_t, int32_t, const String16&, bool, const String16&) instead void finishOp(int32_t op, int32_t uid, const String16& callingPackage); void finishOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::unique_ptr& featureId); + const std::optional& featureId); void startWatchingMode(int32_t op, const String16& packageName, const sp& callback); void stopWatchingMode(const sp& callback); diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 1b4bcce20f..95a80ff268 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -21,6 +21,8 @@ #include #include +#include + #ifdef __ANDROID_VNDK__ #error "This header is not visible to vendors" #endif @@ -36,13 +38,13 @@ public: virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::unique_ptr& featureId, bool shouldCollectAsyncNotedOp, + const std::optional& featureId, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr& featureId, + const String16& packageName, const std::optional& featureId, bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual void finishOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::unique_ptr& featureId) = 0; + const String16& packageName, const std::optional& featureId) = 0; virtual void startWatchingMode(int32_t op, const String16& packageName, const sp& callback) = 0; virtual void stopWatchingMode(const sp& callback) = 0; diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index 4b1a758f38..97f1aeeb7b 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -120,6 +120,7 @@ public: status_t writeCString(const char* str); status_t writeString8(const String8& str); status_t writeString16(const String16& str); + status_t writeString16(const std::optional& str); status_t writeString16(const std::unique_ptr& str); status_t writeString16(const char16_t* str, size_t len); status_t writeStrongBinder(const sp& val); @@ -131,33 +132,48 @@ public: // Take a UTF8 encoded string, convert to UTF16, write it to the parcel. status_t writeUtf8AsUtf16(const std::string& str); + status_t writeUtf8AsUtf16(const std::optional& str); status_t writeUtf8AsUtf16(const std::unique_ptr& str); + status_t writeByteVector(const std::optional>& val); status_t writeByteVector(const std::unique_ptr>& val); status_t writeByteVector(const std::vector& val); + status_t writeByteVector(const std::optional>& val); status_t writeByteVector(const std::unique_ptr>& val); status_t writeByteVector(const std::vector& val); + status_t writeInt32Vector(const std::optional>& val); status_t writeInt32Vector(const std::unique_ptr>& val); status_t writeInt32Vector(const std::vector& val); + status_t writeInt64Vector(const std::optional>& val); status_t writeInt64Vector(const std::unique_ptr>& val); status_t writeInt64Vector(const std::vector& val); + status_t writeUint64Vector(const std::optional>& val); status_t writeUint64Vector(const std::unique_ptr>& val); status_t writeUint64Vector(const std::vector& val); + status_t writeFloatVector(const std::optional>& val); status_t writeFloatVector(const std::unique_ptr>& val); status_t writeFloatVector(const std::vector& val); + status_t writeDoubleVector(const std::optional>& val); status_t writeDoubleVector(const std::unique_ptr>& val); status_t writeDoubleVector(const std::vector& val); + status_t writeBoolVector(const std::optional>& val); status_t writeBoolVector(const std::unique_ptr>& val); status_t writeBoolVector(const std::vector& val); + status_t writeCharVector(const std::optional>& val); status_t writeCharVector(const std::unique_ptr>& val); status_t writeCharVector(const std::vector& val); + status_t writeString16Vector( + const std::optional>>& val); status_t writeString16Vector( const std::unique_ptr>>& val); status_t writeString16Vector(const std::vector& val); + status_t writeUtf8VectorAsUtf16Vector( + const std::optional>>& val); status_t writeUtf8VectorAsUtf16Vector( const std::unique_ptr>>& val); status_t writeUtf8VectorAsUtf16Vector(const std::vector& val); + status_t writeStrongBinderVector(const std::optional>>& val); status_t writeStrongBinderVector(const std::unique_ptr>>& val); status_t writeStrongBinderVector(const std::vector>& val); @@ -166,13 +182,19 @@ public: template && std::is_same_v,int8_t>, bool> = 0> status_t writeEnumVector(const std::vector& val); template && std::is_same_v,int8_t>, bool> = 0> + status_t writeEnumVector(const std::optional>& val); + template && std::is_same_v,int8_t>, bool> = 0> status_t writeEnumVector(const std::unique_ptr>& val); // Write an Enum vector with underlying type != int8_t. template && !std::is_same_v,int8_t>, bool> = 0> status_t writeEnumVector(const std::vector& val); template && !std::is_same_v,int8_t>, bool> = 0> + status_t writeEnumVector(const std::optional>& val); + template && !std::is_same_v,int8_t>, bool> = 0> status_t writeEnumVector(const std::unique_ptr>& val); + template + status_t writeParcelableVector(const std::optional>>& val); template status_t writeParcelableVector(const std::unique_ptr>>& val); template @@ -180,6 +202,8 @@ public: template status_t writeParcelableVector(const std::vector& val); + template + status_t writeNullableParcelable(const std::optional& parcelable); template status_t writeNullableParcelable(const std::unique_ptr& parcelable); @@ -194,6 +218,8 @@ public: template status_t writeVectorSize(const std::vector& val); template + status_t writeVectorSize(const std::optional>& val); + template status_t writeVectorSize(const std::unique_ptr>& val); // Place a native_handle into the parcel (the native_handle's file- @@ -228,6 +254,8 @@ public: // Place a vector of file desciptors into the parcel. Each descriptor is // dup'd as in writeDupFileDescriptor + status_t writeUniqueFileDescriptorVector( + const std::optional>& val); status_t writeUniqueFileDescriptorVector( const std::unique_ptr>& val); status_t writeUniqueFileDescriptorVector( @@ -278,6 +306,7 @@ public: // Read a UTF16 encoded string, convert to UTF8 status_t readUtf8FromUtf16(std::string* str) const; + status_t readUtf8FromUtf16(std::optional* str) const; status_t readUtf8FromUtf16(std::unique_ptr* str) const; const char* readCString() const; @@ -285,25 +314,32 @@ public: status_t readString8(String8* pArg) const; String16 readString16() const; status_t readString16(String16* pArg) const; + status_t readString16(std::optional* pArg) const; status_t readString16(std::unique_ptr* pArg) const; const char16_t* readString16Inplace(size_t* outLen) const; sp readStrongBinder() const; status_t readStrongBinder(sp* val) const; status_t readNullableStrongBinder(sp* val) const; - // Read an Enum vector with underlying type int8_t. // Does not use padding; each byte is contiguous. template && std::is_same_v,int8_t>, bool> = 0> status_t readEnumVector(std::vector* val) const; template && std::is_same_v,int8_t>, bool> = 0> status_t readEnumVector(std::unique_ptr>* val) const; + template && std::is_same_v,int8_t>, bool> = 0> + status_t readEnumVector(std::optional>* val) const; // Read an Enum vector with underlying type != int8_t. template && !std::is_same_v,int8_t>, bool> = 0> status_t readEnumVector(std::vector* val) const; template && !std::is_same_v,int8_t>, bool> = 0> status_t readEnumVector(std::unique_ptr>* val) const; + template && !std::is_same_v,int8_t>, bool> = 0> + status_t readEnumVector(std::optional>* val) const; + template + status_t readParcelableVector( + std::optional>>* val) const; template status_t readParcelableVector( std::unique_ptr>>* val) const; @@ -312,6 +348,8 @@ public: status_t readParcelable(Parcelable* parcelable) const; + template + status_t readParcelable(std::optional* parcelable) const; template status_t readParcelable(std::unique_ptr* parcelable) const; @@ -321,30 +359,44 @@ public: template status_t readNullableStrongBinder(sp* val) const; + status_t readStrongBinderVector(std::optional>>* val) const; status_t readStrongBinderVector(std::unique_ptr>>* val) const; status_t readStrongBinderVector(std::vector>* val) const; + status_t readByteVector(std::optional>* val) const; status_t readByteVector(std::unique_ptr>* val) const; status_t readByteVector(std::vector* val) const; + status_t readByteVector(std::optional>* val) const; status_t readByteVector(std::unique_ptr>* val) const; status_t readByteVector(std::vector* val) const; + status_t readInt32Vector(std::optional>* val) const; status_t readInt32Vector(std::unique_ptr>* val) const; status_t readInt32Vector(std::vector* val) const; + status_t readInt64Vector(std::optional>* val) const; status_t readInt64Vector(std::unique_ptr>* val) const; status_t readInt64Vector(std::vector* val) const; + status_t readUint64Vector(std::optional>* val) const; status_t readUint64Vector(std::unique_ptr>* val) const; status_t readUint64Vector(std::vector* val) const; + status_t readFloatVector(std::optional>* val) const; status_t readFloatVector(std::unique_ptr>* val) const; status_t readFloatVector(std::vector* val) const; + status_t readDoubleVector(std::optional>* val) const; status_t readDoubleVector(std::unique_ptr>* val) const; status_t readDoubleVector(std::vector* val) const; + status_t readBoolVector(std::optional>* val) const; status_t readBoolVector(std::unique_ptr>* val) const; status_t readBoolVector(std::vector* val) const; + status_t readCharVector(std::optional>* val) const; status_t readCharVector(std::unique_ptr>* val) const; status_t readCharVector(std::vector* val) const; + status_t readString16Vector( + std::optional>>* val) const; status_t readString16Vector( std::unique_ptr>>* val) const; status_t readString16Vector(std::vector* val) const; + status_t readUtf8VectorFromUtf16Vector( + std::optional>>* val) const; status_t readUtf8VectorFromUtf16Vector( std::unique_ptr>>* val) const; status_t readUtf8VectorFromUtf16Vector(std::vector* val) const; @@ -358,10 +410,15 @@ public: template status_t resizeOutVector(std::vector* val) const; template + status_t resizeOutVector(std::optional>* val) const; + template status_t resizeOutVector(std::unique_ptr>* val) const; template status_t reserveOutVector(std::vector* val, size_t* size) const; template + status_t reserveOutVector(std::optional>* val, + size_t* size) const; + template status_t reserveOutVector(std::unique_ptr>* val, size_t* size) const; @@ -396,6 +453,8 @@ public: // Retrieve a vector of smart file descriptors from the parcel. + status_t readUniqueFileDescriptorVector( + std::optional>* val) const; status_t readUniqueFileDescriptorVector( std::unique_ptr>* val) const; status_t readUniqueFileDescriptorVector( @@ -490,6 +549,9 @@ private: status_t unsafeReadTypedVector(std::vector* val, status_t(Parcel::*read_func)(U*) const) const; template + status_t readNullableTypedVector(std::optional>* val, + status_t(Parcel::*read_func)(T*) const) const; + template status_t readNullableTypedVector(std::unique_ptr>* val, status_t(Parcel::*read_func)(T*) const) const; template @@ -499,9 +561,15 @@ private: status_t unsafeWriteTypedVector(const std::vector& val, status_t(Parcel::*write_func)(U)); template + status_t writeNullableTypedVector(const std::optional>& val, + status_t(Parcel::*write_func)(const T&)); + template status_t writeNullableTypedVector(const std::unique_ptr>& val, status_t(Parcel::*write_func)(const T&)); template + status_t writeNullableTypedVector(const std::optional>& val, + status_t(Parcel::*write_func)(T)); + template status_t writeNullableTypedVector(const std::unique_ptr>& val, status_t(Parcel::*write_func)(T)); template @@ -688,6 +756,15 @@ status_t Parcel::writeVectorSize(const std::vector& val) { return writeInt32(static_cast(val.size())); } +template +status_t Parcel::writeVectorSize(const std::optional>& val) { + if (!val) { + return writeInt32(-1); + } + + return writeVectorSize(*val); +} + template status_t Parcel::writeVectorSize(const std::unique_ptr>& val) { if (!val) { @@ -712,6 +789,22 @@ status_t Parcel::resizeOutVector(std::vector* val) const { return OK; } +template +status_t Parcel::resizeOutVector(std::optional>* val) const { + int32_t size; + status_t err = readInt32(&size); + if (err != NO_ERROR) { + return err; + } + + val->reset(); + if (size >= 0) { + val->emplace(size_t(size)); + } + + return OK; +} + template status_t Parcel::resizeOutVector(std::unique_ptr>* val) const { int32_t size; @@ -744,6 +837,25 @@ status_t Parcel::reserveOutVector(std::vector* val, size_t* size) const { return OK; } +template +status_t Parcel::reserveOutVector(std::optional>* val, size_t* size) const { + int32_t read_size; + status_t err = readInt32(&read_size); + if (err != NO_ERROR) { + return err; + } + + if (read_size >= 0) { + *size = static_cast(read_size); + val->emplace(); + (*val)->reserve(*size); + } else { + val->reset(); + } + + return OK; +} + template status_t Parcel::reserveOutVector(std::unique_ptr>* val, size_t* size) const { @@ -838,6 +950,30 @@ status_t Parcel::readTypedVector(std::vector* val, return unsafeReadTypedVector(val, read_func); } +template +status_t Parcel::readNullableTypedVector(std::optional>* val, + status_t(Parcel::*read_func)(T*) const) const { + const size_t start = dataPosition(); + int32_t size; + status_t status = readInt32(&size); + val->reset(); + + if (status != OK || size < 0) { + return status; + } + + setDataPosition(start); + val->emplace(); + + status = unsafeReadTypedVector(&**val, read_func); + + if (status != OK) { + val->reset(); + } + + return status; +} + template status_t Parcel::readNullableTypedVector(std::unique_ptr>* val, status_t(Parcel::*read_func)(T*) const) const { @@ -898,6 +1034,16 @@ status_t Parcel::writeTypedVector(const std::vector& val, return unsafeWriteTypedVector(val, write_func); } +template +status_t Parcel::writeNullableTypedVector(const std::optional>& val, + status_t(Parcel::*write_func)(const T&)) { + if (!val) { + return this->writeInt32(-1); + } + + return unsafeWriteTypedVector(*val, write_func); +} + template status_t Parcel::writeNullableTypedVector(const std::unique_ptr>& val, status_t(Parcel::*write_func)(const T&)) { @@ -908,6 +1054,16 @@ status_t Parcel::writeNullableTypedVector(const std::unique_ptr>& return unsafeWriteTypedVector(*val, write_func); } +template +status_t Parcel::writeNullableTypedVector(const std::optional>& val, + status_t(Parcel::*write_func)(T)) { + if (!val) { + return this->writeInt32(-1); + } + + return unsafeWriteTypedVector(*val, write_func); +} + template status_t Parcel::writeNullableTypedVector(const std::unique_ptr>& val, status_t(Parcel::*write_func)(T)) { @@ -923,6 +1079,30 @@ status_t Parcel::readParcelableVector(std::vector* val) const { return unsafeReadTypedVector(val, &Parcel::readParcelable); } +template +status_t Parcel::readParcelableVector(std::optional>>* val) const { + const size_t start = dataPosition(); + int32_t size; + status_t status = readInt32(&size); + val->reset(); + + if (status != OK || size < 0) { + return status; + } + + setDataPosition(start); + val->emplace(); + + using NullableT = std::optional; + status = unsafeReadTypedVector(&**val, &Parcel::readParcelable); + + if (status != OK) { + val->reset(); + } + + return status; +} + template status_t Parcel::readParcelableVector(std::unique_ptr>>* val) const { const size_t start = dataPosition(); @@ -937,7 +1117,8 @@ status_t Parcel::readParcelableVector(std::unique_ptrreset(new std::vector>()); - status = unsafeReadTypedVector(val->get(), &Parcel::readParcelable); + using NullableT = std::unique_ptr; + status = unsafeReadTypedVector(val->get(), &Parcel::readParcelable); if (status != OK) { val->reset(); @@ -946,6 +1127,29 @@ status_t Parcel::readParcelableVector(std::unique_ptr +status_t Parcel::readParcelable(std::optional* parcelable) const { + const size_t start = dataPosition(); + int32_t present; + status_t status = readInt32(&present); + parcelable->reset(); + + if (status != OK || !present) { + return status; + } + + setDataPosition(start); + parcelable->emplace(); + + status = readParcelable(&**parcelable); + + if (status != OK) { + parcelable->reset(); + } + + return status; +} + template status_t Parcel::readParcelable(std::unique_ptr* parcelable) const { const size_t start = dataPosition(); @@ -969,6 +1173,11 @@ status_t Parcel::readParcelable(std::unique_ptr* parcelable) const { return status; } +template +status_t Parcel::writeNullableParcelable(const std::optional& parcelable) { + return writeRawNullableParcelable(parcelable ? &*parcelable : nullptr); +} + template status_t Parcel::writeNullableParcelable(const std::unique_ptr& parcelable) { return writeRawNullableParcelable(parcelable.get()); @@ -979,6 +1188,16 @@ status_t Parcel::writeParcelableVector(const std::vector& val) { return unsafeWriteTypedVector(val, &Parcel::writeParcelable); } +template +status_t Parcel::writeParcelableVector(const std::optional>>& val) { + if (!val) { + return this->writeInt32(-1); + } + + using NullableT = std::optional; + return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable); +} + template status_t Parcel::writeParcelableVector(const std::unique_ptr>>& val) { if (val.get() == nullptr) { @@ -994,7 +1213,8 @@ status_t Parcel::writeParcelableVector(const std::shared_ptrwriteInt32(-1); } - return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable); + using NullableT = std::unique_ptr; + return unsafeWriteTypedVector(*val, &Parcel::writeNullableParcelable); } template,int32_t>, bool>> @@ -1011,6 +1231,11 @@ status_t Parcel::writeEnumVector(const std::vector& val) { return writeByteVectorInternal(reinterpret_cast(val.data()), val.size()); } template && std::is_same_v,int8_t>, bool>> +status_t Parcel::writeEnumVector(const std::optional>& val) { + if (!val) return writeInt32(-1); + return writeByteVectorInternal(reinterpret_cast(val->data()), val->size()); +} +template && std::is_same_v,int8_t>, bool>> status_t Parcel::writeEnumVector(const std::unique_ptr>& val) { if (!val) return writeInt32(-1); return writeByteVectorInternal(reinterpret_cast(val->data()), val->size()); @@ -1020,6 +1245,10 @@ status_t Parcel::writeEnumVector(const std::vector& val) { return writeTypedVector(val, &Parcel::writeEnum); } template && !std::is_same_v,int8_t>, bool>> +status_t Parcel::writeEnumVector(const std::optional>& val) { + return writeNullableTypedVector(val, &Parcel::writeEnum); +} +template && !std::is_same_v,int8_t>, bool>> status_t Parcel::writeEnumVector(const std::unique_ptr>& val) { return writeNullableTypedVector(val, &Parcel::writeEnum); } @@ -1051,6 +1280,17 @@ status_t Parcel::readEnumVector(std::vector* val) const { return readByteVectorInternal(val, size); } template && std::is_same_v,int8_t>, bool>> +status_t Parcel::readEnumVector(std::optional>* val) const { + size_t size; + if (status_t status = reserveOutVector(val, &size); status != OK) return status; + if (!*val) { + // reserveOutVector does not create the out vector if size is < 0. + // This occurs when writing a null Enum vector. + return OK; + } + return readByteVectorInternal(&**val, size); +} +template && std::is_same_v,int8_t>, bool>> status_t Parcel::readEnumVector(std::unique_ptr>* val) const { size_t size; if (status_t status = reserveOutVector(val, &size); status != OK) return status; @@ -1066,6 +1306,10 @@ status_t Parcel::readEnumVector(std::vector* val) const { return readTypedVector(val, &Parcel::readEnum); } template && !std::is_same_v,int8_t>, bool>> +status_t Parcel::readEnumVector(std::optional>* val) const { + return readNullableTypedVector(val, &Parcel::readEnum); +} +template && !std::is_same_v,int8_t>, bool>> status_t Parcel::readEnumVector(std::unique_ptr>* val) const { return readNullableTypedVector(val, &Parcel::readEnum); } diff --git a/libs/binder/include/binder/ParcelFileDescriptor.h b/libs/binder/include/binder/ParcelFileDescriptor.h index 4635ad84c6..2ede6c4b59 100644 --- a/libs/binder/include/binder/ParcelFileDescriptor.h +++ b/libs/binder/include/binder/ParcelFileDescriptor.h @@ -32,6 +32,7 @@ public: ParcelFileDescriptor(); explicit ParcelFileDescriptor(android::base::unique_fd fd); ParcelFileDescriptor(ParcelFileDescriptor&& other) : mFd(std::move(other.mFd)) { } + ParcelFileDescriptor& operator=(ParcelFileDescriptor&& other) = default; ~ParcelFileDescriptor() override; int get() const { return mFd.get(); } -- cgit v1.2.3-59-g8ed1b From 1e219c147e9b6ab34058613424a3c86b69b5e6dc Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Thu, 27 Feb 2020 16:27:49 -0800 Subject: libbinder: move AppOpManager globals into function Bug: 148177595 Test: N/A Change-Id: Ibf19d8fbe82595f249fddf8c918c1750bc750f66 --- libs/binder/AppOpsManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index aeca12b582..b2a6f3bbe9 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -43,11 +43,10 @@ const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; } // namespace -static String16 _appops("appops"); -static pthread_mutex_t gClientIdMutex = PTHREAD_MUTEX_INITIALIZER; -static sp gClientId; - static const sp& getClientId() { + static pthread_mutex_t gClientIdMutex = PTHREAD_MUTEX_INITIALIZER; + static sp gClientId; + pthread_mutex_lock(&gClientIdMutex); if (gClientId == nullptr) { gClientId = new BBinder(); @@ -72,6 +71,7 @@ sp AppOpsManager::getService() { return NULL; } #else sp AppOpsManager::getService() { + static String16 _appops("appops"); std::lock_guard scoped_lock(mLock); int64_t startTime = 0; -- cgit v1.2.3-59-g8ed1b From d83ecb04f9c78e23e8f413167f0b25642efef490 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Wed, 4 Mar 2020 18:02:02 -0800 Subject: libbinder: cleanup appOpNote globals Removed unused. Moved used to functions (save memory when unused). Bug: 148177595 Test: th Change-Id: Ifb374759206b411efcc269c2977573213c60ccb4 --- libs/binder/AppOpsManager.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index aeca12b582..0bba6ca19b 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -56,12 +56,6 @@ static const sp& getClientId() { return gClientId; } -thread_local uint64_t notedAppOpsInThisBinderTransaction[2]; -thread_local int32_t uidOfThisBinderTransaction = -1; - -// Whether an appop should be collected: 0 == not initialized, 1 == don't note, 2 == note -uint8_t appOpsToNote[AppOpsManager::_NUM_OP] = {0}; - AppOpsManager::AppOpsManager() { } @@ -192,6 +186,9 @@ void AppOpsManager::setCameraAudioRestriction(int32_t mode) { // check it the appops needs to be collected and cache result bool AppOpsManager::shouldCollectNotes(int32_t opcode) { + // Whether an appop should be collected: 0 == not initialized, 1 == don't note, 2 == note + static uint8_t appOpsToNote[AppOpsManager::_NUM_OP] = {0}; + if (appOpsToNote[opcode] == 0) { if (getService()->shouldCollectNotes(opcode)) { appOpsToNote[opcode] = 2; -- cgit v1.2.3-59-g8ed1b From 15a63a8b8fde09c61b62cb11dd70112019d6c7d0 Mon Sep 17 00:00:00 2001 From: Steven Moreland Date: Thu, 27 Feb 2020 16:31:13 -0800 Subject: libbinder: remove __BRILLO__ carveouts distracting Test: N/A Bug: 148177595 Change-Id: I7fd165fdcff7b04688d5763994460b74a781d24e --- libs/binder/AppOpsManager.cpp | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index b2a6f3bbe9..a22cf25671 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -30,19 +30,6 @@ namespace android { -namespace { - -#if defined(__BRILLO__) -// Because Brillo has no application model, security policy is managed -// statically (at build time) with SELinux controls. -// As a consequence, it also never runs the AppOpsManager service. -const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_ALLOWED; -#else -const int APP_OPS_MANAGER_UNAVAILABLE_MODE = AppOpsManager::MODE_IGNORED; -#endif // defined(__BRILLO__) - -} // namespace - static const sp& getClientId() { static pthread_mutex_t gClientIdMutex = PTHREAD_MUTEX_INITIALIZER; static sp gClientId; @@ -65,10 +52,6 @@ AppOpsManager::AppOpsManager() { } -#if defined(__BRILLO__) -// There is no AppOpsService on Brillo -sp AppOpsManager::getService() { return NULL; } -#else sp AppOpsManager::getService() { static String16 _appops("appops"); @@ -96,14 +79,13 @@ sp AppOpsManager::getService() } return service; } -#endif // defined(__BRILLO__) int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage) { sp service = getService(); return service != nullptr ? service->checkOperation(op, uid, callingPackage) - : APP_OPS_MANAGER_UNAVAILABLE_MODE; + : AppOpsManager::MODE_IGNORED; } int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid, @@ -111,7 +93,7 @@ int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t ui sp service = getService(); return service != nullptr ? service->checkAudioOperation(op, usage, uid, callingPackage) - : APP_OPS_MANAGER_UNAVAILABLE_MODE; + : AppOpsManager::MODE_IGNORED; } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage) { @@ -125,7 +107,7 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa int32_t mode = service != nullptr ? service->noteOperation(op, uid, callingPackage, featureId, shouldCollectNotes(op), message) - : APP_OPS_MANAGER_UNAVAILABLE_MODE; + : AppOpsManager::MODE_IGNORED; return mode; } @@ -143,7 +125,7 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c int32_t mode = service != nullptr ? service->startOperation(getClientId(), op, uid, callingPackage, featureId, startIfModeDefault, shouldCollectNotes(op), message) - : APP_OPS_MANAGER_UNAVAILABLE_MODE; + : AppOpsManager::MODE_IGNORED; return mode; } -- cgit v1.2.3-59-g8ed1b From 3f6efd831564cb05d3c7e7699b009e3e7cbcf4da Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Thu, 5 Mar 2020 15:06:19 -0800 Subject: Rename featureId -> attributionTag Bug: 148792795 Test: TH Change-Id: Ic56606795e5e68ba76794198faf496eec6d87cd0 Exempt-From-Owner-Approval: API rename Merged-In: Ic56606795e5e68ba76794198faf496eec6d87cd0 --- libs/binder/AppOpsManager.cpp | 14 +++++++------- libs/binder/IAppOpsService.cpp | 30 ++++++++++++++--------------- libs/binder/include/binder/AppOpsManager.h | 6 +++--- libs/binder/include/binder/IAppOpsService.h | 6 +++--- 4 files changed, 28 insertions(+), 28 deletions(-) (limited to 'libs/binder/AppOpsManager.cpp') diff --git a/libs/binder/AppOpsManager.cpp b/libs/binder/AppOpsManager.cpp index e732829ada..1c6b49135d 100644 --- a/libs/binder/AppOpsManager.cpp +++ b/libs/binder/AppOpsManager.cpp @@ -96,11 +96,11 @@ int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPa } int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::optional& featureId, const String16& message) { + const std::optional& attributionTag, const String16& message) { sp service = getService(); int32_t mode = service != nullptr - ? service->noteOperation(op, uid, callingPackage, featureId, shouldCollectNotes(op), - message) + ? service->noteOperation(op, uid, callingPackage, attributionTag, + shouldCollectNotes(op), message) : AppOpsManager::MODE_IGNORED; return mode; @@ -113,12 +113,12 @@ int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& c } int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const std::optional& featureId, + bool startIfModeDefault, const std::optional& attributionTag, const String16& message) { sp service = getService(); int32_t mode = service != nullptr ? service->startOperation(getClientId(), op, uid, callingPackage, - featureId, startIfModeDefault, shouldCollectNotes(op), message) + attributionTag, startIfModeDefault, shouldCollectNotes(op), message) : AppOpsManager::MODE_IGNORED; return mode; @@ -129,10 +129,10 @@ void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPac } void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::optional& callingFeatureId) { + const std::optional& attributionTag) { sp service = getService(); if (service != nullptr) { - service->finishOperation(getClientId(), op, uid, callingPackage, callingFeatureId); + service->finishOperation(getClientId(), op, uid, callingPackage, attributionTag); } } diff --git a/libs/binder/IAppOpsService.cpp b/libs/binder/IAppOpsService.cpp index 50e23b50a7..cd78866624 100644 --- a/libs/binder/IAppOpsService.cpp +++ b/libs/binder/IAppOpsService.cpp @@ -49,14 +49,14 @@ public: } virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::optional& featureId, bool shouldCollectAsyncNotedOp, + const std::optional& attributionTag, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); - data.writeString16(featureId); + data.writeString16(attributionTag); data.writeInt32(shouldCollectAsyncNotedOp ? 1 : 0); data.writeString16(message); remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply); @@ -66,7 +66,7 @@ public: } virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::optional& featureId, + const String16& packageName, const std::optional& attributionTag, bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); @@ -74,7 +74,7 @@ public: data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); - data.writeString16(featureId); + data.writeString16(attributionTag); data.writeInt32(startIfModeDefault ? 1 : 0); data.writeInt32(shouldCollectAsyncNotedOp ? 1 : 0); data.writeString16(message); @@ -85,14 +85,14 @@ public: } virtual void finishOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::optional& featureId) { + const String16& packageName, const std::optional& attributionTag) { Parcel data, reply; data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor()); data.writeStrongBinder(token); data.writeInt32(code); data.writeInt32(uid); data.writeString16(packageName); - data.writeString16(featureId); + data.writeString16(attributionTag); remote()->transact(FINISH_OPERATION_TRANSACTION, data, &reply); } @@ -184,11 +184,11 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::optional featureId; - data.readString16(&featureId); + std::optional attributionTag; + data.readString16(&attributionTag); bool shouldCollectAsyncNotedOp = data.readInt32() == 1; String16 message = data.readString16(); - int32_t res = noteOperation(code, uid, packageName, featureId, + int32_t res = noteOperation(code, uid, packageName, attributionTag, shouldCollectAsyncNotedOp, message); reply->writeNoException(); reply->writeInt32(res); @@ -200,12 +200,12 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::optional featureId; - data.readString16(&featureId); + std::optional attributionTag; + data.readString16(&attributionTag); bool startIfModeDefault = data.readInt32() == 1; bool shouldCollectAsyncNotedOp = data.readInt32() == 1; String16 message = data.readString16(); - int32_t res = startOperation(token, code, uid, packageName, featureId, + int32_t res = startOperation(token, code, uid, packageName, attributionTag, startIfModeDefault, shouldCollectAsyncNotedOp, message); reply->writeNoException(); reply->writeInt32(res); @@ -217,9 +217,9 @@ status_t BnAppOpsService::onTransact( int32_t code = data.readInt32(); int32_t uid = data.readInt32(); String16 packageName = data.readString16(); - std::optional featureId; - data.readString16(&featureId); - finishOperation(token, code, uid, packageName, featureId); + std::optional attributionTag; + data.readString16(&attributionTag); + finishOperation(token, code, uid, packageName, attributionTag); reply->writeNoException(); return NO_ERROR; } break; diff --git a/libs/binder/include/binder/AppOpsManager.h b/libs/binder/include/binder/AppOpsManager.h index e4641822ad..4169243c1f 100644 --- a/libs/binder/include/binder/AppOpsManager.h +++ b/libs/binder/include/binder/AppOpsManager.h @@ -136,18 +136,18 @@ public: // const String16&) instead int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage); int32_t noteOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::optional& featureId, const String16& message); + const std::optional& attributionTag, const String16& message); // @Deprecated, use startOpNoThrow(int32_t, int32_t, const String16&, bool, const String16&, // const String16&) instead int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, bool startIfModeDefault); int32_t startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage, - bool startIfModeDefault, const std::optional& featureId, + bool startIfModeDefault, const std::optional& attributionTag, const String16& message); // @Deprecated, use finishOp(int32_t, int32_t, const String16&, bool, const String16&) instead void finishOp(int32_t op, int32_t uid, const String16& callingPackage); void finishOp(int32_t op, int32_t uid, const String16& callingPackage, - const std::optional& featureId); + const std::optional& attributionTag); void startWatchingMode(int32_t op, const String16& packageName, const sp& callback); void stopWatchingMode(const sp& callback); diff --git a/libs/binder/include/binder/IAppOpsService.h b/libs/binder/include/binder/IAppOpsService.h index 95a80ff268..a4a20c8b10 100644 --- a/libs/binder/include/binder/IAppOpsService.h +++ b/libs/binder/include/binder/IAppOpsService.h @@ -38,13 +38,13 @@ public: virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) = 0; virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName, - const std::optional& featureId, bool shouldCollectAsyncNotedOp, + const std::optional& attributionTag, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual int32_t startOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::optional& featureId, + const String16& packageName, const std::optional& attributionTag, bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual void finishOperation(const sp& token, int32_t code, int32_t uid, - const String16& packageName, const std::optional& featureId) = 0; + const String16& packageName, const std::optional& attributionTag) = 0; virtual void startWatchingMode(int32_t op, const String16& packageName, const sp& callback) = 0; virtual void stopWatchingMode(const sp& callback) = 0; -- cgit v1.2.3-59-g8ed1b