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

Commit 83a22c5c authored by Ronghua Wu's avatar Ronghua Wu Committed by Android (Google) Code Review
Browse files

Merge "Reduce lock time for dump to make sure not locked when calling back to...

Merge "Reduce lock time for dump to make sure not locked when calling back to IResourceManagerClient." into mnc-dr-dev
parents 1d29e126 76d4c7ff
Loading
Loading
Loading
Loading
+26 −11
Original line number Original line Diff line number Diff line
@@ -90,11 +90,7 @@ static ResourceInfo& getResourceInfoForEdit(
}
}


status_t ResourceManagerService::dump(int fd, const Vector<String16>& /* args */) {
status_t ResourceManagerService::dump(int fd, const Vector<String16>& /* args */) {
    Mutex::Autolock lock(mLock);

    String8 result;
    String8 result;
    const size_t SIZE = 256;
    char buffer[SIZE];


    if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
    if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
        result.format("Permission Denial: "
        result.format("Permission Denial: "
@@ -105,20 +101,35 @@ status_t ResourceManagerService::dump(int fd, const Vector<String16>& /* args */
        return PERMISSION_DENIED;
        return PERMISSION_DENIED;
    }
    }


    PidResourceInfosMap mapCopy;
    bool supportsMultipleSecureCodecs;
    bool supportsSecureWithNonSecureCodec;
    String8 serviceLog;
    {
        Mutex::Autolock lock(mLock);
        mapCopy = mMap;  // Shadow copy, real copy will happen on write.
        supportsMultipleSecureCodecs = mSupportsMultipleSecureCodecs;
        supportsSecureWithNonSecureCodec = mSupportsSecureWithNonSecureCodec;
        serviceLog = mServiceLog->toString("    " /* linePrefix */);
    }

    const size_t SIZE = 256;
    char buffer[SIZE];
    snprintf(buffer, SIZE, "ResourceManagerService: %p\n", this);
    snprintf(buffer, SIZE, "ResourceManagerService: %p\n", this);
    result.append(buffer);
    result.append(buffer);
    result.append("  Policies:\n");
    result.append("  Policies:\n");
    snprintf(buffer, SIZE, "    SupportsMultipleSecureCodecs: %d\n", mSupportsMultipleSecureCodecs);
    snprintf(buffer, SIZE, "    SupportsMultipleSecureCodecs: %d\n", supportsMultipleSecureCodecs);
    result.append(buffer);
    result.append(buffer);
    snprintf(buffer, SIZE, "    SupportsSecureWithNonSecureCodec: %d\n", mSupportsSecureWithNonSecureCodec);
    snprintf(buffer, SIZE, "    SupportsSecureWithNonSecureCodec: %d\n",
            supportsSecureWithNonSecureCodec);
    result.append(buffer);
    result.append(buffer);


    result.append("  Processes:\n");
    result.append("  Processes:\n");
    for (size_t i = 0; i < mMap.size(); ++i) {
    for (size_t i = 0; i < mapCopy.size(); ++i) {
        snprintf(buffer, SIZE, "    Pid: %d\n", mMap.keyAt(i));
        snprintf(buffer, SIZE, "    Pid: %d\n", mapCopy.keyAt(i));
        result.append(buffer);
        result.append(buffer);


        const ResourceInfos &infos = mMap.valueAt(i);
        const ResourceInfos &infos = mapCopy.valueAt(i);
        for (size_t j = 0; j < infos.size(); ++j) {
        for (size_t j = 0; j < infos.size(); ++j) {
            result.append("      Client:\n");
            result.append("      Client:\n");
            snprintf(buffer, SIZE, "        Id: %lld\n", (long long)infos[j].clientId);
            snprintf(buffer, SIZE, "        Id: %lld\n", (long long)infos[j].clientId);
@@ -136,7 +147,7 @@ status_t ResourceManagerService::dump(int fd, const Vector<String16>& /* args */
        }
        }
    }
    }
    result.append("  Events logs (most recent at top):\n");
    result.append("  Events logs (most recent at top):\n");
    result.append(mServiceLog->toString("    " /* linePrefix */));
    result.append(serviceLog);


    write(fd, result.string(), result.size());
    write(fd, result.string(), result.size());
    return OK;
    return OK;
@@ -307,6 +318,10 @@ bool ResourceManagerService::reclaimResource(
        }
        }
    }
    }


    if (failedClient == NULL) {
        return true;
    }

    {
    {
        Mutex::Autolock lock(mLock);
        Mutex::Autolock lock(mLock);
        bool found = false;
        bool found = false;
@@ -329,7 +344,7 @@ bool ResourceManagerService::reclaimResource(
        }
        }
    }
    }


    return (failedClient == NULL);
    return false;
}
}


bool ResourceManagerService::getAllClients_l(
bool ResourceManagerService::getAllClients_l(