blob: 6a6ddc84be494b578f8ac2650e9ab6fa36bc5d59 [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;
Ying Zheng9403bde2019-04-10 16:34:54 -070021
22import com.android.internal.os.RoSystemProperties;
Miao Chou658bf2f2015-06-26 17:14:35 -070023
24class BluetoothService extends SystemService {
Miao Chou658bf2f2015-06-26 17:14:35 -070025 private BluetoothManagerService mBluetoothManagerService;
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080026 private boolean mInitialized = false;
Miao Chou658bf2f2015-06-26 17:14:35 -070027
28 public BluetoothService(Context context) {
29 super(context);
30 mBluetoothManagerService = new BluetoothManagerService(context);
31 }
32
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080033 private void initialize() {
34 if (!mInitialized) {
35 mBluetoothManagerService.handleOnBootPhase();
36 mInitialized = true;
37 }
38 }
39
Miao Chou658bf2f2015-06-26 17:14:35 -070040 @Override
41 public void onStart() {
Miao Chou658bf2f2015-06-26 17:14:35 -070042 }
43
44 @Override
45 public void onBootPhase(int phase) {
46 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
Jeff Sharkeyaacb89e2016-03-05 14:42:58 -070047 publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,
48 mBluetoothManagerService);
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080049 } else if (phase == SystemService.PHASE_ACTIVITY_MANAGER_READY &&
Ying Zheng9403bde2019-04-10 16:34:54 -070050 !RoSystemProperties.MULTIUSER_HEADLESS_SYSTEM_USER) {
Joseph Pirozzo60cae8d2018-11-12 13:37:06 -080051 initialize();
Miao Chou658bf2f2015-06-26 17:14:35 -070052 }
53 }
54
55 @Override
56 public void onSwitchUser(int userHandle) {
Ram Periathiruvadi344555b2019-07-31 15:47:47 -070057 if (!mInitialized) {
58 initialize();
59 } else {
60 mBluetoothManagerService.handleOnSwitchUser(userHandle);
61 }
Miao Chou658bf2f2015-06-26 17:14:35 -070062 }
Jeff Sharkeyaacb89e2016-03-05 14:42:58 -070063
64 @Override
65 public void onUnlockUser(int userHandle) {
66 mBluetoothManagerService.handleOnUnlockUser(userHandle);
67 }
Miao Chou658bf2f2015-06-26 17:14:35 -070068}