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:
hughchen
2020-01-08 19:38:40 +08:00
parent d0811849ec
commit c770c9133a
4 changed files with 71 additions and 11 deletions

View File

@@ -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();
}
}