1 /* 2 * Copyright (C) 2017 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.rtt; 18 19 import android.content.Context; 20 import android.net.wifi.aware.IWifiAwareManager; 21 import android.os.HandlerThread; 22 import android.os.ServiceManager; 23 import android.util.Log; 24 25 import com.android.server.SystemService; 26 import com.android.server.wifi.HalDeviceManager; 27 import com.android.server.wifi.WifiInjector; 28 import com.android.server.wifi.util.WifiPermissionsUtil; 29 30 /** 31 * TBD. 32 */ 33 public class RttService extends SystemService { 34 private static final String TAG = "RttService"; 35 private Context mContext; 36 private RttServiceImpl mImpl; 37 38 public RttService(Context context) { 39 super(context); 40 mContext = context; 41 mImpl = new RttServiceImpl(context); 42 } 43 44 @Override 45 public void onStart() { 46 Log.i(TAG, "Registering " + Context.WIFI_RTT_RANGING_SERVICE); 47 publishBinderService(Context.WIFI_RTT_RANGING_SERVICE, mImpl); 48 } 49 50 @Override 51 public void onBootPhase(int phase) { 52 if (phase == SystemService.PHASE_SYSTEM_SERVICES_READY) { 53 Log.i(TAG, "Starting " + Context.WIFI_RTT_RANGING_SERVICE); 54 55 WifiInjector wifiInjector = WifiInjector.getInstance(); 56 if (wifiInjector == null) { 57 Log.e(TAG, "onBootPhase(PHASE_SYSTEM_SERVICES_READY): NULL injector!"); 58 return; 59 } 60 61 HalDeviceManager halDeviceManager = wifiInjector.getHalDeviceManager(); 62 HandlerThread handlerThread = wifiInjector.getRttHandlerThread(); 63 WifiPermissionsUtil wifiPermissionsUtil = wifiInjector.getWifiPermissionsUtil(); 64 RttMetrics rttMetrics = wifiInjector.getWifiMetrics().getRttMetrics(); 65 66 IWifiAwareManager awareBinder = (IWifiAwareManager) ServiceManager.getService( 67 Context.WIFI_AWARE_SERVICE); 68 69 RttNative rttNative = new RttNative(mImpl, halDeviceManager); 70 mImpl.start(handlerThread.getLooper(), wifiInjector.getClock(), awareBinder, rttNative, 71 rttMetrics, wifiPermissionsUtil, wifiInjector.getFrameworkFacade()); 72 } 73 } 74 } 75