summaryrefslogtreecommitdiff
path: root/libs/permission/IAppOpsService.cpp
diff options
context:
space:
mode:
author Karishma Vakil <kvakil@google.com> 2023-08-21 17:40:30 +0000
committer Karishma Vakil <kvakil@google.com> 2023-11-01 01:37:33 +0000
commit14f7ae8fa66cf12bd6ef641635d9d0a73bf92993 (patch)
tree9bd5a6fb1f9e57dbe19fc64ddd4fbf91759e9a92 /libs/permission/IAppOpsService.cpp
parent574cfcf497cd70675d1106cd522ce07bf282b141 (diff)
[DeviceAware] Use AttributionSourceState in native AppOpsService checkOp, noteOp,
startOp, finishOp methods This allows us to reduce the number of parameters being passed around and also enables easy addition of new parameters such as device id. Note that this change is unflagged and is meant to be a pure refactor. This is preparatory CL and no new methods are being added to AppOpsManager yet, but will be needed to allow clients to pass in device id. Bug: 299160174 Test: atest CtsAppOpsTestCases CtsAppOps2TestCases Change-Id: Ic2fdb088b3a3913a510c8c73f24570147267efd0
Diffstat (limited to 'libs/permission/IAppOpsService.cpp')
-rw-r--r--libs/permission/IAppOpsService.cpp95
1 files changed, 49 insertions, 46 deletions
diff --git a/libs/permission/IAppOpsService.cpp b/libs/permission/IAppOpsService.cpp
index 7f235a4541..33dd24d728 100644
--- a/libs/permission/IAppOpsService.cpp
+++ b/libs/permission/IAppOpsService.cpp
@@ -26,6 +26,8 @@
namespace android {
+using android::content::AttributionSourceState;
+
// ----------------------------------------------------------------------
class BpAppOpsService : public BpInterface<IAppOpsService>
@@ -36,31 +38,30 @@ public:
{
}
- virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) {
+ virtual int32_t checkOperationWithState(int32_t code,
+ const AttributionSourceState &attributionSourceState) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- remote()->transact(CHECK_OPERATION_TRANSACTION, data, &reply);
+ data.writeParcelable(attributionSourceState);
+ remote()->transact(CHECK_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
return reply.readInt32();
}
- virtual int32_t noteOperation(int32_t code, int32_t uid, const String16& packageName,
- const std::optional<String16>& attributionTag, bool shouldCollectAsyncNotedOp,
- const String16& message, bool shouldCollectMessage) {
+ virtual int32_t noteOperationWithState(int32_t code,
+ const AttributionSourceState& attributionSourceState,
+ bool shouldCollectAsyncNotedOp, const String16& message,
+ bool shouldCollectMessage) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- data.writeString16(attributionTag);
+ data.writeParcelable(attributionSourceState);
data.writeBool(shouldCollectAsyncNotedOp);
data.writeString16(message);
data.writeBool(shouldCollectMessage);
- remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply);
+ remote()->transact(NOTE_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
// TODO b/184855056: extract to class
@@ -69,22 +70,20 @@ public:
return reply.readInt32();
}
- virtual int32_t startOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName, const std::optional<String16>& attributionTag,
- bool startIfModeDefault, bool shouldCollectAsyncNotedOp, const String16& message,
+ virtual int32_t startOperationWithState(const sp<IBinder>& token, int32_t code,
+ const AttributionSourceState& attributionSourceState, bool startIfModeDefault,
+ bool shouldCollectAsyncNotedOp, const String16& message,
bool shouldCollectMessage) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeStrongBinder(token);
data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- data.writeString16(attributionTag);
+ data.writeParcelable(attributionSourceState);
data.writeBool(startIfModeDefault);
data.writeBool(shouldCollectAsyncNotedOp);
data.writeString16(message);
data.writeBool(shouldCollectMessage);
- remote()->transact(START_OPERATION_TRANSACTION, data, &reply);
+ remote()->transact(START_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
// TODO b/184855056: extract to class
@@ -93,16 +92,14 @@ public:
return reply.readInt32();
}
- virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
- const String16& packageName, const std::optional<String16>& attributionTag) {
+ virtual void finishOperationWithState(const sp<IBinder>& token, int32_t code,
+ const AttributionSourceState& attributionSourceState) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeStrongBinder(token);
data.writeInt32(code);
- data.writeInt32(uid);
- data.writeString16(packageName);
- data.writeString16(attributionTag);
- remote()->transact(FINISH_OPERATION_TRANSACTION, data, &reply);
+ data.writeParcelable(attributionSourceState);
+ remote()->transact(FINISH_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
}
virtual void startWatchingMode(int32_t op, const String16& packageName,
@@ -189,59 +186,65 @@ status_t BnAppOpsService::onTransact(
{
//printf("AppOpsService received: "); data.print();
switch(code) {
- case CHECK_OPERATION_TRANSACTION: {
+ case CHECK_OPERATION_WITH_STATE_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- int32_t res = checkOperation(code, uid, packageName);
+ AttributionSourceState attributionSourceState;
+ status_t status = data.readParcelable(&attributionSourceState);
+ if (status != NO_ERROR) {
+ return status;
+ }
+ int32_t res = checkOperationWithState(code, attributionSourceState);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case NOTE_OPERATION_TRANSACTION: {
+ case NOTE_OPERATION_WITH_STATE_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- std::optional<String16> attributionTag;
- data.readString16(&attributionTag);
+ AttributionSourceState attributionSourceState;
+ status_t status = data.readParcelable(&attributionSourceState);
+ if (status != NO_ERROR) {
+ return status;
+ }
bool shouldCollectAsyncNotedOp = data.readBool();
String16 message = data.readString16();
bool shouldCollectMessage = data.readBool();
- int32_t res = noteOperation(code, uid, packageName, attributionTag,
+ int32_t res = noteOperationWithState(code, attributionSourceState,
shouldCollectAsyncNotedOp, message, shouldCollectMessage);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case START_OPERATION_TRANSACTION: {
+ case START_OPERATION_WITH_STATE_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
sp<IBinder> token = data.readStrongBinder();
int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- std::optional<String16> attributionTag;
- data.readString16(&attributionTag);
+ AttributionSourceState attributionSourceState;
+ status_t status = data.readParcelable(&attributionSourceState);
+ if (status != NO_ERROR) {
+ return status;
+ }
bool startIfModeDefault = data.readBool();
bool shouldCollectAsyncNotedOp = data.readBool();
String16 message = data.readString16();
bool shouldCollectMessage = data.readBool();
- int32_t res = startOperation(token, code, uid, packageName, attributionTag,
+ int32_t res = startOperationWithState(token, code, attributionSourceState,
startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case FINISH_OPERATION_TRANSACTION: {
+ case FINISH_OPERATION_WITH_STATE_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
sp<IBinder> token = data.readStrongBinder();
int32_t code = data.readInt32();
- int32_t uid = data.readInt32();
- String16 packageName = data.readString16();
- std::optional<String16> attributionTag;
- data.readString16(&attributionTag);
- finishOperation(token, code, uid, packageName, attributionTag);
+ AttributionSourceState attributionSourceState;
+ status_t status = data.readParcelable(&attributionSourceState);
+ if (status != NO_ERROR) {
+ return status;
+ }
+ finishOperationWithState(token, code, attributionSourceState);
reply->writeNoException();
return NO_ERROR;
} break;