Home | History | Annotate | Download | only in aware
      1 /*
      2  * Copyright (C) 2016 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.aware;
     18 
     19 import android.content.Context;
     20 import android.os.HandlerThread;
     21 import android.util.Log;
     22 
     23 import com.android.server.SystemService;
     24 import com.android.server.wifi.HalDeviceManager;
     25 import com.android.server.wifi.WifiInjector;
     26 
     27 /**
     28  * Service implementing Wi-Fi Aware functionality. Delegates actual interface
     29  * implementation to WifiAwareServiceImpl.
     30  */
     31 public final class WifiAwareService extends SystemService {
     32     private static final String TAG = "WifiAwareService";
     33     final WifiAwareServiceImpl mImpl;
     34 
     35     public WifiAwareService(Context context) {
     36         super(context);
     37         mImpl = new WifiAwareServiceImpl(context);
     38     }
     39 
     40     @Override
     41     public void onStart() {
     42         Log.i(TAG, "Registering " + Context.WIFI_AWARE_SERVICE);
     43         publishBinderService(Context.WIFI_AWARE_SERVICE, mImpl);
     44     }
     45 
     46     @Override
     47     public void onBootPhase(int phase) {
     48         if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) {
     49             WifiInjector wifiInjector = WifiInjector.getInstance();
     50             if (wifiInjector == null) {
     51                 Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!");
     52                 return;
     53             }
     54 
     55             HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager();
     56             halDeviceManager.initialize();
     57 
     58             WifiAwareStateManager wifiAwareStateManager = new WifiAwareStateManager();
     59             WifiAwareNativeCallback wifiAwareNativeCallback = new WifiAwareNativeCallback(
     60                     wifiAwareStateManager);
     61             WifiAwareNativeManager wifiAwareNativeManager = new WifiAwareNativeManager(
     62                     wifiAwareStateManager, halDeviceManager, wifiAwareNativeCallback);
     63             WifiAwareNativeApi wifiAwareNativeApi = new WifiAwareNativeApi(wifiAwareNativeManager);
     64             wifiAwareStateManager.setNative(wifiAwareNativeApi);
     65 
     66             HandlerThread awareHandlerThread = wifiInjector.getWifiAwareHandlerThread();
     67             mImpl.start(awareHandlerThread, wifiAwareStateManager);
     68         } else if (phase == SystemService.PHASE_BOOT_COMPLETED) {
     69             mImpl.startLate();
     70         }
     71     }
     72 }
     73 
     74