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

Commit 4b555e86 authored by Atneya Nair's avatar Atneya Nair
Browse files

[audio] Avoid startOp when restrictions in place

When AppOp restrictions are in place, starting an op will return
SOFT_DENY, but leave the op in a paused state, which can restart
unexpectedly when the restriction is removed (despite no data delivery
occurring).

Work around this by first checking if recording is restricted, and
avoiding the start call in that case.

Test: manual: start and stop recording with toggle restriction
Test: atest CtsMediaAudioPermissionTestCases
Fixes: 399138369
Bug: 293603271
Flag: EXEMPT bugfix
Change-Id: I3439f6d5fd732ba24cb82c6b744d5665ab9b7827
parent cc7fd0ec
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -172,9 +172,20 @@ static int checkRecordingInternal(const AttributionSourceState &attributionSourc
        permission::PermissionChecker permissionChecker;
        int permitted;
        if (start) {
            // Do a double-check, where we first check without actually starting in order to handle
            // the behavior of AppOps where ops are sometimes started but paused for SOFT_DENIED.
            // Since there is no way to maintain reference consensus due to this behavior, avoid
            // starting an op when a restriction is in place by first checking. Technically racy,
            // but very unlikely.
            // TODO(b/294609684) To be removed when the pause state for an OP is removed.
            permitted = permissionChecker.checkPermissionForPreflightFromDatasource(
                    sAndroidPermissionRecordAudio, resolvedAttributionSource.value(), msg,
                    attributedOpCode);
            if (permitted == PERMISSION_GRANTED) {
                permitted = permissionChecker.checkPermissionForStartDataDeliveryFromDatasource(
                        sAndroidPermissionRecordAudio, resolvedAttributionSource.value(), msg,
                        attributedOpCode);
            }
        } else {
            permitted = permissionChecker.checkPermissionForPreflightFromDatasource(
                    sAndroidPermissionRecordAudio, resolvedAttributionSource.value(), msg,