Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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.server; |
| 18 | |
| 19 | import android.bluetooth.BluetoothAdapter; |
| 20 | import android.content.Context; |
Eric Jeong | e7ead1b | 2019-07-18 09:37:08 -0700 | [diff] [blame] | 21 | import android.os.UserManager; |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 22 | |
| 23 | class BluetoothService extends SystemService { |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 24 | private BluetoothManagerService mBluetoothManagerService; |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 25 | private boolean mInitialized = false; |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 26 | |
| 27 | public BluetoothService(Context context) { |
| 28 | super(context); |
| 29 | mBluetoothManagerService = new BluetoothManagerService(context); |
| 30 | } |
| 31 | |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 32 | private void initialize() { |
| 33 | if (!mInitialized) { |
| 34 | mBluetoothManagerService.handleOnBootPhase(); |
| 35 | mInitialized = true; |
| 36 | } |
| 37 | } |
| 38 | |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 39 | @Override |
| 40 | public void onStart() { |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public void onBootPhase(int phase) { |
| 45 | if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { |
Jeff Sharkey | aacb89e | 2016-03-05 14:42:58 -0700 | [diff] [blame] | 46 | publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, |
| 47 | mBluetoothManagerService); |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 48 | } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY && |
Eric Jeong | e7ead1b | 2019-07-18 09:37:08 -0700 | [diff] [blame] | 49 | !UserManager.isHeadlessSystemUserMode()) { |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 50 | initialize(); |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onSwitchUser(int userHandle) { |
Ram Periathiruvadi | 2097d6a | 2019-07-31 15:47:47 -0700 | [diff] [blame] | 56 | if (!mInitialized) { |
| 57 | initialize(); |
| 58 | } else { |
| 59 | mBluetoothManagerService.handleOnSwitchUser(userHandle); |
| 60 | } |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 61 | } |
Jeff Sharkey | aacb89e | 2016-03-05 14:42:58 -0700 | [diff] [blame] | 62 | |
| 63 | @Override |
| 64 | public void onUnlockUser(int userHandle) { |
| 65 | mBluetoothManagerService.handleOnUnlockUser(userHandle); |
| 66 | } |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 67 | } |