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

Commit 934ac011 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

Snap for 7450397 from fa72c380 to sc-d1-release

Change-Id: I141e63728c5196457f03e9ca5feb3821af01d433
parents 1f4c7118 fa72c380
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
@@ -786,7 +786,7 @@ void AudioPolicyService::updateUidStates_l()
                allowCapture = true;
            }
        }
        setAppState_l(current->portId,
        setAppState_l(current,
                      allowCapture ? apmStatFromAmState(mUidPolicy->getUidState(currentUid)) :
                                APP_STATE_IDLE);
    }
@@ -796,7 +796,7 @@ void AudioPolicyService::silenceAllRecordings_l() {
    for (size_t i = 0; i < mAudioRecordClients.size(); i++) {
        sp<AudioRecordClient> current = mAudioRecordClients[i];
        if (!isVirtualSource(current->attributes.source)) {
            setAppState_l(current->portId, APP_STATE_IDLE);
            setAppState_l(current, APP_STATE_IDLE);
        }
    }
}
@@ -830,17 +830,32 @@ bool AudioPolicyService::isVirtualSource(audio_source_t source)
    return false;
}

void AudioPolicyService::setAppState_l(audio_port_handle_t portId, app_state_t state)
void AudioPolicyService::setAppState_l(sp<AudioRecordClient> client, app_state_t state)
{
    AutoCallerClear acc;

    if (mAudioPolicyManager) {
        mAudioPolicyManager->setAppState(portId, state);
        mAudioPolicyManager->setAppState(client->portId, state);
    }
    sp<IAudioFlinger> af = AudioSystem::get_audio_flinger();
    if (af) {
        bool silenced = state == APP_STATE_IDLE;
        af->setRecordSilenced(portId, silenced);
        if (client->silenced != silenced) {
            if (client->active) {
                if (silenced) {
                    finishRecording(client->attributionSource, client->attributes.source);
                } else {
                    std::stringstream msg;
                    msg << "Audio recording un-silenced on session " << client->session;
                    if (!startRecording(client->attributionSource, String16(msg.str().c_str()),
                            client->attributes.source)) {
                        silenced = true;
                    }
                }
            }
            af->setRecordSilenced(client->portId, silenced);
            client->silenced = silenced;
        }
    }
}

+5 −2
Original line number Diff line number Diff line
@@ -324,8 +324,10 @@ private:
    // Handles binder shell commands
    virtual status_t shellCommand(int in, int out, int err, Vector<String16>& args);

    class AudioRecordClient;

    // Sets whether the given UID records only silence
    virtual void setAppState_l(audio_port_handle_t portId, app_state_t state) REQUIRES(mLock);
    virtual void setAppState_l(sp<AudioRecordClient> client, app_state_t state) REQUIRES(mLock);

    // Overrides the UID state as if it is idle
    status_t handleSetUidState(Vector<String16>& args, int err);
@@ -826,13 +828,14 @@ private:
                    AudioClient(attributes, io, attributionSource,
                        session, portId, deviceId), attributionSource(attributionSource),
                        startTimeNs(0), canCaptureOutput(canCaptureOutput),
                        canCaptureHotword(canCaptureHotword) {}
                        canCaptureHotword(canCaptureHotword), silenced(false) {}
                ~AudioRecordClient() override = default;

        const AttributionSourceState attributionSource; // attribution source of client
        nsecs_t startTimeNs;
        const bool canCaptureOutput;
        const bool canCaptureHotword;
        bool silenced;
    };

    // --- AudioPlaybackClient ---
+14 −90
Original line number Diff line number Diff line
@@ -131,8 +131,6 @@ static const String16 sCameraOpenCloseListenerPermission(
        "android.permission.CAMERA_OPEN_CLOSE_LISTENER");
static const String16
        sCameraInjectExternalCameraPermission("android.permission.CAMERA_INJECT_EXTERNAL_CAMERA");
static int sMemFd = -1;
const char *sFileName = "lastOpenSessionDumpFile";

static constexpr int32_t kVendorClientScore = resource_policy::PERCEPTIBLE_APP_ADJ;
static constexpr int32_t kVendorClientState = ActivityManager::PROCESS_STATE_PERSISTENT_UI;
@@ -150,11 +148,6 @@ CameraService::CameraService() :
        mAudioRestriction(hardware::camera2::ICameraDeviceUser::AUDIO_RESTRICTION_NONE) {
    ALOGI("CameraService started (pid=%d)", getpid());
    mServiceLockWrapper = std::make_shared<WaitableMutexWrapper>(&mServiceLock);

    sMemFd = memfd_create(sFileName, MFD_ALLOW_SEALING);
    if (sMemFd == -1) {
        ALOGE("%s:Error while creating the file:%s", __FUNCTION__, sFileName);
    }
}

void CameraService::onFirstRef()
@@ -1644,21 +1637,6 @@ Status CameraService::connectDevice(
    }

    *device = client;

    Mutex::Autolock lock(mServiceLock);

    // Clear the previous cached logs and reposition the
    // file offset to beginning of the file to log new data.
    // If either truncate or lseek fails, close the previous file and create a new one.
    if ((ftruncate(sMemFd, 0) == -1) || (lseek(sMemFd, 0, SEEK_SET) == -1)) {
        ALOGE("%s: Error while truncating the file:%s", __FUNCTION__, sFileName);
        // Close the previous memfd.
        close(sMemFd);
        // If failure to wipe the data, then create a new file and
        // assign the new value to sMemFd.
        sMemFd = memfd_create(sFileName, MFD_ALLOW_SEALING);
    }

    return ret;
}

