[Audiosharing] Impl pwd dialog and detail page
Bug: 305620450
Test: manual
Change-Id: I2686aee4c3809c5f683a42b6440a5fd361e7be0b
diff --git a/res/xml/audio_stream_details_fragment.xml b/res/xml/audio_stream_details_fragment.xml
new file mode 100644
index 0000000..9727442
--- /dev/null
+++ b/res/xml/audio_stream_details_fragment.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ ~ 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.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:title="Audio stream details">
+
+ <com.android.settingslib.widget.LayoutPreference
+ android:key="audio_stream_header"
+ android:layout="@layout/settings_entity_header"
+ android:selectable="false"
+ settings:allowDividerBelow="true"
+ settings:searchable="false" />
+
+ <com.android.settingslib.widget.ActionButtonsPreference
+ android:key="audio_stream_button"
+ settings:allowDividerBelow="true" />
+
+</PreferenceScreen>
diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamDetailsFragment.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamDetailsFragment.java
new file mode 100644
index 0000000..1e69829
--- /dev/null
+++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamDetailsFragment.java
@@ -0,0 +1,47 @@
+/*
+ * 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.audiostreams;
+
+import android.content.Context;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+
+public class AudioStreamDetailsFragment extends DashboardFragment {
+ private static final String TAG = "AudioStreamDetailsFragment";
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ // TODO(chelseahao): update metrics id
+ return 0;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.audio_stream_details_fragment;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+}
diff --git a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsProgressCategoryController.java b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsProgressCategoryController.java
index 6cf69c5..45f0c2f 100644
--- a/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsProgressCategoryController.java
+++ b/src/com/android/settings/connecteddevice/audiosharing/audiostreams/AudioStreamsProgressCategoryController.java
@@ -18,10 +18,18 @@
import static java.util.Collections.emptyList;
+import android.app.AlertDialog;
+import android.app.settings.SettingsEnums;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.content.Context;
+import android.os.Bundle;
+import android.provider.Settings;
import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
@@ -29,13 +37,16 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.bluetooth.Utils;
import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.bluetooth.BluetoothUtils;
import com.android.settingslib.bluetooth.LocalBluetoothLeBroadcastAssistant;
import com.android.settingslib.utils.ThreadUtils;
+import java.nio.charset.StandardCharsets;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
@@ -198,11 +209,48 @@
}
private boolean launchDetailFragment(AudioStreamPreference preference) {
- // TODO(chelseahao): impl
+ Bundle broadcast = new Bundle();
+ broadcast.putString(
+ Settings.Secure.BLUETOOTH_LE_BROADCAST_PROGRAM_INFO,
+ (String) preference.getTitle());
+
+ new SubSettingLauncher(mContext)
+ .setTitleText("Audio stream details")
+ .setDestination(AudioStreamDetailsFragment.class.getName())
+ // TODO(chelseahao): Add logging enum
+ .setSourceMetricsCategory(SettingsEnums.PAGE_UNKNOWN)
+ .setArguments(broadcast)
+ .launch();
return true;
}
private void launchPasswordDialog(BluetoothLeBroadcastMetadata source, Preference preference) {
- // TODO(chelseahao): impl
+ View layout =
+ LayoutInflater.from(mContext)
+ .inflate(R.layout.bluetooth_find_broadcast_password_dialog, null);
+ ((TextView) layout.requireViewById(R.id.broadcast_name_text))
+ .setText(preference.getTitle());
+ AlertDialog alertDialog =
+ new AlertDialog.Builder(mContext)
+ .setTitle(R.string.find_broadcast_password_dialog_title)
+ .setView(layout)
+ .setNeutralButton(android.R.string.cancel, null)
+ .setPositiveButton(
+ R.string.bluetooth_connect_access_dialog_positive,
+ (dialog, which) -> {
+ var code =
+ ((EditText)
+ layout.requireViewById(
+ R.id.broadcast_edit_text))
+ .getText()
+ .toString();
+ mAudioStreamsHelper.addSource(
+ new BluetoothLeBroadcastMetadata.Builder(source)
+ .setBroadcastCode(
+ code.getBytes(StandardCharsets.UTF_8))
+ .build());
+ })
+ .create();
+ alertDialog.show();
}
}