Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ae73bff6 authored by Philip P. Moltmann's avatar Philip P. Moltmann Committed by Android (Google) Code Review
Browse files

Merge "Collect AsyncNotedAppOp in same call as native noteOp"

parents 1ca25ba9 3879cf69
Loading
Loading
Loading
Loading
+10 −39
Original line number Diff line number Diff line
@@ -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) {
    }
}

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;
bool AppOpsManager::shouldCollectNotes(int32_t opcode) {
    if (appOpsToNote[opcode] == 0) {
        if (getService()->shouldCollectNotes(opcode)) {
            appOpsToNote[opcode] = 2;
        } else {
            appOpsToNote[opCode] = 1;
        }
    }

    if (appOpsToNote[opCode] != 2) {
        return;
            appOpsToNote[opcode] = 1;
        }

    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
+14 −32
Original line number Diff line number Diff line
@@ -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();
+0 −5
Original line number Diff line number Diff line
@@ -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);
};

+5 −8
Original line number Diff line number Diff line
@@ -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 {