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

Commit 7945a8d2 authored by Abdelrahman Daim's avatar Abdelrahman Daim Committed by Yurii Zubrytskyi
Browse files

Fix the listener in the incremental service.



Summary: The listener doesn't function as intended. The previous
listener triggers for changes matching the given code or changes
matching the package, always returning the listened code, not
the changing code.

The end result is that logging will be disabled if there are any
changes for a data loader. An example can be seen when the
device is activated and a number of changes occur, resulting in
the disable logging flow.

With this change, we listen to all changes for a given package
name. This results in the listener being called with accurate
codes, which we can then filter for.

Test: Successful Build on master branch
Flag: EXEMPT small bugfix

Signed-off-by: default avatarAbdelrahman Daim <adaim@meta.com>
(cherry picked from https://android-review.googlesource.com/q/commit:f6b8b2ab5396cebd47bffd94c03ce2d03e9725d6)
Change-Id: I44eca6cad70933eca9310a055e5839f8908a142b
parent 872d9783
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -2318,12 +2318,12 @@ void IncrementalService::registerAppOpsCallback(const std::string& packageName)
        if (cb) {
            return;
        }
        cb = new AppOpsListener(*this, packageName);
        cb = new AppOpsListener(*this, packageName, AppOpsManager::OP_GET_USAGE_STATS);
        listener = cb;
    }

    mAppOpsManager->startWatchingMode(AppOpsManager::OP_GET_USAGE_STATS,
                                      String16(packageName.c_str()), listener);
    mAppOpsManager->startWatchingMode(AppOpsManager::OP_NONE, String16(packageName.c_str()),
                                      listener);
}

bool IncrementalService::unregisterAppOpsCallback(const std::string& packageName) {
@@ -3198,9 +3198,13 @@ void IncrementalService::DataLoaderStub::onDump(int fd) {
    dprintf(fd, "    }\n");
}

binder::Status IncrementalService::AppOpsListener::opChanged(int32_t, int32_t,
binder::Status IncrementalService::AppOpsListener::opChanged(int32_t changedOp, int32_t,
                                                             const String16&, const String16&) {
    // The listener will notify for any AppOp change for the given package.
    // Confirm it's the one we're interested in.
    if (changedOp == op) {
        incrementalService.onAppOpChanged(packageName);
    }
    return binder::Status::ok();
}

+5 −2
Original line number Diff line number Diff line
@@ -202,14 +202,17 @@ public:

    class AppOpsListener : public com::android::internal::app::BnAppOpsCallback {
    public:
        AppOpsListener(IncrementalService& incrementalService, std::string packageName)
              : incrementalService(incrementalService), packageName(std::move(packageName)) {}
        AppOpsListener(IncrementalService& incrementalService, std::string packageName, int32_t op)
              : incrementalService(incrementalService),
                packageName(std::move(packageName)),
                op(op) {}
        binder::Status opChanged(int32_t op, int32_t uid, const String16& packageName,
                                 const String16& persistentDeviceId) final;

    private:
        IncrementalService& incrementalService;
        const std::string packageName;
        const int32_t op;
    };

    class IncrementalServiceConnector : public os::incremental::BnIncrementalServiceConnector {
+1 −1
Original line number Diff line number Diff line
@@ -1678,7 +1678,7 @@ TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsSuccessAndPermissionChang
                                                  {}, {}));
    ASSERT_GE(mDataLoader->setStorageParams(true), 0);
    ASSERT_NE(nullptr, mAppOpsManager->mStoredCallback.get());
    mAppOpsManager->mStoredCallback->opChanged(0, 0, {}, {});
    mAppOpsManager->mStoredCallback->opChanged(AppOpsManager::OP_GET_USAGE_STATS, 0, {}, {});
}

TEST_F(IncrementalServiceTest, testSetIncFsMountOptionsCheckPermissionFails) {