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

Commit 210af508 authored by Andy Hung's avatar Andy Hung Committed by Gerrit Code Review
Browse files

Merge "Fix allowing playback capture for packages with shared UID"

parents 1e2b6013 703ec268
Loading
Loading
Loading
Loading
+9 −9
Original line number Original line Diff line number Diff line
@@ -266,7 +266,7 @@ status_t checkIMemory(const sp<IMemory>& iMemory)
    return NO_ERROR;
    return NO_ERROR;
}
}


sp<content::pm::IPackageManagerNative> MediaPackageManager::retreivePackageManager() {
sp<content::pm::IPackageManagerNative> MediaPackageManager::retrievePackageManager() {
    const sp<IServiceManager> sm = defaultServiceManager();
    const sp<IServiceManager> sm = defaultServiceManager();
    if (sm == nullptr) {
    if (sm == nullptr) {
        ALOGW("%s: failed to retrieve defaultServiceManager", __func__);
        ALOGW("%s: failed to retrieve defaultServiceManager", __func__);
@@ -283,27 +283,27 @@ sp<content::pm::IPackageManagerNative> MediaPackageManager::retreivePackageManag
std::optional<bool> MediaPackageManager::doIsAllowed(uid_t uid) {
std::optional<bool> MediaPackageManager::doIsAllowed(uid_t uid) {
    if (mPackageManager == nullptr) {
    if (mPackageManager == nullptr) {
        /** Can not fetch package manager at construction it may not yet be registered. */
        /** Can not fetch package manager at construction it may not yet be registered. */
        mPackageManager = retreivePackageManager();
        mPackageManager = retrievePackageManager();
        if (mPackageManager == nullptr) {
        if (mPackageManager == nullptr) {
            ALOGW("%s: Playback capture is denied as package manager is not reachable", __func__);
            ALOGW("%s: Playback capture is denied as package manager is not reachable", __func__);
            return std::nullopt;
            return std::nullopt;
        }
        }
    }
    }


    // Retrieve package names for the UID and transform to a std::vector<std::string>.
    Vector<String16> str16PackageNames;
    PermissionController{}.getPackagesForUid(uid, str16PackageNames);
    std::vector<std::string> packageNames;
    std::vector<std::string> packageNames;
    auto status = mPackageManager->getNamesForUids({(int32_t)uid}, &packageNames);
    for (const auto& str16PackageName : str16PackageNames) {
    if (!status.isOk()) {
        packageNames.emplace_back(String8(str16PackageName).string());
        ALOGW("%s: Playback capture is denied for uid %u as the package names could not be "
              "retrieved from the package manager: %s", __func__, uid, status.toString8().c_str());
        return std::nullopt;
    }
    }
    if (packageNames.empty()) {
    if (packageNames.empty()) {
        ALOGW("%s: Playback capture for uid %u is denied as no package name could be retrieved "
        ALOGW("%s: Playback capture for uid %u is denied as no package name could be retrieved "
              "from the package manager: %s", __func__, uid, status.toString8().c_str());
              "from the package manager.", __func__, uid);
        return std::nullopt;
        return std::nullopt;
    }
    }
    std::vector<bool> isAllowed;
    std::vector<bool> isAllowed;
    status = mPackageManager->isAudioPlaybackCaptureAllowed(packageNames, &isAllowed);
    auto status = mPackageManager->isAudioPlaybackCaptureAllowed(packageNames, &isAllowed);
    if (!status.isOk()) {
    if (!status.isOk()) {
        ALOGW("%s: Playback capture is denied for uid %u as the manifest property could not be "
        ALOGW("%s: Playback capture is denied for uid %u as the manifest property could not be "
              "retrieved from the package manager: %s", __func__, uid, status.toString8().c_str());
              "retrieved from the package manager: %s", __func__, uid, status.toString8().c_str());
+1 −1
Original line number Original line Diff line number Diff line
@@ -110,7 +110,7 @@ public:
private:
private:
    static constexpr const char* nativePackageManagerName = "package_native";
    static constexpr const char* nativePackageManagerName = "package_native";
    std::optional<bool> doIsAllowed(uid_t uid);
    std::optional<bool> doIsAllowed(uid_t uid);
    sp<content::pm::IPackageManagerNative> retreivePackageManager();
    sp<content::pm::IPackageManagerNative> retrievePackageManager();
    sp<content::pm::IPackageManagerNative> mPackageManager; // To check apps manifest
    sp<content::pm::IPackageManagerNative> mPackageManager; // To check apps manifest
    uint_t mPackageManagerErrors = 0;
    uint_t mPackageManagerErrors = 0;
    struct Package {
    struct Package {