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

Commit 402baf82 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Merge cherrypicks of ['googleplex-android-review.googlesource.com/32599955'] into 25Q2-release.

Change-Id: I9229418c7ea1cb57f7ea6317c058cadebb3095e4
parents da0d30e8 54114f56
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -64,4 +64,9 @@ interface ICameraServiceProxy
     * Checks if the camera has been disabled via device policy.
     */
    boolean isCameraDisabled(int userId);

    /**
     * Notify a cameraserver watchdog.
     */
    oneway void notifyWatchdog(int /* pid_t */ pid, boolean isNative);
}
+7 −1
Original line number Diff line number Diff line
@@ -45,7 +45,13 @@ bool CameraServiceWatchdog::threadLoop()

            mTidMap[currentThreadId].cycles++;

            if (mTidMap[currentThreadId].cycles >= mMaxCycles) {
            // If we are at 3/4 of reaching timeout, trigger a stack trace dump
            // for all relevant processes by CameraServiceProxy.
            if (mTidMap[currentThreadId].cycles == mMaxCycles * 3 / 4) {
                ALOGW("CameraServiceWatchdog pre-watchdog for pid: %d tid: %d, clientPid %d",
                        getpid(), currentThreadId, mClientPid);
                mCameraServiceProxyWrapper->notifyWatchdog(mClientPid, mIsNativePid);
            } else if (mTidMap[currentThreadId].cycles >= mMaxCycles) {
                std::string abortMessage = getAbortMessage(mTidMap[currentThreadId].functionName);
                android_set_abort_message(abortMessage.c_str());
                ALOGW("CameraServiceWatchdog triggering abort for pid: %d tid: %d", getpid(),
+7 −47
Original line number Diff line number Diff line
@@ -41,8 +41,6 @@

// Used to wrap the call of interest in start and stop calls
#define WATCH(toMonitor) watchThread([&]() { return toMonitor;}, gettid(), __FUNCTION__)
#define WATCH_CUSTOM_TIMER(toMonitor, cycles, cycleLength) \
        watchThread([&]() { return toMonitor;}, gettid(), __FUNCTION__, cycles, cycleLength);

// Default cycles and cycle length values used to calculate permitted elapsed time
const static size_t   kMaxCycles     = 650;
@@ -59,19 +57,15 @@ struct MonitoredFunction {

public:

    explicit CameraServiceWatchdog(const std::set<pid_t> &pids, const std::string &cameraId,
    explicit CameraServiceWatchdog(
            const std::set<pid_t> &pids, pid_t clientPid,
            bool isNativePid, const std::string &cameraId,
            std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper) :
                    mProviderPids(pids), mCameraId(cameraId), mPause(true), mMaxCycles(kMaxCycles),
                    mProviderPids(pids), mClientPid(clientPid), mIsNativePid(isNativePid),
                    mCameraId(cameraId), mPause(true), mMaxCycles(kMaxCycles),
                    mCycleLengthMs(kCycleLengthMs), mEnabled(true),
                    mCameraServiceProxyWrapper(cameraServiceProxyWrapper) {};

    explicit CameraServiceWatchdog (const std::set<pid_t> &pids, const std::string &cameraId,
            size_t maxCycles, uint32_t cycleLengthMs, bool enabled,
            std::shared_ptr<CameraServiceProxyWrapper> cameraServiceProxyWrapper) :
                    mProviderPids(pids), mCameraId(cameraId), mPause(true), mMaxCycles(maxCycles),
                    mCycleLengthMs(cycleLengthMs), mEnabled(enabled),
                    mCameraServiceProxyWrapper(cameraServiceProxyWrapper) {};

    virtual ~CameraServiceWatchdog() {};

    virtual void requestExit();
@@ -79,42 +73,6 @@ public:
    /** Enables/disables the watchdog */
    void setEnabled(bool enable);

    /** Used to wrap monitored calls in start and stop functions using custom timer values */
    template<typename T>
    auto watchThread(T func, uint32_t tid, const char* functionName, uint32_t cycles,
            uint32_t cycleLength) {
        decltype(func()) res;

        if (cycles != mMaxCycles || cycleLength != mCycleLengthMs) {
            // Create another instance of the watchdog to prevent disruption
            // of timer for current monitored calls

            // Lock for mEnabled
            mEnabledLock.lock();
            sp<CameraServiceWatchdog> tempWatchdog = new CameraServiceWatchdog(
                    mProviderPids, mCameraId, cycles, cycleLength, mEnabled,
                    mCameraServiceProxyWrapper);
            mEnabledLock.unlock();

            status_t status = tempWatchdog->run("CameraServiceWatchdog");
            if (status != OK) {
                ALOGE("Unable to watch thread: %s (%d)", strerror(-status), status);
                res = watchThread(func, tid, functionName);
                return res;
            }

            res = tempWatchdog->watchThread(func, tid, functionName);
            tempWatchdog->requestExit();
            tempWatchdog.clear();
        } else {
            // If custom timer values are equivalent to set class timer values, use
            // current thread
            res = watchThread(func, tid, functionName);
        }

        return res;
    }

    /** Used to wrap monitored calls in start and stop functions using class timer values */
    template<typename T>
    auto watchThread(T func, uint32_t tid, const char* functionName) {
@@ -154,6 +112,8 @@ private:
    Mutex           mEnabledLock;       // Lock for enabled status
    Condition       mWatchdogCondition; // Condition variable for stop/start
    std::set<pid_t> mProviderPids;      // Process ID set of camera providers
    pid_t           mClientPid;         // Process ID of the client
    bool            mIsNativePid;       // Whether the client is a native process
    std::string     mCameraId;          // Camera Id the watchdog belongs to
    bool            mPause;             // True if tid map is empty
    uint32_t        mMaxCycles;         // Max cycles
+1 −1
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ Camera2Client::Camera2Client(
                        false /*systemNativeClient - since no ndk for api1*/, cameraDeviceId,
                        api1CameraId, cameraFacing, sensorOrientation, servicePid,
                        overrideForPerfClass, rotationOverride, sharedMode,
                        /*legacyClient*/ true),
                        /*isVendorClient*/ false, /*legacyClient*/ true),
      mParameters(api1CameraId, cameraFacing),
      mInitialized(false),
      mLatestRequestIds(kMaxRequestIds),
+1 −1
Original line number Diff line number Diff line
@@ -92,7 +92,7 @@ CameraDeviceClient::CameraDeviceClient(
                        attributionAndPermissionUtils, clientAttribution, callingPid,
                        systemNativeClient, cameraId, /*API1 camera ID*/ -1, cameraFacing,
                        sensorOrientation, servicePid, overrideForPerfClass, rotationOverride,
                        sharedMode),
                        sharedMode, isVendorClient),
      mInputStream(),
      mStreamingRequestId(REQUEST_ID_NONE),
      mStreamingRequestLastFrameNumber(NO_IN_FLIGHT_REPEATING_FRAMES),
Loading