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

Commit b0d2de64 authored by Jeff Sharkey's avatar Jeff Sharkey
Browse files

AudioService: ignore restrictions on removed users.

During test suites we've observed that the USER_BACKGROUND broadcast
can be delivered after a user has been deleted, which can cause
operations like setUserRestriction() to fail.

Ignore these cases to avoid a runtime restart.

Bug: 255835206
Test: atest FrameworksMockingServicesTests:BroadcastRecordTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueTest
Test: atest FrameworksMockingServicesTests:BroadcastQueueModernImplTest
Change-Id: Ia31f276079583c447f34815d0e0067959ea77668
parent f08577b9
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -8767,13 +8767,21 @@ public class AudioService extends IAudioService.Stub
                    UserInfo userInfo = UserManagerService.getInstance().getUserInfo(userId);
                    killBackgroundUserProcessesWithRecordAudioPermission(userInfo);
                }
                try {
                    UserManagerService.getInstance().setUserRestriction(
                            UserManager.DISALLOW_RECORD_AUDIO, true, userId);
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Failed to apply DISALLOW_RECORD_AUDIO restriction: " + e);
                }
            } else if (action.equals(Intent.ACTION_USER_FOREGROUND)) {
                // Enable audio recording for foreground user/profile
                int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, -1);
                try {
                    UserManagerService.getInstance().setUserRestriction(
                            UserManager.DISALLOW_RECORD_AUDIO, false, userId);
                } catch (IllegalArgumentException e) {
                    Slog.w(TAG, "Failed to apply DISALLOW_RECORD_AUDIO restriction: " + e);
                }
            } else if (action.equals(BluetoothAdapter.ACTION_STATE_CHANGED)) {
                state = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1);
                if (state == BluetoothAdapter.STATE_OFF ||