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 37 private final WifiServiceImpl mImpl; 38 private final WifiContext mWifiContext; 39 WifiService(Context contextBase)40 public WifiService(Context contextBase) { 41 super(contextBase); 42 mWifiContext = new WifiContext(contextBase); 43 WifiInjector injector = new WifiInjector(mWifiContext); 44 mImpl = new WifiServiceImpl(mWifiContext, injector); 45 } 46 47 @Override onStart()48 public void onStart() { 49 Log.i(TAG, "Registering " + Context.WIFI_SERVICE); 50 publishBinderService(Context.WIFI_SERVICE, mImpl); 51 } 52 53 @Override onBootPhase(int phase)54 public void onBootPhase(int phase) { 55 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { 56 mImpl.checkAndStartWifi(); 57 } else if (phase == SystemService.PHASE_BOOT_COMPLETED) { 58 mImpl.handleBootCompleted(); 59 } 60 } 61 62 @Override onUserSwitching(TargetUser from, TargetUser to)63 public void onUserSwitching(TargetUser from, TargetUser to) { 64 mImpl.handleUserSwitch(to.getUserHandle().getIdentifier()); 65 } 66 67 @Override onUserUnlocking(TargetUser user)68 public void onUserUnlocking(TargetUser user) { 69 mImpl.handleUserUnlock(user.getUserHandle().getIdentifier()); 70 } 71 72 @Override onUserStopping(TargetUser user)73 public void onUserStopping(TargetUser user) { 74 mImpl.handleUserStop(user.getUserHandle().getIdentifier()); 75 } 76 } 77