diff options
| author | 2020-01-04 03:23:55 +0000 | |
|---|---|---|
| committer | 2020-01-04 03:23:55 +0000 | |
| commit | ae73bff6bfc908e61b7621c081699cc99b8ba921 (patch) | |
| tree | 3d87f4d611032139c8b1a8c78d3f285ac6f1c615 | |
| parent | 1ca25ba9dc813b1a97e14997ce6bf5cb59e42be5 (diff) | |
| parent | 3879cf6939e5fb177ff08328a000dd1ec4c6ffc8 (diff) | |
Merge "Collect AsyncNotedAppOp in same call as native noteOp"
| -rw-r--r-- | libs/binder/AppOpsManager.cpp | 49 | ||||
| -rw-r--r-- | libs/binder/IAppOpsService.cpp | 46 | ||||
| -rw-r--r-- | libs/binder/include/binder/AppOpsManager.h | 5 | ||||
| -rw-r--r-- | libs/binder/include/binder/IAppOpsService.h | 13 |
4 files changed, 29 insertions, 84 deletions
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<String16>& featureId, const String16& message) { sp<IAppOpsService> 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<IAppOpsService> 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<IAppOpsService> 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<String16>& 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<String16>(), uid, packageName, opCode, featureId, message); -} - -void AppOpsManager::noteAsyncOp(const std::unique_ptr<String16>& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr<String16>& featureId, - const String16& message) { - sp<IAppOpsService> 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<String16>& featureId) { + const std::unique_ptr<String16>& 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<IBinder>& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr<String16>& 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<String16>& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr<String16>& 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<String16> 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<String16> 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<String16> callingPackageName; - data.readString16(&callingPackageName); - int32_t uid = data.readInt32(); - String16 packageName = data.readString16(); - int32_t opCode = data.readInt32(); - std::unique_ptr<String16> 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<IAppOpsCallback>& callback); int32_t permissionToOpCode(const String16& permission); void setCameraAudioRestriction(int32_t mode); - void noteAsyncOp(const std::unique_ptr<String16>& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr<String16>& featureId, - const String16& message); private: Mutex mLock; sp<IAppOpsService> mService; sp<IAppOpsService> getService(); - void markAppOpNoted(int32_t uid, const String16& packageName, int32_t opCode, - const std::unique_ptr<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 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<String16>& featureId) = 0; + const std::unique_ptr<String16>& featureId, bool shouldCollectAsyncNotedOp, + const String16& message) = 0; virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr<String16>& featureId, - bool startIfModeDefault) = 0; + bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message) = 0; virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid, const String16& packageName, const std::unique_ptr<String16>& 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<String16>& callingPackageName, int32_t uid, - const String16& packageName, int32_t opCode, const std::unique_ptr<String16>& 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 { |