[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
This commit is contained in:
@@ -38,11 +38,17 @@
|
|||||||
android:title="Play a test sound"
|
android:title="Play a test sound"
|
||||||
settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingPlaySoundPreferenceController" />
|
settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingPlaySoundPreferenceController" />
|
||||||
|
|
||||||
<com.android.settings.connecteddevice.audiosharing.AudioSharingNamePreference
|
<PreferenceCategory
|
||||||
android:key="audio_sharing_stream_name"
|
android:key="audio_sharing_stream_settings_category"
|
||||||
android:summary="********"
|
android:title="Stream settings"
|
||||||
android:title="Stream name"
|
settings:controller="com.android.settings.connecteddevice.audiosharing.StreamSettingsCategoryController">
|
||||||
settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingNamePreferenceController" />
|
|
||||||
|
<com.android.settings.connecteddevice.audiosharing.AudioSharingNamePreference
|
||||||
|
android:key="audio_sharing_stream_name"
|
||||||
|
android:summary="********"
|
||||||
|
android:title="Stream name"
|
||||||
|
settings:controller="com.android.settings.connecteddevice.audiosharing.AudioSharingNamePreferenceController" />
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="audio_streams_settings_category"
|
android:key="audio_streams_settings_category"
|
||||||
|
@@ -35,7 +35,6 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
|||||||
private AudioSharingDeviceVolumeGroupController mAudioSharingDeviceVolumeGroupController;
|
private AudioSharingDeviceVolumeGroupController mAudioSharingDeviceVolumeGroupController;
|
||||||
private CallsAndAlarmsPreferenceController mCallsAndAlarmsPreferenceController;
|
private CallsAndAlarmsPreferenceController mCallsAndAlarmsPreferenceController;
|
||||||
private AudioSharingPlaySoundPreferenceController mAudioSharingPlaySoundPreferenceController;
|
private AudioSharingPlaySoundPreferenceController mAudioSharingPlaySoundPreferenceController;
|
||||||
private AudioSharingNamePreferenceController mAudioSharingNamePreferenceController;
|
|
||||||
private AudioStreamsCategoryController mAudioStreamsCategoryController;
|
private AudioStreamsCategoryController mAudioStreamsCategoryController;
|
||||||
|
|
||||||
public AudioSharingDashboardFragment() {
|
public AudioSharingDashboardFragment() {
|
||||||
@@ -77,7 +76,6 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
|||||||
mCallsAndAlarmsPreferenceController.init(this);
|
mCallsAndAlarmsPreferenceController.init(this);
|
||||||
mAudioSharingPlaySoundPreferenceController =
|
mAudioSharingPlaySoundPreferenceController =
|
||||||
use(AudioSharingPlaySoundPreferenceController.class);
|
use(AudioSharingPlaySoundPreferenceController.class);
|
||||||
mAudioSharingNamePreferenceController = use(AudioSharingNamePreferenceController.class);
|
|
||||||
mAudioStreamsCategoryController = use(AudioStreamsCategoryController.class);
|
mAudioStreamsCategoryController = use(AudioStreamsCategoryController.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +102,6 @@ public class AudioSharingDashboardFragment extends DashboardFragment
|
|||||||
mAudioSharingDeviceVolumeGroupController.updateVisibility();
|
mAudioSharingDeviceVolumeGroupController.updateVisibility();
|
||||||
mCallsAndAlarmsPreferenceController.updateVisibility();
|
mCallsAndAlarmsPreferenceController.updateVisibility();
|
||||||
mAudioSharingPlaySoundPreferenceController.updateVisibility();
|
mAudioSharingPlaySoundPreferenceController.updateVisibility();
|
||||||
mAudioSharingNamePreferenceController.updateVisibility();
|
|
||||||
mAudioStreamsCategoryController.updateVisibility();
|
mAudioStreamsCategoryController.updateVisibility();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,13 +18,12 @@ package com.android.settings.connecteddevice.audiosharing;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.lifecycle.LifecycleOwner;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
import com.android.settings.widget.ValidatedEditTextPreference;
|
import com.android.settings.widget.ValidatedEditTextPreference;
|
||||||
|
|
||||||
public class AudioSharingNamePreferenceController extends AudioSharingBasePreferenceController
|
public class AudioSharingNamePreferenceController extends BasePreferenceController
|
||||||
implements ValidatedEditTextPreference.Validator, Preference.OnPreferenceChangeListener {
|
implements ValidatedEditTextPreference.Validator, Preference.OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String TAG = "AudioSharingNamePreferenceController";
|
private static final String TAG = "AudioSharingNamePreferenceController";
|
||||||
@@ -33,11 +32,16 @@ public class AudioSharingNamePreferenceController extends AudioSharingBasePrefer
|
|||||||
|
|
||||||
private AudioSharingNameTextValidator mAudioSharingNameTextValidator;
|
private AudioSharingNameTextValidator mAudioSharingNameTextValidator;
|
||||||
|
|
||||||
public AudioSharingNamePreferenceController(Context context) {
|
public AudioSharingNamePreferenceController(Context context, String preferenceKey) {
|
||||||
super(context, PREF_KEY);
|
super(context, preferenceKey);
|
||||||
mAudioSharingNameTextValidator = new AudioSharingNameTextValidator();
|
mAudioSharingNameTextValidator = new AudioSharingNameTextValidator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getAvailabilityStatus() {
|
||||||
|
return AudioSharingUtils.isFeatureEnabled() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getPreferenceKey() {
|
public String getPreferenceKey() {
|
||||||
return PREF_KEY;
|
return PREF_KEY;
|
||||||
@@ -53,16 +57,4 @@ public class AudioSharingNamePreferenceController extends AudioSharingBasePrefer
|
|||||||
public boolean isTextValid(String value) {
|
public boolean isTextValid(String value) {
|
||||||
return mAudioSharingNameTextValidator.isTextValid(value);
|
return mAudioSharingNameTextValidator.isTextValid(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart(@NonNull LifecycleOwner owner) {
|
|
||||||
super.onStart(owner);
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop(@NonNull LifecycleOwner owner) {
|
|
||||||
super.onStop(owner);
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,98 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2024 The Android Open Source Project
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package com.android.settings.connecteddevice.audiosharing;
|
||||||
|
|
||||||
|
import android.bluetooth.BluetoothAdapter;
|
||||||
|
import android.bluetooth.BluetoothDevice;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.lifecycle.DefaultLifecycleObserver;
|
||||||
|
import androidx.lifecycle.LifecycleOwner;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceScreen;
|
||||||
|
|
||||||
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
|
||||||
|
public class StreamSettingsCategoryController extends BasePreferenceController
|
||||||
|
implements DefaultLifecycleObserver {
|
||||||
|
private static final String TAG = "StreamSettingsCategoryController";
|
||||||
|
private final BluetoothAdapter mBluetoothAdapter;
|
||||||
|
private final IntentFilter mIntentFilter;
|
||||||
|
private @Nullable Preference mPreference;
|
||||||
|
private BroadcastReceiver mReceiver =
|
||||||
|
new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (!BluetoothAdapter.ACTION_STATE_CHANGED.equals(intent.getAction())) return;
|
||||||
|
int adapterState =
|
||||||
|
intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BluetoothDevice.ERROR);
|
||||||
|
mContext.getMainExecutor()
|
||||||
|
.execute(
|
||||||
|
() -> {
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user