summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/audio/AudioDeviceBroker.java55
-rw-r--r--services/core/java/com/android/server/audio/AudioDeviceInventory.java28
2 files changed, 42 insertions, 41 deletions
diff --git a/services/core/java/com/android/server/audio/AudioDeviceBroker.java b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
index d2c845dfcac8..09d1434b8547 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceBroker.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceBroker.java
@@ -262,7 +262,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);
@@ -283,7 +283,7 @@ public class AudioDeviceBroker {
/**
* Turns speakerphone on/off
- * @param on
+ * @param on true to enable speakerphone
* @param eventSource for logging purposes
*/
/*package*/ void setSpeakerphoneOn(
@@ -297,21 +297,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) {
@@ -342,7 +342,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) {
@@ -729,15 +728,6 @@ public class AudioDeviceBroker {
}
/**
- * 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.
*/
@@ -924,6 +914,12 @@ public class AudioDeviceBroker {
}
@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()
+ " state=" + mState
@@ -980,7 +976,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
@@ -1369,6 +1365,7 @@ public class AudioDeviceBroker {
mCommDevDispatchers.getBroadcastItem(i)
.dispatchCommunicationDeviceChanged(portId);
} catch (RemoteException e) {
+ Log.e(TAG, "dispatchCommunicationDevice error", e);
}
}
mCommDevDispatchers.finishBroadcast();
@@ -1572,6 +1569,12 @@ public class AudioDeviceBroker {
}
@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()
+ " mUid=" + mUid
@@ -1591,9 +1594,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(
@@ -2192,10 +2195,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);
}
diff --git a/services/core/java/com/android/server/audio/AudioDeviceInventory.java b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
index f8ee264b54b3..8d590148cab5 100644
--- a/services/core/java/com/android/server/audio/AudioDeviceInventory.java
+++ b/services/core/java/com/android/server/audio/AudioDeviceInventory.java
@@ -444,7 +444,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;
}
@@ -452,7 +452,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;
}
@@ -461,7 +461,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;
}
@@ -470,7 +470,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;
}
@@ -484,7 +484,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
@@ -657,7 +657,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;
@@ -1021,7 +1021,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();
@@ -1802,7 +1804,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?
@@ -2664,10 +2667,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) {
@@ -2830,6 +2829,7 @@ public class AudioDeviceInventory {
mPrefDevDispatchers.getBroadcastItem(i).dispatchPrefDevicesChanged(
strategy, devices);
} catch (RemoteException e) {
+ Log.e(TAG, "dispatchPreferredDevice ", e);
}
}
mPrefDevDispatchers.finishBroadcast();
@@ -2846,6 +2846,7 @@ public class AudioDeviceInventory {
mNonDefDevDispatchers.getBroadcastItem(i).dispatchNonDefDevicesChanged(
strategy, devices);
} catch (RemoteException e) {
+ Log.e(TAG, "dispatchNonDefaultDevice ", e);
}
}
mNonDefDevDispatchers.finishBroadcast();
@@ -2862,6 +2863,7 @@ public class AudioDeviceInventory {
mDevRoleCapturePresetDispatchers.getBroadcastItem(i).dispatchDevicesRoleChanged(
capturePreset, role, devices);
} catch (RemoteException e) {
+ Log.e(TAG, "dispatchDevicesRoleForCapturePreset ", e);
}
}
mDevRoleCapturePresetDispatchers.finishBroadcast();
@@ -2927,7 +2929,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