1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.connecteddevice.audiosharing.audiostreams; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 import android.util.Log; 22 23 import androidx.annotation.Nullable; 24 25 import com.android.settings.SettingsActivity; 26 import com.android.settings.bluetooth.Utils; 27 import com.android.settings.connecteddevice.audiosharing.AudioSharingUtils; 28 import com.android.settingslib.bluetooth.LocalBluetoothProfileManager; 29 30 public class AudioStreamConfirmDialogActivity extends SettingsActivity 31 implements LocalBluetoothProfileManager.ServiceListener { 32 private static final String TAG = "AudioStreamConfirmDialogActivity"; 33 @Nullable private LocalBluetoothProfileManager mProfileManager; 34 @Nullable private Bundle mSavedState; 35 @Nullable private Intent mIntent; 36 37 @Override isToolbarEnabled()38 protected boolean isToolbarEnabled() { 39 return false; 40 } 41 42 @Override onCreate(Bundle savedState)43 protected void onCreate(Bundle savedState) { 44 var localBluetoothManager = Utils.getLocalBluetoothManager(this); 45 mProfileManager = 46 localBluetoothManager == null ? null : localBluetoothManager.getProfileManager(); 47 super.onCreate(savedState); 48 } 49 50 @Override createUiFromIntent(@ullable Bundle savedState, Intent intent)51 protected void createUiFromIntent(@Nullable Bundle savedState, Intent intent) { 52 if (AudioSharingUtils.isFeatureEnabled() 53 && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { 54 Log.d(TAG, "createUiFromIntent() : supported but not ready, skip createUiFromIntent"); 55 mSavedState = savedState; 56 mIntent = intent; 57 return; 58 } 59 60 Log.d( 61 TAG, 62 "createUiFromIntent() : not supported or already connected, starting" 63 + " createUiFromIntent"); 64 super.createUiFromIntent(savedState, intent); 65 } 66 67 @Override onStart()68 public void onStart() { 69 if (AudioSharingUtils.isFeatureEnabled() 70 && !AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { 71 Log.d(TAG, "onStart() : supported but not ready, listen to service ready"); 72 if (mProfileManager != null) { 73 mProfileManager.addServiceListener(this); 74 } 75 } 76 super.onStart(); 77 } 78 79 @Override onStop()80 public void onStop() { 81 if (mProfileManager != null) { 82 mProfileManager.removeServiceListener(this); 83 } 84 super.onStop(); 85 } 86 87 @Override onServiceConnected()88 public void onServiceConnected() { 89 if (AudioSharingUtils.isFeatureEnabled() 90 && AudioSharingUtils.isAudioSharingProfileReady(mProfileManager)) { 91 if (mProfileManager != null) { 92 mProfileManager.removeServiceListener(this); 93 } 94 if (mIntent != null) { 95 Log.d(TAG, "onServiceConnected() : service ready, starting createUiFromIntent"); 96 super.createUiFromIntent(mSavedState, mIntent); 97 } 98 } 99 } 100 101 @Override onServiceDisconnected()102 public void onServiceDisconnected() {} 103 104 @Override isValidFragment(String fragmentName)105 protected boolean isValidFragment(String fragmentName) { 106 return AudioStreamConfirmDialog.class.getName().equals(fragmentName); 107 } 108 } 109