@@ -3854,27 +3832,6 @@ static bool tryLock(Mutex& mutex)
    return locked;
}

void CameraService::cacheDump() {
    const Vector<String16>& args = Vector<String16>();
    ATRACE_CALL();

    Mutex::Autolock lock(mServiceLock);

    Mutex::Autolock l(mCameraStatesLock);

    // Start collecting the info for open sessions and store it in temp file.
    for (const auto& state : mCameraStates) {
        String8 cameraId = state.first;

        auto clientDescriptor = mActiveClientManager.get(cameraId);
        if (clientDescriptor != nullptr) {
           dprintf(sMemFd, "== Camera device %s dynamic info: ==\n", cameraId.string());
           // Log the current open session info before device is disconnected.
           dumpOpenSessionClientLogs(sMemFd, args, cameraId);
        }
    }
}

status_t CameraService::dump(int fd, const Vector<String16>& args) {
    ATRACE_CALL();

@@ -3941,10 +3898,21 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {

        auto clientDescriptor = mActiveClientManager.get(cameraId);
        if (clientDescriptor != nullptr) {
            // log the current open session info
            dumpOpenSessionClientLogs(fd, args, cameraId);
            dprintf(fd, "  Device %s is open. Client instance dump:\n",
                    cameraId.string());
            dprintf(fd, "    Client priority score: %d state: %d\n",
                    clientDescriptor->getPriority().getScore(),
                    clientDescriptor->getPriority().getState());
            dprintf(fd, "    Client PID: %d\n", clientDescriptor->getOwnerId());

            auto client = clientDescriptor->getValue();
            dprintf(fd, "    Client package: %s\n",
                    String8(client->getPackageName()).string());

            client->dumpClient(fd, args);
        } else {
            dumpClosedSessionClientLogs(fd, cameraId);
            dprintf(fd, "  Device %s is closed, no client instance\n",
                    cameraId.string());
        }

    }
@@ -4001,53 +3969,9 @@ status_t CameraService::dump(int fd, const Vector<String16>& args) {
            }
        }
    }

    Mutex::Autolock lock(mServiceLock);

    // Dump info from previous open sessions.
    // Reposition the offset to beginning of the file before reading

    if ((sMemFd >= 0) && (lseek(sMemFd, 0, SEEK_SET) != -1)) {
        dprintf(fd, "\n**********Dumpsys from previous open session**********\n");
        ssize_t size_read;
        char buf[4096];
        while ((size_read = read(sMemFd, buf, (sizeof(buf) - 1))) > 0) {
            // Read data from file to a small buffer and write it to fd.
            write(fd, buf, size_read);
            if (size_read == -1){
                ALOGE("%s: Error during reading the file:%s", __FUNCTION__, sFileName);
                break;
            }
        }
        dprintf(fd, "\n**********End of Dumpsys from previous open session**********\n");
    } else {
        ALOGE("%s: Error during reading the file:%s", __FUNCTION__, sFileName);
    }
    return NO_ERROR;
}

void CameraService::dumpOpenSessionClientLogs(int fd,
        const Vector<String16>& args, const String8& cameraId) {
    auto clientDescriptor = mActiveClientManager.get(cameraId);
    dprintf(fd, "  Device %s is open. Client instance dump:\n",
        cameraId.string());
    dprintf(fd, "    Client priority score: %d state: %d\n",
        clientDescriptor->getPriority().getScore(),
        clientDescriptor->getPriority().getState());
    dprintf(fd, "    Client PID: %d\n", clientDescriptor->getOwnerId());

    auto client = clientDescriptor->getValue();
    dprintf(fd, "    Client package: %s\n",
        String8(client->getPackageName()).string());

    client->dumpClient(fd, args);
}

void CameraService::dumpClosedSessionClientLogs(int fd, const String8& cameraId) {
    dprintf(fd, "  Device %s is closed, no client instance\n",
                    cameraId.string());
}

void CameraService::dumpEventLog(int fd) {
    dprintf(fd, "\n== Camera service events log (most recent at top): ==\n");

+0 −8
Original line number Diff line number Diff line
@@ -202,8 +202,6 @@ public:
            std::vector<hardware::CameraStatus>* cameraStatuses, bool isVendor = false,
            bool isProcessLocalTest = false);

    void cacheDump();

    // Monitored UIDs availability notification
    void                notifyMonitoredUids();

@@ -787,12 +785,6 @@ private:
    // Return NO_ERROR if the device with a give ID can be connected to
    status_t checkIfDeviceIsUsable(const String8& cameraId) const;

    // Adds client logs during open session to the file pointed by fd.
    void dumpOpenSessionClientLogs(int fd, const Vector<String16>& args, const String8& cameraId);

    // Adds client logs during closed session to the file pointed by fd.
    void dumpClosedSessionClientLogs(int fd, const String8& cameraId);

    // Container for managing currently active application-layer clients
    CameraClientManager mActiveClientManager;

+0 −2
Original line number Diff line number Diff line
@@ -195,8 +195,6 @@ binder::Status Camera2ClientBase<TClientBase>::disconnect() {

    ALOGV("Camera %s: Shutting down", TClientBase::mCameraIdStr.string());

    // Before detaching the device, cache the info from current open session
    Camera2ClientBase::getCameraService()->cacheDump();
    detachDevice();

    CameraService::BasicClient::disconnect();