/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License */ package com.android.car.settings.wifi; import android.annotation.DrawableRes; import android.content.Context; import android.content.pm.PackageManager; import android.net.wifi.WifiManager; import android.support.annotation.StringRes; import com.android.car.settings.R; /** * A collections of util functions for WIFI. */ public class WifiUtil { @DrawableRes public static int getIconRes(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: case WifiManager.WIFI_STATE_DISABLED: return R.drawable.ic_settings_wifi_disabled; default: return R.drawable.ic_settings_wifi; } } public static boolean isWifiOn(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: case WifiManager.WIFI_STATE_DISABLED: return false; default: return true; } } /** * @return 0 if no proper description can be found. */ @StringRes public static Integer getStateDesc(int state) { switch (state) { case WifiManager.WIFI_STATE_ENABLING: return R.string.wifi_starting; case WifiManager.WIFI_STATE_DISABLING: return R.string.wifi_stopping; case WifiManager.WIFI_STATE_DISABLED: return R.string.wifi_disabled; default: return 0; } } /** * Returns {@Code true} if wifi is available on this device. */ public static boolean isWifiAvailable(Context context) { return context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI); } }