blob: 0bcd9373c6606966ba9cec3870b6ec68d30caf16 [file] [log] [blame]
Miao Chou658bf2f2015-06-26 17:14:35 -07001/*
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
17package com.android.server;
18
19import android.bluetooth.BluetoothAdapter;
20import android.content.Context;
Eric Jeonge7ead1b2019-07-18 09:37:08 -070021import android.os.UserManager;
Miao Chou658bf2f2015-06-26 17:14:35 -070022
23class BluetoothService extends SystemService {
Miao Chou658bf2f2015-06-26 17:14:35 -070024 private BluetoothManagerService mBluetoothManagerService;
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080025 private boolean mInitialized = false;
Miao Chou658bf2f2015-06-26 17:14:35 -070026
27 public BluetoothService(Context context) {
28 super(context);
29 mBluetoothManagerService = new BluetoothManagerService(context);
30 }
31
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080032 private void initialize() {
33 if (!mInitialized) {
34 mBluetoothManagerService.handleOnBootPhase();
35 mInitialized = true;
36 }
37 }
38
Miao Chou658bf2f2015-06-26 17:14:35 -070039 @Override
40 public void onStart() {
Miao Chou658bf2f2015-06-26 17:14:35 -070041 }
42
43 @Override
44 public void onBootPhase(int phase) {
45 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
Jeff Sharkeyaacb89e2016-03-05 14:42:58 -070046 publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,
47 mBluetoothManagerService);
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080048 } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY &&
Eric Jeonge7ead1b2019-07-18 09:37:08 -070049 !UserManager.isHeadlessSystemUserMode()) {
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080050 initialize();
Miao Chou658bf2f2015-06-26 17:14:35 -070051 }
52 }
53
54 @Override
55 public void onSwitchUser(int userHandle) {
Ram Periathiruvadi2097d6a2019-07-31 15:47:47 -070056 if (!mInitialized) {
57 initialize();
58 } else {
59 mBluetoothManagerService.handleOnSwitchUser(userHandle);
60 }
Miao Chou658bf2f2015-06-26 17:14:35 -070061 }
Jeff Sharkeyaacb89e2016-03-05 14:42:58 -070062
63 @Override
64 public void onUnlockUser(int userHandle) {
65 mBluetoothManagerService.handleOnUnlockUser(userHandle);
66 }
Miao Chou658bf2f2015-06-26 17:14:35 -070067}