1 /* 2 * Copyright (C) 2023 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 package com.android.server.bluetooth 17 18 import android.bluetooth.BluetoothAdapter 19 import android.content.Context 20 import android.os.UserManager 21 import com.android.server.SystemService 22 import com.android.server.SystemService.TargetUser 23 24 class BluetoothService(context: Context) : SystemService(context) { 25 private val mBluetoothManagerService = BluetoothManagerService(context) 26 private var mInitialized = false 27 initializenull28 private fun initialize() { 29 if (!mInitialized) { 30 mBluetoothManagerService.handleOnBootPhase() 31 mInitialized = true 32 } 33 } 34 onStartnull35 override fun onStart() {} 36 onBootPhasenull37 override fun onBootPhase(phase: Int) { 38 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { 39 publishBinderService( 40 BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, 41 mBluetoothManagerService 42 ) 43 } 44 } 45 onUserStartingnull46 override fun onUserStarting(user: TargetUser) { 47 if (!UserManager.isHeadlessSystemUserMode()) { 48 initialize() 49 } 50 } 51 onUserSwitchingnull52 override fun onUserSwitching(from: TargetUser?, to: TargetUser) { 53 if (!mInitialized) { 54 initialize() 55 } else { 56 mBluetoothManagerService.onSwitchUser(to.userHandle) 57 } 58 } 59 onUserUnlockingnull60 override fun onUserUnlocking(user: TargetUser) { 61 mBluetoothManagerService.handleOnUnlockUser(user.userHandle) 62 } 63 } 64