Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +0 −71 Original line number Diff line number Diff line Loading @@ -1483,38 +1483,6 @@ public class AudioDeviceBroker { sendLMsgNoDelay(MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED, SENDMSG_QUEUE, client); } /*package*/ void postSaveSetPreferredDevicesForStrategy(int strategy, List<AudioDeviceAttributes> devices) { sendILMsgNoDelay(MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY, SENDMSG_QUEUE, strategy, devices); } /*package*/ void postSaveRemovePreferredDevicesForStrategy(int strategy) { sendIMsgNoDelay(MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY, SENDMSG_QUEUE, strategy); } /*package*/ void postSaveSetDeviceAsNonDefaultForStrategy( int strategy, AudioDeviceAttributes device) { sendILMsgNoDelay(MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY, SENDMSG_QUEUE, strategy, device); } /*package*/ void postSaveRemoveDeviceAsNonDefaultForStrategy( int strategy, AudioDeviceAttributes device) { sendILMsgNoDelay( MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY, SENDMSG_QUEUE, strategy, device); } /*package*/ void postSaveSetPreferredDevicesForCapturePreset( int capturePreset, List<AudioDeviceAttributes> devices) { sendILMsgNoDelay( MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET, SENDMSG_QUEUE, capturePreset, devices); } /*package*/ void postSaveClearPreferredDevicesForCapturePreset(int capturePreset) { sendIMsgNoDelay( MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET, SENDMSG_QUEUE, capturePreset); } /*package*/ void postUpdateCommunicationRouteClient( boolean wasBtScoRequested, String eventSource) { sendILMsgNoDelay(MSG_IL_UPDATE_COMMUNICATION_ROUTE_CLIENT, SENDMSG_QUEUE, Loading Loading @@ -2025,40 +1993,9 @@ public class AudioDeviceBroker { mDeviceInventory.setBluetoothActiveDevice(btInfo); } } break; case MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY: { final int strategy = msg.arg1; final List<AudioDeviceAttributes> devices = (List<AudioDeviceAttributes>) msg.obj; mDeviceInventory.onSaveSetPreferredDevices(strategy, devices); } break; case MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY: { final int strategy = msg.arg1; mDeviceInventory.onSaveRemovePreferredDevices(strategy); } break; case MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY: { final int strategy = msg.arg1; final AudioDeviceAttributes device = (AudioDeviceAttributes) msg.obj; mDeviceInventory.onSaveSetDeviceAsNonDefault(strategy, device); } break; case MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY: { final int strategy = msg.arg1; final AudioDeviceAttributes device = (AudioDeviceAttributes) msg.obj; mDeviceInventory.onSaveRemoveDeviceAsNonDefault(strategy, device); } break; case MSG_CHECK_MUTE_MUSIC: checkMessagesMuteMusic(0); break; case MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET: { final int capturePreset = msg.arg1; final List<AudioDeviceAttributes> devices = (List<AudioDeviceAttributes>) msg.obj; mDeviceInventory.onSaveSetPreferredDevicesForCapturePreset( capturePreset, devices); } break; case MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET: { final int capturePreset = msg.arg1; mDeviceInventory.onSaveClearPreferredDevicesForCapturePreset(capturePreset); } break; case MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED: { final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; BtHelper.onNotifyPreferredAudioProfileApplied(btDevice); Loading Loading @@ -2151,16 +2088,10 @@ public class AudioDeviceBroker { // process external command to (dis)connect a hearing aid device private static final int MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT = 31; private static final int MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY = 32; private static final int MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY = 33; private static final int MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED = 34; private static final int MSG_CHECK_MUTE_MUSIC = 35; private static final int MSG_REPORT_NEW_ROUTES_A2DP = 36; private static final int MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET = 37; private static final int MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET = 38; private static final int MSG_L_SET_COMMUNICATION_DEVICE_FOR_CLIENT = 42; private static final int MSG_IL_UPDATE_COMMUNICATION_ROUTE_CLIENT = 43; Loading @@ -2169,8 +2100,6 @@ public class AudioDeviceBroker { // process set volume for Le Audio, obj is BleVolumeInfo private static final int MSG_II_SET_LE_AUDIO_OUT_VOLUME = 46; private static final int MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY = 47; private static final int MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY = 48; private static final int MSG_IIL_BTLEAUDIO_TIMEOUT = 49; private static final int MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED = 52; Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +72 −67 Original line number Diff line number Diff line Loading @@ -536,14 +536,17 @@ public class AudioDeviceInventory { @GuardedBy("mDevicesLock") private final ArrayMap<Integer, String> mApmConnectedDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of preferred devices for strategies private final ArrayMap<Integer, List<AudioDeviceAttributes>> mPreferredDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of non-default devices for strategies private final ArrayMap<Integer, List<AudioDeviceAttributes>> mNonDefaultDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of preferred devices of capture preset private final ArrayMap<Integer, List<AudioDeviceAttributes>> mPreferredDevicesForCapturePreset = new ArrayMap<>(); Loading Loading @@ -781,19 +784,13 @@ public class AudioDeviceInventory { synchronized (mDevicesLock) { mAppliedStrategyRoles.clear(); mAppliedPresetRoles.clear(); } synchronized (mPreferredDevices) { mPreferredDevices.forEach((strategy, devices) -> { setPreferredDevicesForStrategy(strategy, devices); }); } synchronized (mNonDefaultDevices) { mNonDefaultDevices.forEach((strategy, devices) -> { addDevicesRoleForStrategy(strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); }); } synchronized (mPreferredDevicesForCapturePreset) { mPreferredDevicesForCapturePreset.forEach((capturePreset, devices) -> { setDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); Loading Loading @@ -1198,7 +1195,8 @@ public class AudioDeviceInventory { mmi.record(); } /*package*/ void onSaveSetPreferredDevices(int strategy, @GuardedBy("mDevicesLock") private void saveSetPreferredDevices(int strategy, @NonNull List<AudioDeviceAttributes> devices) { mPreferredDevices.put(strategy, devices); List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); Loading @@ -1216,12 +1214,14 @@ public class AudioDeviceInventory { dispatchPreferredDevice(strategy, devices); } /*package*/ void onSaveRemovePreferredDevices(int strategy) { @GuardedBy("mDevicesLock") private void saveRemovePreferredDevices(int strategy) { mPreferredDevices.remove(strategy); dispatchPreferredDevice(strategy, new ArrayList<AudioDeviceAttributes>()); } /*package*/ void onSaveSetDeviceAsNonDefault(int strategy, @GuardedBy("mDevicesLock") private void saveSetDeviceAsNonDefault(int strategy, @NonNull AudioDeviceAttributes device) { List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); if (nonDefaultDevices == null) { Loading @@ -1245,7 +1245,8 @@ public class AudioDeviceInventory { } } /*package*/ void onSaveRemoveDeviceAsNonDefault(int strategy, @GuardedBy("mDevicesLock") private void saveRemoveDeviceAsNonDefault(int strategy, @NonNull AudioDeviceAttributes device) { List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); if (nonDefaultDevices != null) { Loading @@ -1255,14 +1256,16 @@ public class AudioDeviceInventory { } } /*package*/ void onSaveSetPreferredDevicesForCapturePreset( @GuardedBy("mDevicesLock") private void saveSetPreferredDevicesForCapturePreset( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { mPreferredDevicesForCapturePreset.put(capturePreset, devices); dispatchDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); } /*package*/ void onSaveClearPreferredDevicesForCapturePreset(int capturePreset) { @GuardedBy("mDevicesLock") private void saveClearPreferredDevicesForCapturePreset(int capturePreset) { mPreferredDevicesForCapturePreset.remove(capturePreset); dispatchDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, Loading @@ -1274,22 +1277,23 @@ public class AudioDeviceInventory { /*package*/ int setPreferredDevicesForStrategyAndSave(int strategy, @NonNull List<AudioDeviceAttributes> devices) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = setPreferredDevicesForStrategy(strategy, devices); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetPreferredDevicesForStrategy(strategy, devices); saveSetPreferredDevices(strategy, devices); } return status; } } } // Only used for external requests coming from an API /*package*/ int setPreferredDevicesForStrategy(int strategy, @NonNull List<AudioDeviceAttributes> devices) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = setDevicesRoleForStrategy( return setDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_PREFERRED, devices, false /* internal */); } return status; } // Only used for internal requests /*package*/ int setPreferredDevicesForStrategyInt(int strategy, @NonNull List<AudioDeviceAttributes> devices) { Loading @@ -1299,22 +1303,22 @@ public class AudioDeviceInventory { } /*package*/ int removePreferredDevicesForStrategyAndSave(int strategy) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = removePreferredDevicesForStrategy(strategy); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveRemovePreferredDevicesForStrategy(strategy); saveRemovePreferredDevices(strategy); } return status; } } } // Only used for external requests coming from an API /*package*/ int removePreferredDevicesForStrategy(int strategy) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = clearDevicesRoleForStrategy( return clearDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_PREFERRED, false /*internal */); } return status; } // Only used for internal requests /*package*/ int removePreferredDevicesForStrategyInt(int strategy) { return clearDevicesRoleForStrategy( Loading @@ -1324,16 +1328,17 @@ public class AudioDeviceInventory { /*package*/ int setDeviceAsNonDefaultForStrategyAndSave(int strategy, @NonNull AudioDeviceAttributes device) { int status = AudioSystem.ERROR; synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { List<AudioDeviceAttributes> devices = new ArrayList<>(); devices.add(device); status = addDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); } if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetDeviceAsNonDefaultForStrategy(strategy, device); saveSetDeviceAsNonDefault(strategy, device); } } } return status; } Loading @@ -1341,16 +1346,17 @@ public class AudioDeviceInventory { /*package*/ int removeDeviceAsNonDefaultForStrategyAndSave(int strategy, @NonNull AudioDeviceAttributes device) { int status = AudioSystem.ERROR; synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { List<AudioDeviceAttributes> devices = new ArrayList<>(); devices.add(device); status = removeDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); } if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveRemoveDeviceAsNonDefaultForStrategy(strategy, device); saveRemoveDeviceAsNonDefault(strategy, device); } } } return status; } Loading Loading @@ -1378,42 +1384,41 @@ public class AudioDeviceInventory { /*package*/ int setPreferredDevicesForCapturePresetAndSave( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = setPreferredDevicesForCapturePreset(capturePreset, devices); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetPreferredDevicesForCapturePreset(capturePreset, devices); saveSetPreferredDevicesForCapturePreset(capturePreset, devices); } return status; } } } // Only used for external requests coming from an API private int setPreferredDevicesForCapturePreset( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = setDevicesRoleForCapturePreset( return setDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); } return status; } /*package*/ int clearPreferredDevicesForCapturePresetAndSave(int capturePreset) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = clearPreferredDevicesForCapturePreset(capturePreset); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveClearPreferredDevicesForCapturePreset(capturePreset); saveClearPreferredDevicesForCapturePreset(capturePreset); } return status; } } } // Only used for external requests coming from an API private int clearPreferredDevicesForCapturePreset(int capturePreset) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = clearDevicesRoleForCapturePreset( return clearDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED); } return status; } // Only used for internal requests private int addDevicesRoleForCapturePresetInt(int capturePreset, int role, Loading Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +0 −71 Original line number Diff line number Diff line Loading @@ -1483,38 +1483,6 @@ public class AudioDeviceBroker { sendLMsgNoDelay(MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED, SENDMSG_QUEUE, client); } /*package*/ void postSaveSetPreferredDevicesForStrategy(int strategy, List<AudioDeviceAttributes> devices) { sendILMsgNoDelay(MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY, SENDMSG_QUEUE, strategy, devices); } /*package*/ void postSaveRemovePreferredDevicesForStrategy(int strategy) { sendIMsgNoDelay(MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY, SENDMSG_QUEUE, strategy); } /*package*/ void postSaveSetDeviceAsNonDefaultForStrategy( int strategy, AudioDeviceAttributes device) { sendILMsgNoDelay(MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY, SENDMSG_QUEUE, strategy, device); } /*package*/ void postSaveRemoveDeviceAsNonDefaultForStrategy( int strategy, AudioDeviceAttributes device) { sendILMsgNoDelay( MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY, SENDMSG_QUEUE, strategy, device); } /*package*/ void postSaveSetPreferredDevicesForCapturePreset( int capturePreset, List<AudioDeviceAttributes> devices) { sendILMsgNoDelay( MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET, SENDMSG_QUEUE, capturePreset, devices); } /*package*/ void postSaveClearPreferredDevicesForCapturePreset(int capturePreset) { sendIMsgNoDelay( MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET, SENDMSG_QUEUE, capturePreset); } /*package*/ void postUpdateCommunicationRouteClient( boolean wasBtScoRequested, String eventSource) { sendILMsgNoDelay(MSG_IL_UPDATE_COMMUNICATION_ROUTE_CLIENT, SENDMSG_QUEUE, Loading Loading @@ -2025,40 +1993,9 @@ public class AudioDeviceBroker { mDeviceInventory.setBluetoothActiveDevice(btInfo); } } break; case MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY: { final int strategy = msg.arg1; final List<AudioDeviceAttributes> devices = (List<AudioDeviceAttributes>) msg.obj; mDeviceInventory.onSaveSetPreferredDevices(strategy, devices); } break; case MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY: { final int strategy = msg.arg1; mDeviceInventory.onSaveRemovePreferredDevices(strategy); } break; case MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY: { final int strategy = msg.arg1; final AudioDeviceAttributes device = (AudioDeviceAttributes) msg.obj; mDeviceInventory.onSaveSetDeviceAsNonDefault(strategy, device); } break; case MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY: { final int strategy = msg.arg1; final AudioDeviceAttributes device = (AudioDeviceAttributes) msg.obj; mDeviceInventory.onSaveRemoveDeviceAsNonDefault(strategy, device); } break; case MSG_CHECK_MUTE_MUSIC: checkMessagesMuteMusic(0); break; case MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET: { final int capturePreset = msg.arg1; final List<AudioDeviceAttributes> devices = (List<AudioDeviceAttributes>) msg.obj; mDeviceInventory.onSaveSetPreferredDevicesForCapturePreset( capturePreset, devices); } break; case MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET: { final int capturePreset = msg.arg1; mDeviceInventory.onSaveClearPreferredDevicesForCapturePreset(capturePreset); } break; case MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED: { final BluetoothDevice btDevice = (BluetoothDevice) msg.obj; BtHelper.onNotifyPreferredAudioProfileApplied(btDevice); Loading Loading @@ -2151,16 +2088,10 @@ public class AudioDeviceBroker { // process external command to (dis)connect a hearing aid device private static final int MSG_L_HEARING_AID_DEVICE_CONNECTION_CHANGE_EXT = 31; private static final int MSG_IL_SAVE_PREF_DEVICES_FOR_STRATEGY = 32; private static final int MSG_I_SAVE_REMOVE_PREF_DEVICES_FOR_STRATEGY = 33; private static final int MSG_L_COMMUNICATION_ROUTE_CLIENT_DIED = 34; private static final int MSG_CHECK_MUTE_MUSIC = 35; private static final int MSG_REPORT_NEW_ROUTES_A2DP = 36; private static final int MSG_IL_SAVE_PREF_DEVICES_FOR_CAPTURE_PRESET = 37; private static final int MSG_I_SAVE_CLEAR_PREF_DEVICES_FOR_CAPTURE_PRESET = 38; private static final int MSG_L_SET_COMMUNICATION_DEVICE_FOR_CLIENT = 42; private static final int MSG_IL_UPDATE_COMMUNICATION_ROUTE_CLIENT = 43; Loading @@ -2169,8 +2100,6 @@ public class AudioDeviceBroker { // process set volume for Le Audio, obj is BleVolumeInfo private static final int MSG_II_SET_LE_AUDIO_OUT_VOLUME = 46; private static final int MSG_IL_SAVE_NDEF_DEVICE_FOR_STRATEGY = 47; private static final int MSG_IL_SAVE_REMOVE_NDEF_DEVICE_FOR_STRATEGY = 48; private static final int MSG_IIL_BTLEAUDIO_TIMEOUT = 49; private static final int MSG_L_NOTIFY_PREFERRED_AUDIOPROFILE_APPLIED = 52; Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +72 −67 Original line number Diff line number Diff line Loading @@ -536,14 +536,17 @@ public class AudioDeviceInventory { @GuardedBy("mDevicesLock") private final ArrayMap<Integer, String> mApmConnectedDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of preferred devices for strategies private final ArrayMap<Integer, List<AudioDeviceAttributes>> mPreferredDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of non-default devices for strategies private final ArrayMap<Integer, List<AudioDeviceAttributes>> mNonDefaultDevices = new ArrayMap<>(); @GuardedBy("mDevicesLock") // List of preferred devices of capture preset private final ArrayMap<Integer, List<AudioDeviceAttributes>> mPreferredDevicesForCapturePreset = new ArrayMap<>(); Loading Loading @@ -781,19 +784,13 @@ public class AudioDeviceInventory { synchronized (mDevicesLock) { mAppliedStrategyRoles.clear(); mAppliedPresetRoles.clear(); } synchronized (mPreferredDevices) { mPreferredDevices.forEach((strategy, devices) -> { setPreferredDevicesForStrategy(strategy, devices); }); } synchronized (mNonDefaultDevices) { mNonDefaultDevices.forEach((strategy, devices) -> { addDevicesRoleForStrategy(strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); }); } synchronized (mPreferredDevicesForCapturePreset) { mPreferredDevicesForCapturePreset.forEach((capturePreset, devices) -> { setDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); Loading Loading @@ -1198,7 +1195,8 @@ public class AudioDeviceInventory { mmi.record(); } /*package*/ void onSaveSetPreferredDevices(int strategy, @GuardedBy("mDevicesLock") private void saveSetPreferredDevices(int strategy, @NonNull List<AudioDeviceAttributes> devices) { mPreferredDevices.put(strategy, devices); List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); Loading @@ -1216,12 +1214,14 @@ public class AudioDeviceInventory { dispatchPreferredDevice(strategy, devices); } /*package*/ void onSaveRemovePreferredDevices(int strategy) { @GuardedBy("mDevicesLock") private void saveRemovePreferredDevices(int strategy) { mPreferredDevices.remove(strategy); dispatchPreferredDevice(strategy, new ArrayList<AudioDeviceAttributes>()); } /*package*/ void onSaveSetDeviceAsNonDefault(int strategy, @GuardedBy("mDevicesLock") private void saveSetDeviceAsNonDefault(int strategy, @NonNull AudioDeviceAttributes device) { List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); if (nonDefaultDevices == null) { Loading @@ -1245,7 +1245,8 @@ public class AudioDeviceInventory { } } /*package*/ void onSaveRemoveDeviceAsNonDefault(int strategy, @GuardedBy("mDevicesLock") private void saveRemoveDeviceAsNonDefault(int strategy, @NonNull AudioDeviceAttributes device) { List<AudioDeviceAttributes> nonDefaultDevices = mNonDefaultDevices.get(strategy); if (nonDefaultDevices != null) { Loading @@ -1255,14 +1256,16 @@ public class AudioDeviceInventory { } } /*package*/ void onSaveSetPreferredDevicesForCapturePreset( @GuardedBy("mDevicesLock") private void saveSetPreferredDevicesForCapturePreset( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { mPreferredDevicesForCapturePreset.put(capturePreset, devices); dispatchDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); } /*package*/ void onSaveClearPreferredDevicesForCapturePreset(int capturePreset) { @GuardedBy("mDevicesLock") private void saveClearPreferredDevicesForCapturePreset(int capturePreset) { mPreferredDevicesForCapturePreset.remove(capturePreset); dispatchDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, Loading @@ -1274,22 +1277,23 @@ public class AudioDeviceInventory { /*package*/ int setPreferredDevicesForStrategyAndSave(int strategy, @NonNull List<AudioDeviceAttributes> devices) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = setPreferredDevicesForStrategy(strategy, devices); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetPreferredDevicesForStrategy(strategy, devices); saveSetPreferredDevices(strategy, devices); } return status; } } } // Only used for external requests coming from an API /*package*/ int setPreferredDevicesForStrategy(int strategy, @NonNull List<AudioDeviceAttributes> devices) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = setDevicesRoleForStrategy( return setDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_PREFERRED, devices, false /* internal */); } return status; } // Only used for internal requests /*package*/ int setPreferredDevicesForStrategyInt(int strategy, @NonNull List<AudioDeviceAttributes> devices) { Loading @@ -1299,22 +1303,22 @@ public class AudioDeviceInventory { } /*package*/ int removePreferredDevicesForStrategyAndSave(int strategy) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = removePreferredDevicesForStrategy(strategy); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveRemovePreferredDevicesForStrategy(strategy); saveRemovePreferredDevices(strategy); } return status; } } } // Only used for external requests coming from an API /*package*/ int removePreferredDevicesForStrategy(int strategy) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = clearDevicesRoleForStrategy( return clearDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_PREFERRED, false /*internal */); } return status; } // Only used for internal requests /*package*/ int removePreferredDevicesForStrategyInt(int strategy) { return clearDevicesRoleForStrategy( Loading @@ -1324,16 +1328,17 @@ public class AudioDeviceInventory { /*package*/ int setDeviceAsNonDefaultForStrategyAndSave(int strategy, @NonNull AudioDeviceAttributes device) { int status = AudioSystem.ERROR; synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { List<AudioDeviceAttributes> devices = new ArrayList<>(); devices.add(device); status = addDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); } if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetDeviceAsNonDefaultForStrategy(strategy, device); saveSetDeviceAsNonDefault(strategy, device); } } } return status; } Loading @@ -1341,16 +1346,17 @@ public class AudioDeviceInventory { /*package*/ int removeDeviceAsNonDefaultForStrategyAndSave(int strategy, @NonNull AudioDeviceAttributes device) { int status = AudioSystem.ERROR; synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { List<AudioDeviceAttributes> devices = new ArrayList<>(); devices.add(device); status = removeDevicesRoleForStrategy( strategy, AudioSystem.DEVICE_ROLE_DISABLED, devices, false /* internal */); } if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveRemoveDeviceAsNonDefaultForStrategy(strategy, device); saveRemoveDeviceAsNonDefault(strategy, device); } } } return status; } Loading Loading @@ -1378,42 +1384,41 @@ public class AudioDeviceInventory { /*package*/ int setPreferredDevicesForCapturePresetAndSave( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = setPreferredDevicesForCapturePreset(capturePreset, devices); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveSetPreferredDevicesForCapturePreset(capturePreset, devices); saveSetPreferredDevicesForCapturePreset(capturePreset, devices); } return status; } } } // Only used for external requests coming from an API private int setPreferredDevicesForCapturePreset( int capturePreset, @NonNull List<AudioDeviceAttributes> devices) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = setDevicesRoleForCapturePreset( return setDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED, devices); } return status; } /*package*/ int clearPreferredDevicesForCapturePresetAndSave(int capturePreset) { synchronized(mDevicesLock){ try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { final int status = clearPreferredDevicesForCapturePreset(capturePreset); if (status == AudioSystem.SUCCESS) { mDeviceBroker.postSaveClearPreferredDevicesForCapturePreset(capturePreset); saveClearPreferredDevicesForCapturePreset(capturePreset); } return status; } } } // Only used for external requests coming from an API private int clearPreferredDevicesForCapturePreset(int capturePreset) { int status = AudioSystem.ERROR; try (SafeCloseable ignored = ClearCallingIdentityContext.create()) { status = clearDevicesRoleForCapturePreset( return clearDevicesRoleForCapturePreset( capturePreset, AudioSystem.DEVICE_ROLE_PREFERRED); } return status; } // Only used for internal requests private int addDevicesRoleForCapturePresetInt(int capturePreset, int role, Loading