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

Commit 241d9592 authored by Evan Severson's avatar Evan Severson
Browse files

Wire up the microphone toggle to the audio service

Bug: 162549680
Test: When mic is disabled, test that audio gets muted. Also test that
          virtual record works so services like captioning still work.
Change-Id: I6f9c762086cfa3900ec9585aaf68e458c9dadff5
parent 78b1947e
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -529,6 +529,11 @@ void AudioPolicyService::updateUidStates_l()

    for (size_t i =0; i < mAudioRecordClients.size(); i++) {
        sp<AudioRecordClient> current = mAudioRecordClients[i];
        if (!isVirtualSource(current->attributes.source)
                && isUserSensorPrivacyEnabledForUid(current->uid)) {
            setAppState_l(current->portId, APP_STATE_IDLE);
            continue;
        }
        if (!current->active) {
            continue;
        }
@@ -978,6 +983,16 @@ status_t AudioPolicyService::handleGetUidState(Vector<String16>& args, int out,
    return NO_INIT;
}

bool AudioPolicyService::isUserSensorPrivacyEnabledForUid(uid_t uid) {
    userid_t userId = multiuser_get_user_id(uid);
    if (mMicrophoneSensorPrivacyPolicies.find(userId) == mMicrophoneSensorPrivacyPolicies.end()) {
        sp<SensorPrivacyPolicy> userPolicy = new SensorPrivacyPolicy(this);
        userPolicy->registerSelfForMicrophoneOnly(userId);
        mMicrophoneSensorPrivacyPolicies[userId] = userPolicy;
    }
    return mMicrophoneSensorPrivacyPolicies[userId]->isSensorPrivacyEnabled();
}

status_t AudioPolicyService::printHelp(int out) {
    return dprintf(out, "Audio policy service commands:\n"
        "  get-uid-state <PACKAGE> [--user USER_ID] gets the uid state\n"
@@ -1211,6 +1226,14 @@ void AudioPolicyService::SensorPrivacyPolicy::registerSelf() {
    spm.addSensorPrivacyListener(this);
}

void AudioPolicyService::SensorPrivacyPolicy::registerSelfForMicrophoneOnly(int userId) {
    SensorPrivacyManager spm;
    mSensorPrivacyEnabled = spm.isIndividualSensorPrivacyEnabled(userId,
            SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE);
    spm.addIndividualSensorPrivacyListener(userId,
            SensorPrivacyManager::INDIVIDUAL_SENSOR_MICROPHONE, this);
}

void AudioPolicyService::SensorPrivacyPolicy::unregisterSelf() {
    SensorPrivacyManager spm;
    spm.removeSensorPrivacyListener(this);
+5 −0
Original line number Diff line number Diff line
@@ -304,6 +304,8 @@ public:

    virtual status_t setRttEnabled(bool enabled);

    virtual bool isUserSensorPrivacyEnabledForUid(uid_t uid);

            bool isCallScreenModeSupported() override;

            void doOnNewAudioModulesAvailable();
@@ -466,6 +468,7 @@ private:
                    : mService(service) {}

            void registerSelf();
            void registerSelfForMicrophoneOnly(int userId);
            void unregisterSelf();

            bool isSensorPrivacyEnabled();
@@ -939,6 +942,8 @@ private:
    MediaPackageManager mPackageManager; // To check allowPlaybackCapture

    CaptureStateNotifier mCaptureStateNotifier;

    std::map<userid_t, sp<SensorPrivacyPolicy>> mMicrophoneSensorPrivacyPolicies;
};

} // namespace android