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 package com.android.car.settings.wifi; 17 18 import android.annotation.DrawableRes; 19 import android.content.Context; 20 import android.content.pm.PackageManager; 21 import android.net.wifi.WifiManager; 22 import android.support.annotation.StringRes; 23 24 import com.android.car.settings.R; 25 26 /** 27 * A collections of util functions for WIFI. 28 */ 29 public class WifiUtil { 30 @DrawableRes getIconRes(int state)31 public static int getIconRes(int state) { 32 switch (state) { 33 case WifiManager.WIFI_STATE_ENABLING: 34 case WifiManager.WIFI_STATE_DISABLED: 35 return R.drawable.ic_settings_wifi_disabled; 36 default: 37 return R.drawable.ic_settings_wifi; 38 } 39 } 40 isWifiOn(int state)41 public static boolean isWifiOn(int state) { 42 switch (state) { 43 case WifiManager.WIFI_STATE_ENABLING: 44 case WifiManager.WIFI_STATE_DISABLED: 45 return false; 46 default: 47 return true; 48 } 49 } 50 51 /** 52 * @return 0 if no proper description can be found. 53 */ 54 @StringRes getStateDesc(int state)55 public static Integer getStateDesc(int state) { 56 switch (state) { 57 case WifiManager.WIFI_STATE_ENABLING: 58 return R.string.wifi_starting; 59 case WifiManager.WIFI_STATE_DISABLING: 60 return R.string.wifi_stopping; 61 case WifiManager.WIFI_STATE_DISABLED: 62 return R.string.wifi_disabled; 63 default: 64 return 0; 65 } 66 } 67 68 /** 69 * Returns {@Code true} if wifi is available on this device. 70 */ isWifiAvailable(Context context)71 public static boolean isWifiAvailable(Context context) { 72 return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); 73 } 74 } 75