1 /*
2  * Copyright (C) 2010 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.wifi;
18 
19 import android.content.Context;
20 import android.net.wifi.WifiContext;
21 import android.util.Log;
22 
23 import com.android.server.SystemService;
24 
25 /**
26  * Service implementing Wi-Fi functionality. Delegates actual interface
27  * implementation to WifiServiceImpl.
28  */
29 public final class WifiService extends SystemService {
30 
31     private static final String TAG = "WifiService";
32     // Notification channels used by the wifi service.
33     public static final String NOTIFICATION_NETWORK_STATUS = "NETWORK_STATUS";
34     public static final String NOTIFICATION_NETWORK_ALERTS = "NETWORK_ALERTS";
35     public static final String NOTIFICATION_NETWORK_AVAILABLE = "NETWORK_AVAILABLE";
36     public static final String NOTIFICATION_APM_ALERTS = "APM_ALERTS";
37 
38     private final WifiServiceImpl mImpl;
39     private final WifiContext mWifiContext;
40 
WifiService(Context contextBase)41     public WifiService(Context contextBase) {
42         super(contextBase);
43         mWifiContext = new WifiContext(contextBase);
44         WifiInjector injector = new WifiInjector(mWifiContext);
45         mImpl = new WifiServiceImpl(mWifiContext, injector);
46     }
47 
48     @Override
onStart()49     public void onStart() {
50         Log.i(TAG, "Registering " + Context.WIFI_SERVICE);
51         publishBinderService(Context.WIFI_SERVICE, mImpl);
52     }
53 
54     @Override
onBootPhase(int phase)55     public void onBootPhase(int phase) {
56         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
57             mImpl.checkAndStartWifi();
58         } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
59             mImpl.handleBootCompleted();
60         }
61     }
62 
63     @Override
onUserSwitching(TargetUser from, TargetUser to)64     public void onUserSwitching(TargetUser from, TargetUser to) {
65         mImpl.handleUserSwitch(to.getUserHandle().getIdentifier());
66     }
67 
68     @Override
onUserUnlocking(TargetUser user)69     public void onUserUnlocking(TargetUser user) {
70         mImpl.handleUserUnlock(user.getUserHandle().getIdentifier());
71     }
72 
73     @Override
onUserStopping(TargetUser user)74     public void onUserStopping(TargetUser user) {
75         mImpl.handleUserStop(user.getUserHandle().getIdentifier());
76     }
77 }
78