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; 18 19 import android.content.Context; 20 import android.content.Intent; 21 import android.net.wifi.WifiManager; 22 import android.os.UserHandle; 23 import android.util.Log; 24 25 import java.io.FileDescriptor; 26 import java.io.PrintWriter; 27 28 /** 29 * Base class for available WiFi operating modes. 30 * 31 * Currently supported modes include Client, ScanOnly and SoftAp. 32 */ 33 public interface ActiveModeManager { 34 String TAG = "ActiveModeManager"; 35 36 /** 37 * Method used to start the Manager for a given Wifi operational mode. 38 */ 39 void start(); 40 41 /** 42 * Method used to stop the Manager for a give Wifi operational mode. 43 */ 44 void stop(); 45 46 /** 47 * Method to dump for logging state. 48 */ 49 void dump(FileDescriptor fd, PrintWriter pw, String[] args); 50 51 /** 52 * Method that allows Mode Managers to update WifiScanner about the current state. 53 * 54 * @param context Context to use for the notification 55 * @param available boolean indicating if scanning is available 56 */ 57 default void sendScanAvailableBroadcast(Context context, boolean available) { 58 Log.d(TAG, "sending scan available broadcast: " + available); 59 final Intent intent = new Intent(WifiManager.WIFI_SCAN_AVAILABLE); 60 intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); 61 if (available) { 62 intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WifiManager.WIFI_STATE_ENABLED); 63 } else { 64 intent.putExtra(WifiManager.EXTRA_SCAN_AVAILABLE, WifiManager.WIFI_STATE_DISABLED); 65 } 66 context.sendStickyBroadcastAsUser(intent, UserHandle.ALL); 67 } 68 } 69