Update output switch UI
This CL include following update: 1. Add onDeviceAttributesChanged() callback to update UI when device attributes are changed. 2. Fix the top device when user press device to transfer. 3. Update UI when device is on goning call state and receive STREAM_DEVICES_CHANGED_ACTION intent. Bug: 144535188 Test: make -j42 RunSettingsRoboTests Change-Id: Idd5fb95054db30f8184faf4f6ab75d0b550907a1
This commit is contained in:
@@ -31,6 +31,7 @@ import android.text.TextUtils;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import com.android.settings.slices.SliceBackgroundWorker;
|
||||
import com.android.settingslib.Utils;
|
||||
import com.android.settingslib.media.LocalMediaManager;
|
||||
import com.android.settingslib.media.MediaDevice;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
@@ -49,6 +50,9 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
private final DevicesChangedBroadcastReceiver mReceiver;
|
||||
private final String mPackageName;
|
||||
|
||||
private boolean mIsTouched;
|
||||
private MediaDevice mTopDevice;
|
||||
|
||||
@VisibleForTesting
|
||||
LocalMediaManager mLocalMediaManager;
|
||||
|
||||
@@ -62,6 +66,7 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
@Override
|
||||
protected void onSlicePinned() {
|
||||
mMediaDevices.clear();
|
||||
mIsTouched = false;
|
||||
if (mLocalMediaManager == null) {
|
||||
mLocalMediaManager = new LocalMediaManager(mContext, mPackageName, null);
|
||||
}
|
||||
@@ -100,6 +105,11 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
notifySliceChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceAttributesChanged() {
|
||||
notifySliceChange();
|
||||
}
|
||||
|
||||
public List<MediaDevice> getMediaDevices() {
|
||||
return new ArrayList<>(mMediaDevices);
|
||||
}
|
||||
@@ -118,11 +128,28 @@ public class MediaDeviceUpdateWorker extends SliceBackgroundWorker
|
||||
return mLocalMediaManager.getCurrentConnectedDevice();
|
||||
}
|
||||
|
||||
void setIsTouched(boolean isTouched) {
|
||||
mIsTouched = isTouched;
|
||||
}
|
||||
|
||||
boolean getIsTouched() {
|
||||
return mIsTouched;
|
||||
}
|
||||
|
||||
void setTopDevice(MediaDevice device) {
|
||||
mTopDevice = device;
|
||||
}
|
||||
|
||||
MediaDevice getTopDevice() {
|
||||
return mTopDevice;
|
||||
}
|
||||
|
||||
private class DevicesChangedBroadcastReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (TextUtils.equals(AudioManager.STREAM_DEVICES_CHANGED_ACTION, action)) {
|
||||
if (TextUtils.equals(AudioManager.STREAM_DEVICES_CHANGED_ACTION, action)
|
||||
&& Utils.isAudioModeOngoingCall(mContext)) {
|
||||
notifySliceChange();
|
||||
}
|
||||
}
|
||||
|
@@ -61,7 +61,7 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void init(String packageName, MediaDeviceUpdateWorker worker) {
|
||||
void init(MediaDeviceUpdateWorker worker) {
|
||||
mWorker = worker;
|
||||
}
|
||||
|
||||
@@ -79,15 +79,20 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
}
|
||||
|
||||
final List<MediaDevice> devices = getMediaDevices();
|
||||
final MediaDeviceUpdateWorker worker = getWorker();
|
||||
final MediaDevice connectedDevice = worker.getCurrentConnectedMediaDevice();
|
||||
final boolean isTouched = worker.getIsTouched();
|
||||
// Fix the last top device when user press device to transfer.
|
||||
final MediaDevice topDevice = isTouched ? worker.getTopDevice() : connectedDevice;
|
||||
|
||||
final MediaDevice connectedDevice = getWorker().getCurrentConnectedMediaDevice();
|
||||
if (connectedDevice != null) {
|
||||
listBuilder.addRow(getActiveDeviceHeaderRow(connectedDevice));
|
||||
if (topDevice != null) {
|
||||
listBuilder.addRow(getActiveDeviceHeaderRow(topDevice));
|
||||
worker.setTopDevice(topDevice);
|
||||
}
|
||||
|
||||
for (MediaDevice device : devices) {
|
||||
if (connectedDevice == null
|
||||
|| !TextUtils.equals(connectedDevice.getId(), device.getId())) {
|
||||
if (topDevice == null
|
||||
|| !TextUtils.equals(topDevice.getId(), device.getId())) {
|
||||
listBuilder.addRow(getMediaDeviceRow(device));
|
||||
}
|
||||
}
|
||||
@@ -173,6 +178,7 @@ public class MediaOutputSlice implements CustomSliceable {
|
||||
final MediaDevice device = worker.getMediaDeviceById(id);
|
||||
if (device != null) {
|
||||
Log.d(TAG, "onNotifyChange() device name : " + device.getName());
|
||||
worker.setIsTouched(true);
|
||||
worker.connectDevice(device);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user