From 162533362a84a7c9a679bc1e9b22d0e6ea60bd0a Mon Sep 17 00:00:00 2001 From: Yiyi Shen Date: Mon, 15 Jan 2024 17:58:55 +0800 Subject: [PATCH] [Audiosharing] Always show broadcast name when BT is on. Also group the broadcast name to Stream settings category. Test: manual Bug: 305620450 Change-Id: I12bba9d5199d6770f86dad1089b47c3767285573 --- res/xml/bluetooth_audio_sharing.xml | 16 ++- .../AudioSharingDashboardFragment.java | 3 - .../AudioSharingNamePreferenceController.java | 26 ++--- .../StreamSettingsCategoryController.java | 98 +++++++++++++++++++ 4 files changed, 118 insertions(+), 25 deletions(-) create mode 100644 src/com/android/settings/connecteddevice/audiosharing/StreamSettingsCategoryController.java diff --git a/res/xml/bluetooth_audio_sharing.xml b/res/xml/bluetooth_audio_sharing.xml index 9ffa2b27798..dc577f6af9d 100644 --- a/res/xml/bluetooth_audio_sharing.xml +++ b/res/xml/bluetooth_audio_sharing.xml @@ -38,11 +38,17 @@ android:title="Play a test sound" settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingPlaySoundPreferenceController" /> - + + + + { + if (mPreference == null) { + Log.w( + TAG, + "Skip BT state change due to mPreference " + + "is null"); + } else { + mPreference.setVisible( + adapterState == BluetoothAdapter.STATE_ON); + } + }); + } + }; + + public StreamSettingsCategoryController(Context context, String key) { + super(context, key); + mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); + mIntentFilter = new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED); + } + + @Override + public void onStart(@NonNull LifecycleOwner owner) { + mContext.registerReceiver(mReceiver, mIntentFilter, Context.RECEIVER_EXPORTED_UNAUDITED); + } + + @Override + public void onStop(@NonNull LifecycleOwner owner) { + mContext.unregisterReceiver(mReceiver); + } + + @Override + public void displayPreference(PreferenceScreen screen) { + super.displayPreference(screen); + mPreference = screen.findPreference(getPreferenceKey()); + if (mPreference != null) { + mPreference.setVisible(isBluetoothStateOn()); + } + } + + @Override + public int getAvailabilityStatus() { + return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE; + } + + private boolean isBluetoothStateOn() { + return mBluetoothAdapter != null && mBluetoothAdapter.isEnabled(); + } +}