• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.bluetooth;
18 
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.bluetooth.BluetoothAdapter;
22 import android.content.Context;
23 import android.os.UserManager;
24 
25 import com.android.server.SystemService;
26 import com.android.server.SystemService.TargetUser;
27 
28 public class BluetoothService extends SystemService {
29     private BluetoothManagerService mBluetoothManagerService;
30     private boolean mInitialized = false;
31 
BluetoothService(Context context)32     public BluetoothService(Context context) {
33         super(context);
34         mBluetoothManagerService = new BluetoothManagerService(context);
35     }
36 
initialize()37     private void initialize() {
38         if (!mInitialized) {
39             mBluetoothManagerService.handleOnBootPhase();
40             mInitialized = true;
41         }
42     }
43 
44     @Override
onStart()45     public void onStart() {
46     }
47 
48     @Override
onBootPhase(int phase)49     public void onBootPhase(int phase) {
50         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
51             publishBinderService(BluetoothAdapter.BLUETOOTH_MANAGER_SERVICE,
52                     mBluetoothManagerService);
53         }
54     }
55 
56     @Override
onUserStarting(@onNull TargetUser user)57     public void onUserStarting(@NonNull TargetUser user) {
58         if (!UserManager.isHeadlessSystemUserMode()) {
59             initialize();
60         }
61     }
62 
63     @Override
onUserSwitching(@ullable TargetUser from, @NonNull TargetUser to)64     public void onUserSwitching(@Nullable TargetUser from, @NonNull TargetUser to) {
65         if (!mInitialized) {
66             initialize();
67         } else {
68             mBluetoothManagerService.handleOnSwitchUser(to.getUserHandle());
69         }
70     }
71 
72     @Override
onUserUnlocking(@onNull TargetUser user)73     public void onUserUnlocking(@NonNull TargetUser user) {
74         mBluetoothManagerService.handleOnUnlockUser(user.getUserHandle());
75     }
76 }
77