Revert "[DeviceAware] Use AttributionSourceState in native AppOp..."
Revert submission 24499968-appops-deviceid
Reason for revert: Causing perf regression b/308786093
Reverted changes: /q/submissionid:24499968-appops-deviceid
Change-Id: I7e0da4a493b85e1296b41db09e114dd0c8b9e244
diff --git a/libs/permission/Android.bp b/libs/permission/Android.bp
index 86dcaef..0eeca54 100644
--- a/libs/permission/Android.bp
+++ b/libs/permission/Android.bp
@@ -20,12 +20,6 @@
],
}
-filegroup {
- name: "framework-permission-aidl-filegroup",
- srcs: ["aidl/android/**/*.aidl"],
- path: "aidl",
-}
-
cc_library {
name: "libpermission",
host_supported: true,
@@ -41,7 +35,6 @@
"-Werror",
],
srcs: [
- ":framework-permission-aidl-filegroup",
"AppOpsManager.cpp",
"IAppOpsCallback.cpp",
"IAppOpsService.cpp",
diff --git a/libs/permission/AppOpsManager.cpp b/libs/permission/AppOpsManager.cpp
index b407d02..6959274 100644
--- a/libs/permission/AppOpsManager.cpp
+++ b/libs/permission/AppOpsManager.cpp
@@ -31,9 +31,6 @@
namespace android {
-using ::android::String16;
-using ::android::String8;
-
static const sp<IBinder>& getClientId() {
static pthread_mutex_t gClientIdMutex = PTHREAD_MUTEX_INITIALIZER;
static sp<IBinder> gClientId;
@@ -46,11 +43,6 @@
return gClientId;
}
-
-static std::string getString(const String16& stringToConvert) {
- return std::string(String8(stringToConvert).c_str());
-}
-
AppOpsManager::AppOpsManager()
{
}
@@ -86,14 +78,9 @@
int32_t AppOpsManager::checkOp(int32_t op, int32_t uid, const String16& callingPackage)
{
sp<IAppOpsService> service = getService();
- if (service == nullptr) {
- return AppOpsManager::MODE_IGNORED;
- }
- AttributionSourceState attributionSourceState;
- attributionSourceState.uid = uid;
- attributionSourceState.packageName = getString(callingPackage);
-
- return service->checkOperationWithState(op, attributionSourceState);
+ return service != nullptr
+ ? service->checkOperation(op, uid, callingPackage)
+ : AppOpsManager::MODE_IGNORED;
}
int32_t AppOpsManager::checkAudioOpNoThrow(int32_t op, int32_t usage, int32_t uid,
@@ -112,18 +99,12 @@
int32_t AppOpsManager::noteOp(int32_t op, int32_t uid, const String16& callingPackage,
const std::optional<String16>& attributionTag, const String16& message) {
sp<IAppOpsService> service = getService();
- if (service == nullptr) {
- return AppOpsManager::MODE_IGNORED;
- }
- AttributionSourceState attributionSourceState;
- attributionSourceState.uid = uid;
- attributionSourceState.packageName = getString(callingPackage);
- if (attributionTag.has_value()) {
- attributionSourceState.attributionTag = getString(attributionTag.value());
- }
+ int32_t mode = service != nullptr
+ ? service->noteOperation(op, uid, callingPackage, attributionTag,
+ shouldCollectNotes(op), message, uid == AID_SYSTEM)
+ : AppOpsManager::MODE_IGNORED;
- return service->noteOperationWithState(op, attributionSourceState,
- shouldCollectNotes(op), message, uid == AID_SYSTEM);
+ return mode;
}
int32_t AppOpsManager::startOpNoThrow(int32_t op, int32_t uid, const String16& callingPackage,
@@ -136,18 +117,13 @@
bool startIfModeDefault, const std::optional<String16>& attributionTag,
const String16& message) {
sp<IAppOpsService> service = getService();
- if (service == nullptr) {
- return AppOpsManager::MODE_IGNORED;
- }
- AttributionSourceState attributionSourceState;
- attributionSourceState.uid = uid;
- attributionSourceState.packageName = getString(callingPackage);
- if (attributionTag.has_value()) {
- attributionSourceState.attributionTag = getString(attributionTag.value());
- }
+ int32_t mode = service != nullptr
+ ? service->startOperation(getClientId(), op, uid, callingPackage,
+ attributionTag, startIfModeDefault, shouldCollectNotes(op), message,
+ uid == AID_SYSTEM)
+ : AppOpsManager::MODE_IGNORED;
- return service->startOperationWithState(getClientId(), op, attributionSourceState,
- startIfModeDefault,shouldCollectNotes(op), message, uid == AID_SYSTEM);
+ return mode;
}
void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage) {
@@ -157,16 +133,9 @@
void AppOpsManager::finishOp(int32_t op, int32_t uid, const String16& callingPackage,
const std::optional<String16>& attributionTag) {
sp<IAppOpsService> service = getService();
- if (service == nullptr) {
- return;
+ if (service != nullptr) {
+ service->finishOperation(getClientId(), op, uid, callingPackage, attributionTag);
}
- AttributionSourceState attributionSourceState;
- attributionSourceState.uid = uid;
- attributionSourceState.packageName = getString(callingPackage);
- if (attributionTag.has_value()) {
- attributionSourceState.attributionTag = getString(attributionTag.value());
- }
- service->finishOperationWithState(getClientId(), op, attributionSourceState);
}
void AppOpsManager::startWatchingMode(int32_t op, const String16& packageName,
diff --git a/libs/permission/IAppOpsService.cpp b/libs/permission/IAppOpsService.cpp
index 33dd24d..7f235a4 100644
--- a/libs/permission/IAppOpsService.cpp
+++ b/libs/permission/IAppOpsService.cpp
@@ -26,8 +26,6 @@
namespace android {
-using android::content::AttributionSourceState;
-
// ----------------------------------------------------------------------
class BpAppOpsService : public BpInterface<IAppOpsService>
@@ -38,30 +36,31 @@
{
}
- virtual int32_t checkOperationWithState(int32_t code,
- const AttributionSourceState &attributionSourceState) {
+ virtual int32_t checkOperation(int32_t code, int32_t uid, const String16& packageName) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeInt32(code);
- data.writeParcelable(attributionSourceState);
- remote()->transact(CHECK_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
+ data.writeInt32(uid);
+ data.writeString16(packageName);
+ remote()->transact(CHECK_OPERATION_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
return reply.readInt32();
}
- virtual int32_t noteOperationWithState(int32_t code,
- const AttributionSourceState& attributionSourceState,
- bool shouldCollectAsyncNotedOp, const String16& message,
- bool shouldCollectMessage) {
+ 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) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeInt32(code);
- data.writeParcelable(attributionSourceState);
+ data.writeInt32(uid);
+ data.writeString16(packageName);
+ data.writeString16(attributionTag);
data.writeBool(shouldCollectAsyncNotedOp);
data.writeString16(message);
data.writeBool(shouldCollectMessage);
- remote()->transact(NOTE_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
+ remote()->transact(NOTE_OPERATION_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
// TODO b/184855056: extract to class
@@ -70,20 +69,22 @@
return reply.readInt32();
}
- virtual int32_t startOperationWithState(const sp<IBinder>& token, int32_t code,
- const AttributionSourceState& attributionSourceState, bool startIfModeDefault,
- bool shouldCollectAsyncNotedOp, const String16& message,
+ 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,
bool shouldCollectMessage) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeStrongBinder(token);
data.writeInt32(code);
- data.writeParcelable(attributionSourceState);
+ data.writeInt32(uid);
+ data.writeString16(packageName);
+ data.writeString16(attributionTag);
data.writeBool(startIfModeDefault);
data.writeBool(shouldCollectAsyncNotedOp);
data.writeString16(message);
data.writeBool(shouldCollectMessage);
- remote()->transact(START_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
+ remote()->transact(START_OPERATION_TRANSACTION, data, &reply);
// fail on exception
if (reply.readExceptionCode() != 0) return MODE_ERRORED;
// TODO b/184855056: extract to class
@@ -92,14 +93,16 @@
return reply.readInt32();
}
- virtual void finishOperationWithState(const sp<IBinder>& token, int32_t code,
- const AttributionSourceState& attributionSourceState) {
+ virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
+ const String16& packageName, const std::optional<String16>& attributionTag) {
Parcel data, reply;
data.writeInterfaceToken(IAppOpsService::getInterfaceDescriptor());
data.writeStrongBinder(token);
data.writeInt32(code);
- data.writeParcelable(attributionSourceState);
- remote()->transact(FINISH_OPERATION_WITH_STATE_TRANSACTION, data, &reply);
+ data.writeInt32(uid);
+ data.writeString16(packageName);
+ data.writeString16(attributionTag);
+ remote()->transact(FINISH_OPERATION_TRANSACTION, data, &reply);
}
virtual void startWatchingMode(int32_t op, const String16& packageName,
@@ -186,65 +189,59 @@
{
//printf("AppOpsService received: "); data.print();
switch(code) {
- case CHECK_OPERATION_WITH_STATE_TRANSACTION: {
+ case CHECK_OPERATION_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
int32_t code = data.readInt32();
- AttributionSourceState attributionSourceState;
- status_t status = data.readParcelable(&attributionSourceState);
- if (status != NO_ERROR) {
- return status;
- }
- int32_t res = checkOperationWithState(code, attributionSourceState);
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ int32_t res = checkOperation(code, uid, packageName);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case NOTE_OPERATION_WITH_STATE_TRANSACTION: {
+ case NOTE_OPERATION_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
int32_t code = data.readInt32();
- AttributionSourceState attributionSourceState;
- status_t status = data.readParcelable(&attributionSourceState);
- if (status != NO_ERROR) {
- return status;
- }
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ std::optional<String16> attributionTag;
+ data.readString16(&attributionTag);
bool shouldCollectAsyncNotedOp = data.readBool();
String16 message = data.readString16();
bool shouldCollectMessage = data.readBool();
- int32_t res = noteOperationWithState(code, attributionSourceState,
+ int32_t res = noteOperation(code, uid, packageName, attributionTag,
shouldCollectAsyncNotedOp, message, shouldCollectMessage);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case START_OPERATION_WITH_STATE_TRANSACTION: {
+ case START_OPERATION_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
sp<IBinder> token = data.readStrongBinder();
int32_t code = data.readInt32();
- AttributionSourceState attributionSourceState;
- status_t status = data.readParcelable(&attributionSourceState);
- if (status != NO_ERROR) {
- return status;
- }
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ std::optional<String16> attributionTag;
+ data.readString16(&attributionTag);
bool startIfModeDefault = data.readBool();
bool shouldCollectAsyncNotedOp = data.readBool();
String16 message = data.readString16();
bool shouldCollectMessage = data.readBool();
- int32_t res = startOperationWithState(token, code, attributionSourceState,
+ int32_t res = startOperation(token, code, uid, packageName, attributionTag,
startIfModeDefault, shouldCollectAsyncNotedOp, message, shouldCollectMessage);
reply->writeNoException();
reply->writeInt32(res);
return NO_ERROR;
} break;
- case FINISH_OPERATION_WITH_STATE_TRANSACTION: {
+ case FINISH_OPERATION_TRANSACTION: {
CHECK_INTERFACE(IAppOpsService, data, reply);
sp<IBinder> token = data.readStrongBinder();
int32_t code = data.readInt32();
- AttributionSourceState attributionSourceState;
- status_t status = data.readParcelable(&attributionSourceState);
- if (status != NO_ERROR) {
- return status;
- }
- finishOperationWithState(token, code, attributionSourceState);
+ int32_t uid = data.readInt32();
+ String16 packageName = data.readString16();
+ std::optional<String16> attributionTag;
+ data.readString16(&attributionTag);
+ finishOperation(token, code, uid, packageName, attributionTag);
reply->writeNoException();
return NO_ERROR;
} break;
diff --git a/libs/permission/include/binder/IAppOpsService.h b/libs/permission/include/binder/IAppOpsService.h
index a5fdc54..918fcdb 100644
--- a/libs/permission/include/binder/IAppOpsService.h
+++ b/libs/permission/include/binder/IAppOpsService.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android/content/AttributionSourceState.h>
#include <binder/IAppOpsCallback.h>
#include <binder/IInterface.h>
@@ -28,24 +27,23 @@
namespace android {
-using android::content::AttributionSourceState;
-
// ----------------------------------------------------------------------
class IAppOpsService : public IInterface
{
public:
DECLARE_META_INTERFACE(AppOpsService)
- virtual int32_t checkOperationWithState(int32_t code,
- const AttributionSourceState& attributionSourceState) = 0;
- virtual int32_t noteOperationWithState(int32_t code,
- const AttributionSourceState& attributionSourceState, bool shouldCollectAsyncNotedOp,
+
+ 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<String16>& attributionTag, bool shouldCollectAsyncNotedOp,
const String16& message, bool shouldCollectMessage) = 0;
- virtual int32_t startOperationWithState(const sp<IBinder>& token, int32_t code,
- const AttributionSourceState& attributionSourceState, bool startIfModeDefault,
- bool shouldCollectAsyncNotedOp, const String16& message, bool shouldCollectMessage) = 0;
- virtual void finishOperationWithState(const sp<IBinder>& token, int32_t code,
- const AttributionSourceState& attributionSourceState) = 0;
+ 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,
+ bool shouldCollectMessage) = 0;
+ virtual void finishOperation(const sp<IBinder>& token, int32_t code, int32_t uid,
+ const String16& packageName, const std::optional<String16>& attributionTag) = 0;
virtual void startWatchingMode(int32_t op, const String16& packageName,
const sp<IAppOpsCallback>& callback) = 0;
virtual void stopWatchingMode(const sp<IAppOpsCallback>& callback) = 0;
@@ -58,10 +56,10 @@
int32_t flags, const sp<IAppOpsCallback>& callback) = 0;
enum {
- CHECK_OPERATION_WITH_STATE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+50,
- NOTE_OPERATION_WITH_STATE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+52,
- START_OPERATION_WITH_STATE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+53,
- FINISH_OPERATION_WITH_STATE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+54,
+ CHECK_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION,
+ NOTE_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+1,
+ START_OPERATION_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+2,
+ 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,
PERMISSION_TO_OP_CODE_TRANSACTION = IBinder::FIRST_CALL_TRANSACTION+6,