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

Commit b34bd486 authored by Jayant Chowdhary's avatar Jayant Chowdhary Committed by Android (Google) Code Review
Browse files

Merge "cameraservice: re-map oom_adj scores and states of native vendor clients." into qt-dev

parents 48aa740f c578a50c
Loading
Loading
Loading
Loading
+12 −2
Original line number Diff line number Diff line
@@ -117,6 +117,11 @@ static void setLogLevel(int level) {

static const String16 sManageCameraPermission("android.permission.MANAGE_CAMERA");

// Matches with PERCEPTIBLE_APP_ADJ in ProcessList.java
static constexpr int32_t kVendorClientScore = 200;
// Matches with PROCESS_STATE_PERSISTENT_UI in ActivityManager.java
static constexpr int32_t kVendorClientState = 1;

Mutex CameraService::sProxyMutex;
sp<hardware::ICameraServiceProxy> CameraService::sCameraServiceProxy;

@@ -1120,7 +1125,8 @@ status_t CameraService::handleEvictionsLocked(const String8& cameraId, int clien
        std::map<int,resource_policy::ClientPriority> pidToPriorityMap;
        for (size_t i = 0; i < ownerPids.size() - 1; i++) {
            pidToPriorityMap.emplace(ownerPids[i],
                    resource_policy::ClientPriority(priorityScores[i], states[i]));
                    resource_policy::ClientPriority(priorityScores[i], states[i],
                            /* isVendorClient won't get copied over*/ false));
        }
        mActiveClientManager.updatePriorities(pidToPriorityMap);

@@ -2980,8 +2986,12 @@ CameraService::DescriptorPtr CameraService::CameraClientManager::makeClientDescr
        const std::set<String8>& conflictingKeys, int32_t score, int32_t ownerId,
        int32_t state) {

    bool isVendorClient = hardware::IPCThreadState::self()->isServingCall();
    int32_t score_adj = isVendorClient ? kVendorClientScore : score;
    int32_t state_adj = isVendorClient ? kVendorClientState: state;

    return std::make_shared<resource_policy::ClientDescriptor<String8, sp<BasicClient>>>(
            key, value, cost, conflictingKeys, score, ownerId, state);
            key, value, cost, conflictingKeys, score_adj, ownerId, state_adj, isVendorClient);
}

CameraService::DescriptorPtr CameraService::CameraClientManager::makeClientDescriptor(
+45 −9
Original line number Diff line number Diff line
@@ -33,12 +33,38 @@ namespace resource_policy {

class ClientPriority {
public:
    ClientPriority(int32_t score, int32_t state) :
        mScore(score), mState(state) {}
    /**
     * Choosing to set mIsVendorClient through a parameter instead of calling
     * hardware::IPCThreadState::self()->isServingCall() to protect against the
     * case where the construction is offloaded to another thread which isn't a
     * hwbinder thread.
     */
    ClientPriority(int32_t score, int32_t state, bool isVendorClient) :
            mScore(score), mState(state), mIsVendorClient(isVendorClient) { }

    int32_t getScore() const { return mScore; }
    int32_t getState() const { return mState; }

    void setScore(int32_t score) {
        // For vendor clients, the score is set once and for all during
        // construction. Otherwise, it can get reset each time cameraserver
        // queries ActivityManagerService for oom_adj scores / states .
        if (!mIsVendorClient) {
            mScore = score;
        }
    }

    void setState(int32_t state) {
      // For vendor clients, the score is set once and for all during
      // construction. Otherwise, it can get reset each time cameraserver
      // queries ActivityManagerService for oom_adj scores / states
      // (ActivityManagerService returns a vendor process' state as
      // PROCESS_STATE_NONEXISTENT.
      if (!mIsVendorClient) {
          mState = state;
      }
    }

    bool operator==(const ClientPriority& rhs) const {
        return (this->mScore == rhs.mScore) && (this->mState == rhs.mState);
    }
@@ -66,6 +92,7 @@ public:
private:
        int32_t mScore;
        int32_t mState;
        bool mIsVendorClient = false;
};

// --------------------------------------------------------------------------------
@@ -82,9 +109,10 @@ template<class KEY, class VALUE>
class ClientDescriptor final {
public:
    ClientDescriptor(const KEY& key, const VALUE& value, int32_t cost,
            const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state);
            const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
            bool isVendorClient);
    ClientDescriptor(KEY&& key, VALUE&& value, int32_t cost, std::set<KEY>&& conflictingKeys,
            int32_t score, int32_t ownerId, int32_t state);
            int32_t score, int32_t ownerId, int32_t state, bool isVendorClient);

    ~ClientDescriptor();

@@ -148,17 +176,19 @@ bool operator < (const ClientDescriptor<K, V>& a, const ClientDescriptor<K, V>&

template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::ClientDescriptor(const KEY& key, const VALUE& value, int32_t cost,
        const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state) :
        const std::set<KEY>& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
        bool isVendorClient) :
        mKey{key}, mValue{value}, mCost{cost}, mConflicting{conflictingKeys},
        mPriority(score, state),
        mPriority(score, state, isVendorClient),
        mOwnerId{ownerId} {}

template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::ClientDescriptor(KEY&& key, VALUE&& value, int32_t cost,
        std::set<KEY>&& conflictingKeys, int32_t score, int32_t ownerId, int32_t state) :
        std::set<KEY>&& conflictingKeys, int32_t score, int32_t ownerId, int32_t state,
        bool isVendorClient) :
        mKey{std::forward<KEY>(key)}, mValue{std::forward<VALUE>(value)}, mCost{cost},
        mConflicting{std::forward<std::set<KEY>>(conflictingKeys)},
        mPriority(score, state), mOwnerId{ownerId} {}
        mPriority(score, state, isVendorClient), mOwnerId{ownerId} {}

template<class KEY, class VALUE>
ClientDescriptor<KEY, VALUE>::~ClientDescriptor() {}
@@ -204,7 +234,13 @@ std::set<KEY> ClientDescriptor<KEY, VALUE>::getConflicting() const {

template<class KEY, class VALUE>
void ClientDescriptor<KEY, VALUE>::setPriority(const ClientPriority& priority) {
    mPriority = priority;
    // We don't use the usual copy constructor here since we want to remember
    // whether a client is a vendor client or not. This could have been wiped
    // off in the incoming priority argument since an AIDL thread might have
    // called hardware::IPCThreadState::self()->isServingCall() after refreshing
    // priorities for old clients through ProcessInfoService::getProcessStatesScoresFromPids().
    mPriority.setScore(priority.getScore());
    mPriority.setState(priority.getState());
}

// --------------------------------------------------------------------------------