[Audiosharing] Move getSummary
to a bg thread.
Bug: 308368124 Test: Manual Change-Id: I6d521681ce8835e5187c43f6ec930fb119f46674
This commit is contained in:
@@ -25,10 +25,10 @@ import androidx.preference.Preference;
|
|||||||
import androidx.preference.PreferenceScreen;
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.widget.SummaryUpdater;
|
|
||||||
|
|
||||||
public class AudioStreamsActiveDeviceController extends BasePreferenceController
|
public class AudioStreamsActiveDeviceController extends BasePreferenceController
|
||||||
implements SummaryUpdater.OnSummaryChangeListener, DefaultLifecycleObserver {
|
implements AudioStreamsActiveDeviceSummaryUpdater.OnSummaryChangeListener,
|
||||||
|
DefaultLifecycleObserver {
|
||||||
|
|
||||||
public static final String KEY = "audio_streams_active_device";
|
public static final String KEY = "audio_streams_active_device";
|
||||||
private final AudioStreamsActiveDeviceSummaryUpdater mSummaryHelper;
|
private final AudioStreamsActiveDeviceSummaryUpdater mSummaryHelper;
|
||||||
|
@@ -19,28 +19,30 @@ package com.android.settings.connecteddevice.audiosharing.audiostreams;
|
|||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.bluetooth.BluetoothProfile;
|
import android.bluetooth.BluetoothProfile;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.android.settings.bluetooth.Utils;
|
import com.android.settings.bluetooth.Utils;
|
||||||
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
|
||||||
import com.android.settings.widget.SummaryUpdater;
|
|
||||||
import com.android.settingslib.bluetooth.BluetoothCallback;
|
import com.android.settingslib.bluetooth.BluetoothCallback;
|
||||||
import com.android.settingslib.bluetooth.BluetoothUtils;
|
import com.android.settingslib.bluetooth.BluetoothUtils;
|
||||||
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
import com.android.settingslib.bluetooth.CachedBluetoothDevice;
|
||||||
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
import com.android.settingslib.bluetooth.LocalBluetoothManager;
|
||||||
|
import com.android.settingslib.utils.ThreadUtils;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class AudioStreamsActiveDeviceSummaryUpdater extends SummaryUpdater
|
public class AudioStreamsActiveDeviceSummaryUpdater implements BluetoothCallback {
|
||||||
implements BluetoothCallback {
|
private static final String TAG = "AudioStreamsActiveDeviceSummaryUpdater";
|
||||||
private static final String TAG = "AudioStreamsListenWithSummaryUpdater";
|
|
||||||
private static final boolean DEBUG = BluetoothUtils.D;
|
private static final boolean DEBUG = BluetoothUtils.D;
|
||||||
private final LocalBluetoothManager mBluetoothManager;
|
private final LocalBluetoothManager mBluetoothManager;
|
||||||
|
private String mSummary;
|
||||||
|
private OnSummaryChangeListener mListener;
|
||||||
|
|
||||||
public AudioStreamsActiveDeviceSummaryUpdater(
|
public AudioStreamsActiveDeviceSummaryUpdater(
|
||||||
Context context, OnSummaryChangeListener listener) {
|
Context context, OnSummaryChangeListener listener) {
|
||||||
super(context, listener);
|
|
||||||
mBluetoothManager = Utils.getLocalBluetoothManager(context);
|
mBluetoothManager = Utils.getLocalBluetoothManager(context);
|
||||||
|
mListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -59,8 +61,7 @@ public class AudioStreamsActiveDeviceSummaryUpdater extends SummaryUpdater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
void register(boolean register) {
|
||||||
public void register(boolean register) {
|
|
||||||
if (register) {
|
if (register) {
|
||||||
notifyChangeIfNeeded();
|
notifyChangeIfNeeded();
|
||||||
mBluetoothManager.getEventManager().registerCallback(this);
|
mBluetoothManager.getEventManager().registerCallback(this);
|
||||||
@@ -69,8 +70,18 @@ public class AudioStreamsActiveDeviceSummaryUpdater extends SummaryUpdater
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void notifyChangeIfNeeded() {
|
||||||
protected String getSummary() {
|
ThreadUtils.postOnBackgroundThread(
|
||||||
|
() -> {
|
||||||
|
String summary = getSummary();
|
||||||
|
if (!TextUtils.equals(mSummary, summary)) {
|
||||||
|
mSummary = summary;
|
||||||
|
ThreadUtils.postOnMainThread(() -> mListener.onSummaryChanged(summary));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getSummary() {
|
||||||
var activeSink = getActiveSinkOnAssistant(mBluetoothManager);
|
var activeSink = getActiveSinkOnAssistant(mBluetoothManager);
|
||||||
if (activeSink.isEmpty()) {
|
if (activeSink.isEmpty()) {
|
||||||
return "No active LE Audio device";
|
return "No active LE Audio device";
|
||||||
@@ -95,4 +106,14 @@ public class AudioStreamsActiveDeviceSummaryUpdater extends SummaryUpdater
|
|||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Interface definition for a callback to be invoked when the summary has been changed. */
|
||||||
|
interface OnSummaryChangeListener {
|
||||||
|
/**
|
||||||
|
* Called when summary has changed.
|
||||||
|
*
|
||||||
|
* @param summary The new summary.
|
||||||
|
*/
|
||||||
|
void onSummaryChanged(String summary);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user