1 /* 2 * Copyright (C) 2025 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; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.util.Log; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.annotation.VisibleForTesting; 26 27 import com.android.settings.R; 28 import com.android.settings.dashboard.DashboardFragment; 29 import com.android.settingslib.utils.ThreadUtils; 30 31 public class AudioSharingJoinHandlerDashboardFragment extends DashboardFragment { 32 private static final String TAG = "AudioSharingJoinHandlerFrag"; 33 34 @Nullable private AudioSharingJoinHandlerController mController; 35 36 @Override getMetricsCategory()37 public int getMetricsCategory() { 38 // TODO: use real enum 39 return 0; 40 } 41 42 @Override getPreferenceScreenResId()43 protected int getPreferenceScreenResId() { 44 return R.xml.bluetooth_le_audio_sharing_join_handler; 45 } 46 47 @Override getLogTag()48 protected String getLogTag() { 49 return TAG; 50 } 51 52 @Override onAttach(Context context)53 public void onAttach(Context context) { 54 super.onAttach(context); 55 mController = use(AudioSharingJoinHandlerController.class); 56 if (mController != null) { 57 Log.d(TAG, "onAttach, init controller"); 58 mController.init(this); 59 } 60 } 61 62 /** Handle just connected device via intent. */ handleDeviceConnectedFromIntent(@onNull Intent intent)63 public void handleDeviceConnectedFromIntent(@NonNull Intent intent) { 64 var unused = 65 ThreadUtils.postOnBackgroundThread( 66 () -> { 67 if (mController != null) { 68 Log.d(TAG, "handleDeviceConnectedFromIntent"); 69 mController.handleDeviceConnectedFromIntent(intent); 70 } 71 }); 72 } 73 74 /** Test only: set mock controllers for the {@link AudioSharingJoinHandlerDashboardFragment} */ 75 @VisibleForTesting setController(AudioSharingJoinHandlerController controller)76 void setController(AudioSharingJoinHandlerController controller) { 77 mController = controller; 78 } 79 } 80