1 /*
2  * Copyright (C) 2008 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.scanner;
18 
19 import android.content.Context;
20 import android.net.wifi.WifiContext;
21 import android.os.BatteryStatsManager;
22 import android.os.HandlerThread;
23 import android.util.Log;
24 
25 import com.android.server.SystemService;
26 import com.android.server.wifi.WifiInjector;
27 
28 /**
29  * Service implementing Wi-Fi scanning functionality. Delegates actual interface
30  * implementation to WifiScanningServiceImpl.
31  */
32 public class WifiScanningService extends SystemService {
33 
34     static final String TAG = "WifiScanningService";
35     private final WifiScanningServiceImpl mImpl;
36     private final HandlerThread mHandlerThread;
37 
WifiScanningService(Context contextBase)38     public WifiScanningService(Context contextBase) {
39         super(new WifiContext(contextBase));
40         Log.i(TAG, "Creating " + Context.WIFI_SCANNING_SERVICE);
41         mHandlerThread = new HandlerThread("WifiScanningService");
42         mHandlerThread.start();
43         mImpl = new WifiScanningServiceImpl(getContext(), mHandlerThread.getLooper(),
44                 WifiScannerImpl.DEFAULT_FACTORY,
45                 getContext().getSystemService(BatteryStatsManager.class),
46                 WifiInjector.getInstance());
47     }
48 
49     @Override
onStart()50     public void onStart() {
51         Log.i(TAG, "Publishing " + Context.WIFI_SCANNING_SERVICE);
52         publishBinderService(Context.WIFI_SCANNING_SERVICE, mImpl);
53     }
54 
55     @Override
onBootPhase(int phase)56     public void onBootPhase(int phase) {
57         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
58             Log.i(TAG, "Starting " + Context.WIFI_SCANNING_SERVICE);
59             mImpl.startService();
60         }
61     }
62 }
63