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; |
Ying Zheng | 9403bde | 2019-04-10 16:34:54 -0700 | [diff] [blame] | 21 | |
| 22 | import com.android.internal.os.RoSystemProperties; |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 23 | |
| 24 | class BluetoothService extends SystemService { |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 25 | private BluetoothManagerService mBluetoothManagerService; |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 26 | private boolean mInitialized = false; |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 27 | |
| 28 | public BluetoothService(Context context) { |
| 29 | super(context); |
| 30 | mBluetoothManagerService = new BluetoothManagerService(context); |
| 31 | } |
| 32 | |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 33 | private void initialize() { |
| 34 | if (!mInitialized) { |
| 35 | mBluetoothManagerService.handleOnBootPhase(); |
| 36 | mInitialized = true; |
| 37 | } |
| 38 | } |
| 39 | |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 40 | @Override |
| 41 | public void onStart() { |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public void onBootPhase(int phase) { |
| 46 | if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { |
Jeff Sharkey | aacb89e | 2016-03-05 14:42:58 -0700 | [diff] [blame] | 47 | publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE, |
| 48 | mBluetoothManagerService); |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 49 | } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY && |
Ying Zheng | 9403bde | 2019-04-10 16:34:54 -0700 | [diff] [blame] | 50 | !RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER) { |
Joseph Pirozzo | 60cae8d | 2018-11-12 13:37:06 -0800 | [diff] [blame] | 51 | initialize(); |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public void onSwitchUser(int userHandle) { |
Ram Periathiruvadi | 344555b | 2019-07-31 15:47:47 -0700 | [diff] [blame] | 57 | if (!mInitialized) { |
| 58 | initialize(); |
| 59 | } else { |
| 60 | mBluetoothManagerService.handleOnSwitchUser(userHandle); |
| 61 | } |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 62 | } |
Jeff Sharkey | aacb89e | 2016-03-05 14:42:58 -0700 | [diff] [blame] | 63 | |
| 64 | @Override |
| 65 | public void onUnlockUser(int userHandle) { |
| 66 | mBluetoothManagerService.handleOnUnlockUser(userHandle); |
| 67 | } |
Miao Chou | 658bf2f | 2015-06-26 17:14:35 -0700 | [diff] [blame] | 68 | } |