Loading services/core/java/com/android/server/audio/AudioDeviceBroker.java +27 −28 Original line number Diff line number Diff line Loading @@ -275,7 +275,7 @@ public class AudioDeviceBroker { * Handle BluetoothHeadset intents where the action is one of * {@link BluetoothHeadset#ACTION_ACTIVE_DEVICE_CHANGED} or * {@link BluetoothHeadset#ACTION_AUDIO_STATE_CHANGED}. * @param intent * @param intent the Intent received from BT service */ private void onReceiveBtEvent(@NonNull Intent intent) { mBtHelper.onReceiveBtEvent(intent); Loading @@ -296,7 +296,7 @@ public class AudioDeviceBroker { /** * Turns speakerphone on/off * @param on * @param on true to enable speakerphone * @param eventSource for logging purposes */ /*package*/ void setSpeakerphoneOn( Loading @@ -310,21 +310,21 @@ public class AudioDeviceBroker { on, BtHelper.SCO_MODE_UNDEFINED, eventSource, isPrivileged)); } private static final long SET_COMMUNICATION_DEVICE_TIMEOUT_MS = 3000; /** synchronization for setCommunicationDevice() and getCommunicationDevice */ private final Object mCommunicationDeviceLock = new Object(); @GuardedBy("mCommunicationDeviceLock") private int mCommunicationDeviceUpdateCount = 0; /** * Select device for use for communication use cases. * @param cb Client binder for death detection * @param uid Client uid * @param device Device selected or null to unselect. * @param eventSource for logging purposes * @return false if there is no device and no communication client */ private static final long SET_COMMUNICATION_DEVICE_TIMEOUT_MS = 3000; /** synchronization for setCommunicationDevice() and getCommunicationDevice */ private Object mCommunicationDeviceLock = new Object(); @GuardedBy("mCommunicationDeviceLock") private int mCommunicationDeviceUpdateCount = 0; /*package*/ boolean setCommunicationDevice(IBinder cb, int uid, AudioDeviceInfo device, boolean isPrivileged, String eventSource) { Loading Loading @@ -355,7 +355,6 @@ public class AudioDeviceBroker { * Sets or resets the communication device for matching client. If no client matches and the * request is to reset for a given device (deviceInfo.mOn == false), the method is a noop. * @param deviceInfo information on the device and requester {@link #CommunicationDeviceInfo} * @return true if the communication device is set or reset */ @GuardedBy("mDeviceStateLock") /*package*/ void onSetCommunicationDeviceForClient(CommunicationDeviceInfo deviceInfo) { Loading Loading @@ -741,15 +740,6 @@ public class AudioDeviceBroker { && mPreferredCommunicationDevice.getType() == deviceType; } /** * Helper method on top of isDeviceRequestedForCommunication() indicating if * speakerphone ON is currently requested or not. * @return true if speakerphone ON requested, false otherwise. */ private boolean isSpeakerphoneRequested() { return isDeviceRequestedForCommunication(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER); } /** * Indicates if preferred route selection for communication is speakerphone. * @return true if speakerphone is active, false otherwise. Loading Loading @@ -928,6 +918,12 @@ public class AudioDeviceBroker { return false; } @Override public int hashCode() { // only hashing on the fields used in equals() return Objects.hash(mProfile, mDevice); } @Override public String toString() { return "BtDeviceInfo: device=" + mDevice.toString() Loading Loading @@ -990,7 +986,7 @@ public class AudioDeviceBroker { /** * will block on mDeviceStateLock, which is held during an A2DP (dis) connection * not just a simple message post * @param info struct with the (dis)connection information * @param data struct with the (dis)connection information */ /*package*/ void queueOnBluetoothActiveDeviceChanged(@NonNull BtDeviceChangedData data) { if (data.mPreviousDevice != null Loading Loading @@ -1379,6 +1375,7 @@ public class AudioDeviceBroker { mCommDevDispatchers.getBroadcastItem(i) .dispatchCommunicationDeviceChanged(portId); } catch (RemoteException e) { Log.e(TAG, "dispatchCommunicationDevice error", e); } } mCommDevDispatchers.finishBroadcast(); Loading Loading @@ -1580,6 +1577,12 @@ public class AudioDeviceBroker { && mUid == ((CommunicationDeviceInfo) o).mUid; } @Override public int hashCode() { // only hashing on the fields used in equals() return Objects.hash(mCb.hashCode(), mUid); } @Override public String toString() { return "CommunicationDeviceInfo mCb=" + mCb.toString() Loading @@ -1600,9 +1603,9 @@ public class AudioDeviceBroker { //@GuardedBy("mConnectedDevices") /*package*/ void setBluetoothA2dpOnInt(boolean on, boolean fromA2dp, String source) { // for logging only final String eventSource = new StringBuilder("setBluetoothA2dpOn(").append(on) .append(") from u/pid:").append(Binder.getCallingUid()).append("/") .append(Binder.getCallingPid()).append(" src:").append(source).toString(); final String eventSource = "setBluetoothA2dpOn(" + on + ") from u/pid:" + Binder.getCallingUid() + "/" + Binder.getCallingPid() + " src:" + source; mBluetoothA2dpEnabled.set(on); onSetForceUse( Loading Loading @@ -2203,10 +2206,6 @@ public class AudioDeviceBroker { sendIILMsg(msg, existingMsgPolicy, 0, 0, obj, delay); } private void sendIMsg(int msg, int existingMsgPolicy, int arg, int delay) { sendIILMsg(msg, existingMsgPolicy, arg, 0, null, delay); } private void sendMsgNoDelay(int msg, int existingMsgPolicy) { sendIILMsg(msg, existingMsgPolicy, 0, 0, null, 0); } Loading services/core/java/com/android/server/audio/AudioDeviceInventory.java +15 −13 Original line number Diff line number Diff line Loading @@ -449,7 +449,7 @@ public class AudioDeviceInventory { @Override public DeviceInfo put(String key, DeviceInfo value) { final DeviceInfo result = super.put(key, value); record("put", true /* connected */, key, value); record("put", true /* connected */, value); return result; } Loading @@ -457,7 +457,7 @@ public class AudioDeviceInventory { public DeviceInfo putIfAbsent(String key, DeviceInfo value) { final DeviceInfo result = super.putIfAbsent(key, value); if (result == null) { record("putIfAbsent", true /* connected */, key, value); record("putIfAbsent", true /* connected */, value); } return result; } Loading @@ -466,7 +466,7 @@ public class AudioDeviceInventory { public DeviceInfo remove(Object key) { final DeviceInfo result = super.remove(key); if (result != null) { record("remove", false /* connected */, (String) key, result); record("remove", false /* connected */, result); } return result; } Loading @@ -475,7 +475,7 @@ public class AudioDeviceInventory { public boolean remove(Object key, Object value) { final boolean result = super.remove(key, value); if (result) { record("remove", false /* connected */, (String) key, (DeviceInfo) value); record("remove", false /* connected */, (DeviceInfo) value); } return result; } Loading @@ -489,7 +489,7 @@ public class AudioDeviceInventory { // putAll // replace // replaceAll private void record(String event, boolean connected, String key, DeviceInfo value) { private void record(String event, boolean connected, DeviceInfo value) { // DeviceInfo - int mDeviceType; // DeviceInfo - int mDeviceCodecFormat; new MediaMetrics.Item(MediaMetrics.Name.AUDIO_DEVICE Loading Loading @@ -662,7 +662,7 @@ public class AudioDeviceInventory { /** * A class just for packaging up a set of connection parameters. */ /*package*/ class WiredDeviceConnectionState { /*package*/ static class WiredDeviceConnectionState { public final AudioDeviceAttributes mAttributes; public final @AudioService.ConnectionState int mState; public final String mCaller; Loading Loading @@ -1054,7 +1054,9 @@ public class AudioDeviceInventory { IAudioRoutesObserver obs = mRoutesObservers.getBroadcastItem(n); try { obs.dispatchAudioRoutesChanged(routes); } catch (RemoteException e) { } } catch (RemoteException e) { Log.e(TAG, "onReportNewRoutes", e); } } } mRoutesObservers.finishBroadcast(); Loading Loading @@ -1835,7 +1837,8 @@ public class AudioDeviceInventory { .set(MediaMetrics.Property.EVENT, "disconnectHearingAid") .record(); if (toRemove.size() > 0) { final int delay = checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, /*final int delay = */ checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, AudioService.CONNECTION_STATE_DISCONNECTED, AudioSystem.DEVICE_NONE); toRemove.stream().forEach(deviceAddress -> // TODO delay not used? Loading Loading @@ -2697,10 +2700,6 @@ public class AudioDeviceInventory { private static final String CONNECT_INTENT_KEY_PORT_NAME = "portName"; private static final String CONNECT_INTENT_KEY_STATE = "state"; private static final String CONNECT_INTENT_KEY_ADDRESS = "address"; private static final String CONNECT_INTENT_KEY_HAS_PLAYBACK = "hasPlayback"; private static final String CONNECT_INTENT_KEY_HAS_CAPTURE = "hasCapture"; private static final String CONNECT_INTENT_KEY_HAS_MIDI = "hasMIDI"; private static final String CONNECT_INTENT_KEY_DEVICE_CLASS = "class"; private void sendDeviceConnectionIntent(int device, int state, String address, String deviceName) { Loading Loading @@ -2863,6 +2862,7 @@ public class AudioDeviceInventory { mPrefDevDispatchers.getBroadcastItem(i).dispatchPrefDevicesChanged( strategy, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchPreferredDevice ", e); } } mPrefDevDispatchers.finishBroadcast(); Loading @@ -2879,6 +2879,7 @@ public class AudioDeviceInventory { mNonDefDevDispatchers.getBroadcastItem(i).dispatchNonDefDevicesChanged( strategy, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchNonDefaultDevice ", e); } } mNonDefDevDispatchers.finishBroadcast(); Loading @@ -2895,6 +2896,7 @@ public class AudioDeviceInventory { mDevRoleCapturePresetDispatchers.getBroadcastItem(i).dispatchDevicesRoleChanged( capturePreset, role, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchDevicesRoleForCapturePreset ", e); } } mDevRoleCapturePresetDispatchers.finishBroadcast(); Loading Loading @@ -2960,7 +2962,7 @@ public class AudioDeviceInventory { /** * Check if device is in the list of connected devices * @param device * @param device the device to query * @return true if connected */ @VisibleForTesting Loading Loading
services/core/java/com/android/server/audio/AudioDeviceBroker.java +27 −28 Original line number Diff line number Diff line Loading @@ -275,7 +275,7 @@ public class AudioDeviceBroker { * Handle BluetoothHeadset intents where the action is one of * {@link BluetoothHeadset#ACTION_ACTIVE_DEVICE_CHANGED} or * {@link BluetoothHeadset#ACTION_AUDIO_STATE_CHANGED}. * @param intent * @param intent the Intent received from BT service */ private void onReceiveBtEvent(@NonNull Intent intent) { mBtHelper.onReceiveBtEvent(intent); Loading @@ -296,7 +296,7 @@ public class AudioDeviceBroker { /** * Turns speakerphone on/off * @param on * @param on true to enable speakerphone * @param eventSource for logging purposes */ /*package*/ void setSpeakerphoneOn( Loading @@ -310,21 +310,21 @@ public class AudioDeviceBroker { on, BtHelper.SCO_MODE_UNDEFINED, eventSource, isPrivileged)); } private static final long SET_COMMUNICATION_DEVICE_TIMEOUT_MS = 3000; /** synchronization for setCommunicationDevice() and getCommunicationDevice */ private final Object mCommunicationDeviceLock = new Object(); @GuardedBy("mCommunicationDeviceLock") private int mCommunicationDeviceUpdateCount = 0; /** * Select device for use for communication use cases. * @param cb Client binder for death detection * @param uid Client uid * @param device Device selected or null to unselect. * @param eventSource for logging purposes * @return false if there is no device and no communication client */ private static final long SET_COMMUNICATION_DEVICE_TIMEOUT_MS = 3000; /** synchronization for setCommunicationDevice() and getCommunicationDevice */ private Object mCommunicationDeviceLock = new Object(); @GuardedBy("mCommunicationDeviceLock") private int mCommunicationDeviceUpdateCount = 0; /*package*/ boolean setCommunicationDevice(IBinder cb, int uid, AudioDeviceInfo device, boolean isPrivileged, String eventSource) { Loading Loading @@ -355,7 +355,6 @@ public class AudioDeviceBroker { * Sets or resets the communication device for matching client. If no client matches and the * request is to reset for a given device (deviceInfo.mOn == false), the method is a noop. * @param deviceInfo information on the device and requester {@link #CommunicationDeviceInfo} * @return true if the communication device is set or reset */ @GuardedBy("mDeviceStateLock") /*package*/ void onSetCommunicationDeviceForClient(CommunicationDeviceInfo deviceInfo) { Loading Loading @@ -741,15 +740,6 @@ public class AudioDeviceBroker { && mPreferredCommunicationDevice.getType() == deviceType; } /** * Helper method on top of isDeviceRequestedForCommunication() indicating if * speakerphone ON is currently requested or not. * @return true if speakerphone ON requested, false otherwise. */ private boolean isSpeakerphoneRequested() { return isDeviceRequestedForCommunication(AudioDeviceInfo.TYPE_BUILTIN_SPEAKER); } /** * Indicates if preferred route selection for communication is speakerphone. * @return true if speakerphone is active, false otherwise. Loading Loading @@ -928,6 +918,12 @@ public class AudioDeviceBroker { return false; } @Override public int hashCode() { // only hashing on the fields used in equals() return Objects.hash(mProfile, mDevice); } @Override public String toString() { return "BtDeviceInfo: device=" + mDevice.toString() Loading Loading @@ -990,7 +986,7 @@ public class AudioDeviceBroker { /** * will block on mDeviceStateLock, which is held during an A2DP (dis) connection * not just a simple message post * @param info struct with the (dis)connection information * @param data struct with the (dis)connection information */ /*package*/ void queueOnBluetoothActiveDeviceChanged(@NonNull BtDeviceChangedData data) { if (data.mPreviousDevice != null Loading Loading @@ -1379,6 +1375,7 @@ public class AudioDeviceBroker { mCommDevDispatchers.getBroadcastItem(i) .dispatchCommunicationDeviceChanged(portId); } catch (RemoteException e) { Log.e(TAG, "dispatchCommunicationDevice error", e); } } mCommDevDispatchers.finishBroadcast(); Loading Loading @@ -1580,6 +1577,12 @@ public class AudioDeviceBroker { && mUid == ((CommunicationDeviceInfo) o).mUid; } @Override public int hashCode() { // only hashing on the fields used in equals() return Objects.hash(mCb.hashCode(), mUid); } @Override public String toString() { return "CommunicationDeviceInfo mCb=" + mCb.toString() Loading @@ -1600,9 +1603,9 @@ public class AudioDeviceBroker { //@GuardedBy("mConnectedDevices") /*package*/ void setBluetoothA2dpOnInt(boolean on, boolean fromA2dp, String source) { // for logging only final String eventSource = new StringBuilder("setBluetoothA2dpOn(").append(on) .append(") from u/pid:").append(Binder.getCallingUid()).append("/") .append(Binder.getCallingPid()).append(" src:").append(source).toString(); final String eventSource = "setBluetoothA2dpOn(" + on + ") from u/pid:" + Binder.getCallingUid() + "/" + Binder.getCallingPid() + " src:" + source; mBluetoothA2dpEnabled.set(on); onSetForceUse( Loading Loading @@ -2203,10 +2206,6 @@ public class AudioDeviceBroker { sendIILMsg(msg, existingMsgPolicy, 0, 0, obj, delay); } private void sendIMsg(int msg, int existingMsgPolicy, int arg, int delay) { sendIILMsg(msg, existingMsgPolicy, arg, 0, null, delay); } private void sendMsgNoDelay(int msg, int existingMsgPolicy) { sendIILMsg(msg, existingMsgPolicy, 0, 0, null, 0); } Loading
services/core/java/com/android/server/audio/AudioDeviceInventory.java +15 −13 Original line number Diff line number Diff line Loading @@ -449,7 +449,7 @@ public class AudioDeviceInventory { @Override public DeviceInfo put(String key, DeviceInfo value) { final DeviceInfo result = super.put(key, value); record("put", true /* connected */, key, value); record("put", true /* connected */, value); return result; } Loading @@ -457,7 +457,7 @@ public class AudioDeviceInventory { public DeviceInfo putIfAbsent(String key, DeviceInfo value) { final DeviceInfo result = super.putIfAbsent(key, value); if (result == null) { record("putIfAbsent", true /* connected */, key, value); record("putIfAbsent", true /* connected */, value); } return result; } Loading @@ -466,7 +466,7 @@ public class AudioDeviceInventory { public DeviceInfo remove(Object key) { final DeviceInfo result = super.remove(key); if (result != null) { record("remove", false /* connected */, (String) key, result); record("remove", false /* connected */, result); } return result; } Loading @@ -475,7 +475,7 @@ public class AudioDeviceInventory { public boolean remove(Object key, Object value) { final boolean result = super.remove(key, value); if (result) { record("remove", false /* connected */, (String) key, (DeviceInfo) value); record("remove", false /* connected */, (DeviceInfo) value); } return result; } Loading @@ -489,7 +489,7 @@ public class AudioDeviceInventory { // putAll // replace // replaceAll private void record(String event, boolean connected, String key, DeviceInfo value) { private void record(String event, boolean connected, DeviceInfo value) { // DeviceInfo - int mDeviceType; // DeviceInfo - int mDeviceCodecFormat; new MediaMetrics.Item(MediaMetrics.Name.AUDIO_DEVICE Loading Loading @@ -662,7 +662,7 @@ public class AudioDeviceInventory { /** * A class just for packaging up a set of connection parameters. */ /*package*/ class WiredDeviceConnectionState { /*package*/ static class WiredDeviceConnectionState { public final AudioDeviceAttributes mAttributes; public final @AudioService.ConnectionState int mState; public final String mCaller; Loading Loading @@ -1054,7 +1054,9 @@ public class AudioDeviceInventory { IAudioRoutesObserver obs = mRoutesObservers.getBroadcastItem(n); try { obs.dispatchAudioRoutesChanged(routes); } catch (RemoteException e) { } } catch (RemoteException e) { Log.e(TAG, "onReportNewRoutes", e); } } } mRoutesObservers.finishBroadcast(); Loading Loading @@ -1835,7 +1837,8 @@ public class AudioDeviceInventory { .set(MediaMetrics.Property.EVENT, "disconnectHearingAid") .record(); if (toRemove.size() > 0) { final int delay = checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, /*final int delay = */ checkSendBecomingNoisyIntentInt(DEVICE_OUT_HEARING_AID, AudioService.CONNECTION_STATE_DISCONNECTED, AudioSystem.DEVICE_NONE); toRemove.stream().forEach(deviceAddress -> // TODO delay not used? Loading Loading @@ -2697,10 +2700,6 @@ public class AudioDeviceInventory { private static final String CONNECT_INTENT_KEY_PORT_NAME = "portName"; private static final String CONNECT_INTENT_KEY_STATE = "state"; private static final String CONNECT_INTENT_KEY_ADDRESS = "address"; private static final String CONNECT_INTENT_KEY_HAS_PLAYBACK = "hasPlayback"; private static final String CONNECT_INTENT_KEY_HAS_CAPTURE = "hasCapture"; private static final String CONNECT_INTENT_KEY_HAS_MIDI = "hasMIDI"; private static final String CONNECT_INTENT_KEY_DEVICE_CLASS = "class"; private void sendDeviceConnectionIntent(int device, int state, String address, String deviceName) { Loading Loading @@ -2863,6 +2862,7 @@ public class AudioDeviceInventory { mPrefDevDispatchers.getBroadcastItem(i).dispatchPrefDevicesChanged( strategy, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchPreferredDevice ", e); } } mPrefDevDispatchers.finishBroadcast(); Loading @@ -2879,6 +2879,7 @@ public class AudioDeviceInventory { mNonDefDevDispatchers.getBroadcastItem(i).dispatchNonDefDevicesChanged( strategy, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchNonDefaultDevice ", e); } } mNonDefDevDispatchers.finishBroadcast(); Loading @@ -2895,6 +2896,7 @@ public class AudioDeviceInventory { mDevRoleCapturePresetDispatchers.getBroadcastItem(i).dispatchDevicesRoleChanged( capturePreset, role, devices); } catch (RemoteException e) { Log.e(TAG, "dispatchDevicesRoleForCapturePreset ", e); } } mDevRoleCapturePresetDispatchers.finishBroadcast(); Loading Loading @@ -2960,7 +2962,7 @@ public class AudioDeviceInventory { /** * Check if device is in the list of connected devices * @param device * @param device the device to query * @return true if connected */ @VisibleForTesting Loading