[Audiosharing] add profile service listener when BT just on

If receive BT on while profile service not ready, add profile service
listener and do things, e.g. update preference, when all relative
profile services connected.

Test: atest
Bug: 305620450
Flag: com.android.settingslib.flags.enable_le_audio_sharing
Change-Id: Ie56ed70190285785f1750a7cbbb16029b566fcbe
This commit is contained in:
Yiyi Shen
2025-01-23 15:33:06 +08:00
parent a618a8a241
commit e9b6016b8d
4 changed files with 147 additions and 39 deletions

View File

@@ -136,8 +136,17 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateSwitch();
mListener.onAudioSharingStateChanged();
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
== BluetoothAdapter.STATE_ON
&& !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (mProfileManager != null) {
mProfileManager.addServiceListener(
AudioSharingSwitchBarController.this);
}
} else {
updateSwitch();
mListener.onAudioSharingStateChanged();
}
}
};
@@ -360,14 +369,14 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
}
mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED);
updateSwitch();
registerCallbacks();
if (!AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (mProfileManager != null) {
mProfileManager.addServiceListener(this);
}
Log.d(TAG, "Skip register callbacks. Profile is not ready.");
Log.d(TAG, "Skip handleStartAudioSharingFromIntent. Profile is not ready.");
return;
}
registerCallbacks();
if (mIntentHandleStage.compareAndSet(
StartIntentHandleStage.TO_HANDLE.ordinal(),
StartIntentHandleStage.HANDLE_AUTO_ADD.ordinal())) {
@@ -445,7 +454,6 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
public void onServiceConnected() {
Log.d(TAG, "onServiceConnected()");
if (AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
registerCallbacks();
updateSwitch();
mListener.onAudioSharingProfilesConnected();
mListener.onAudioSharingStateChanged();
@@ -525,7 +533,7 @@ public class AudioSharingSwitchBarController extends BasePreferenceController
}
private void unregisterCallbacks() {
if (!isAvailable() || !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) {
if (!isAvailable()) {
Log.d(TAG, "Skip unregisterCallbacks(). Feature is not available.");
return;
}

View File

@@ -52,7 +52,15 @@ public class StreamSettingsCategoryController extends BasePreferenceController
@Override
public void onReceive(Context context, Intent intent) {
if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) return;
updateVisibility();
if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothAdapter.ERROR)
== BluetoothAdapter.STATE_ON && !isProfileReady()) {
if (mProfileManager != null) {
mProfileManager.addServiceListener(
StreamSettingsCategoryController.this);
}
} else {
updateVisibility();
}
}
};
@@ -97,7 +105,7 @@ public class StreamSettingsCategoryController extends BasePreferenceController
@Override
public void onServiceConnected() {
if (isAvailable() && isProfileReady()) {
if (isProfileReady()) {
updateVisibility();
if (mProfileManager != null) {
mProfileManager.removeServiceListener(this);