1 /* 2 * Copyright (C) 2021 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.car.settings.qc; 18 19 import android.content.Context; 20 import android.net.TetheringManager; 21 import android.net.Uri; 22 import android.net.wifi.WifiManager; 23 24 /** 25 * Helper methods for hotspot related quick controls. 26 */ 27 public final class HotspotQCUtils { HotspotQCUtils()28 private HotspotQCUtils() { 29 } 30 31 /** 32 * Returns whether or not hotspot is currently enabled. 33 */ isHotspotEnabled(WifiManager wifiManager)34 public static boolean isHotspotEnabled(WifiManager wifiManager) { 35 int state = wifiManager.getWifiApState(); 36 return state == WifiManager.WIFI_AP_STATE_ENABLED 37 || state == WifiManager.WIFI_AP_STATE_ENABLING; 38 } 39 40 /** 41 * Returns whether or not hotspot is currently busy. 42 */ isHotspotBusy(WifiManager wifiManager)43 public static boolean isHotspotBusy(WifiManager wifiManager) { 44 int state = wifiManager.getWifiApState(); 45 return state == WifiManager.WIFI_AP_STATE_ENABLING 46 || state == WifiManager.WIFI_AP_STATE_DISABLING; 47 } 48 49 /** 50 * Helper method to get the default {@link TetheringManager.StartTetheringCallback} used by 51 * hotspot quick controls. 52 */ getDefaultStartTetheringCallback( Context context, Uri uri)53 public static TetheringManager.StartTetheringCallback getDefaultStartTetheringCallback( 54 Context context, Uri uri) { 55 return new TetheringManager.StartTetheringCallback() { 56 @Override 57 public void onTetheringFailed(final int result) { 58 context.getContentResolver().notifyChange(uri, /* observer= */null); 59 } 60 }; 61 } 62 } 63