diff --git a/res/drawable/ic_audio_calls_and_alarms.xml b/res/drawable/ic_audio_calls_and_alarms.xml
new file mode 100644
index 00000000000..5da27c69ca5
--- /dev/null
+++ b/res/drawable/ic_audio_calls_and_alarms.xml
@@ -0,0 +1,32 @@
+
+
+
+
+
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 193887300f4..aeb2d4af717 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -292,6 +292,8 @@
Audio sharing
Share audio
+
+ Calls and alarms
Date & time
diff --git a/res/xml/bluetooth_audio_sharing.xml b/res/xml/bluetooth_audio_sharing.xml
index a90da727d39..bf7593ac14c 100644
--- a/res/xml/bluetooth_audio_sharing.xml
+++ b/res/xml/bluetooth_audio_sharing.xml
@@ -19,4 +19,10 @@
xmlns:settings="http://schemas.android.com/apk/res-auto"
android:title="@string/audio_sharing_title">
+
\ No newline at end of file
diff --git a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
index 370b69a8ccd..b9ef8f4fe3f 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/AudioSharingDashboardFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.connecteddevice.audiosharing;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.os.Bundle;
@@ -36,8 +37,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment {
@Override
public int getMetricsCategory() {
- // TODO: update category id.
- return 0;
+ return SettingsEnums.AUDIO_SHARING_SETTINGS;
}
@Override
@@ -63,6 +63,7 @@ public class AudioSharingDashboardFragment extends DashboardFragment {
@Override
public void onAttach(Context context) {
super.onAttach(context);
+ use(CallsAndAlarmsPreferenceController.class).init(this);
}
@Override
diff --git a/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsDialogFragment.java b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsDialogFragment.java
new file mode 100644
index 00000000000..0577f70ec5a
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsDialogFragment.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2023 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.app.Dialog;
+import android.app.settings.SettingsEnums;
+import android.os.Bundle;
+
+import androidx.appcompat.app.AlertDialog;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentManager;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.flags.Flags;
+
+/** Provides a dialog to choose the active device for calls and alarms. */
+public class CallsAndAlarmsDialogFragment extends InstrumentedDialogFragment {
+ private static final String TAG = "CallsAndAlarmsDialog";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_AUDIO_SHARING_SWITCH_ACTIVE;
+ }
+
+ /**
+ * Display the {@link CallsAndAlarmsDialogFragment} dialog.
+ *
+ * @param host The Fragment this dialog will be hosted.
+ */
+ public static void show(Fragment host) {
+ if (!Flags.enableLeAudioSharing()) return;
+ final FragmentManager manager = host.getChildFragmentManager();
+ if (manager.findFragmentByTag(TAG) == null) {
+ final CallsAndAlarmsDialogFragment dialog = new CallsAndAlarmsDialogFragment();
+ dialog.show(manager, TAG);
+ }
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // TODO: use real device names
+ String[] choices = {"Buds 1", "Buds 2"};
+ AlertDialog.Builder builder =
+ new AlertDialog.Builder(getActivity())
+ .setTitle(R.string.calls_and_alarms_device_title)
+ .setSingleChoiceItems(
+ choices,
+ 0, // TODO: set to current active device.
+ (dialog, which) -> {
+ // TODO: set device to active device for calls and alarms.
+ });
+ return builder.create();
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java
new file mode 100644
index 00000000000..480b25771a3
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/audiosharing/CallsAndAlarmsPreferenceController.java
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2023 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.content.Context;
+import android.util.Log;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.flags.Flags;
+
+/** PreferenceController to control the dialog to choose the active device for calls and alarms */
+public class CallsAndAlarmsPreferenceController extends BasePreferenceController {
+
+ private static final String TAG = "CallsAndAlarmsPreferenceController";
+
+ private static final String PREF_KEY = "calls_and_alarms";
+
+ private Preference mPreference;
+ private DashboardFragment mFragment;
+
+ public CallsAndAlarmsPreferenceController(Context context) {
+ super(context, PREF_KEY);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return Flags.enableLeAudioSharing() ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return PREF_KEY;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ mPreference.setOnPreferenceClickListener(
+ preference -> {
+ if (mFragment != null) {
+ CallsAndAlarmsDialogFragment.show(mFragment);
+ } else {
+ Log.w(TAG, "Dialog fail to show due to null host.");
+ }
+ return true;
+ });
+ }
+
+ /**
+ * Initialize the controller.
+ *
+ * @param fragment The fragment to host the {@link CallsAndAlarmsDialogFragment} dialog.
+ */
+ public void init(DashboardFragment fragment) {
+ this.mFragment = fragment;
+ }
+}