Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 1 | package com.android.settingslib; |
| 2 | |
Andrew Sapperstein | 5c37344 | 2016-06-12 13:17:16 -0700 | [diff] [blame] | 3 | import android.annotation.ColorInt; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 4 | import android.content.Context; |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 5 | import android.content.Intent; |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 6 | import android.content.pm.PackageInfo; |
| 7 | import android.content.pm.PackageManager; |
| 8 | import android.content.pm.PackageManager.NameNotFoundException; |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 9 | import android.content.pm.Signature; |
Fan Zhang | 73b161d | 2017-02-08 11:46:54 -0800 | [diff] [blame] | 10 | import android.content.pm.UserInfo; |
jackqdyulei | b68fd7a | 2017-01-04 15:43:26 -0800 | [diff] [blame] | 11 | import android.content.res.ColorStateList; |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 12 | import android.content.res.Resources; |
Andrew Sapperstein | 5c37344 | 2016-06-12 13:17:16 -0700 | [diff] [blame] | 13 | import android.content.res.TypedArray; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 14 | import android.graphics.Bitmap; |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 15 | import android.graphics.Color; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 16 | import android.graphics.drawable.Drawable; |
Maggie | fab2e2c | 2017-11-21 11:57:30 -0800 | [diff] [blame] | 17 | import android.location.LocationManager; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 18 | import android.net.ConnectivityManager; |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 19 | import android.os.BatteryManager; |
Maggie | fab2e2c | 2017-11-21 11:57:30 -0800 | [diff] [blame] | 20 | import android.os.UserHandle; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 21 | import android.os.UserManager; |
Philip P. Moltmann | 545a58a | 2016-06-28 14:14:06 -0700 | [diff] [blame] | 22 | import android.print.PrintManager; |
Daniel Nishi | 5398280 | 2017-05-23 15:54:34 -0700 | [diff] [blame] | 23 | import android.provider.Settings; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 24 | import com.android.internal.util.UserIcons; |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 25 | import com.android.settingslib.drawable.UserIconDrawable; |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 26 | import com.android.settingslib.wrapper.LocationManagerWrapper; |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 27 | import java.text.NumberFormat; |
| 28 | |
| 29 | public class Utils { |
Maggie | fab2e2c | 2017-11-21 11:57:30 -0800 | [diff] [blame] | 30 | |
| 31 | private static final String CURRENT_MODE_KEY = "CURRENT_MODE"; |
| 32 | private static final String NEW_MODE_KEY = "NEW_MODE"; |
| 33 | |
Svetoslav Ganov | a9c2500 | 2016-04-13 19:25:56 -0700 | [diff] [blame] | 34 | private static Signature[] sSystemSignature; |
| 35 | private static String sPermissionControllerPackageName; |
| 36 | private static String sServicesSystemSharedLibPackageName; |
| 37 | private static String sSharedSystemSharedLibPackageName; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 38 | |
Eric Schwarzenbach | 44268e3 | 2017-08-04 16:38:07 -0700 | [diff] [blame] | 39 | static final int[] WIFI_PIE = { |
| 40 | com.android.internal.R.drawable.ic_wifi_signal_0, |
| 41 | com.android.internal.R.drawable.ic_wifi_signal_1, |
| 42 | com.android.internal.R.drawable.ic_wifi_signal_2, |
| 43 | com.android.internal.R.drawable.ic_wifi_signal_3, |
| 44 | com.android.internal.R.drawable.ic_wifi_signal_4 |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 45 | }; |
| 46 | |
Maggie | aa080f9 | 2018-01-04 15:35:11 -0800 | [diff] [blame] | 47 | public static void updateLocationEnabled(Context context, boolean enabled, int userId) { |
| 48 | Intent intent = new Intent(LocationManager.MODE_CHANGING_ACTION); |
| 49 | |
| 50 | final int oldMode = Settings.Secure.getIntForUser(context.getContentResolver(), |
| 51 | Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF, userId); |
| 52 | final int newMode = enabled |
| 53 | ? Settings.Secure.LOCATION_MODE_HIGH_ACCURACY |
| 54 | : Settings.Secure.LOCATION_MODE_OFF; |
| 55 | intent.putExtra(CURRENT_MODE_KEY, oldMode); |
| 56 | intent.putExtra(NEW_MODE_KEY, newMode); |
| 57 | context.sendBroadcastAsUser( |
| 58 | intent, UserHandle.of(userId), android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 59 | LocationManager locationManager = |
| 60 | (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); |
| 61 | LocationManagerWrapper wrapper = new LocationManagerWrapper(locationManager); |
| 62 | wrapper.setLocationEnabledForUser(enabled, UserHandle.of(userId)); |
| 63 | } |
| 64 | |
Maggie | fab2e2c | 2017-11-21 11:57:30 -0800 | [diff] [blame] | 65 | public static boolean updateLocationMode(Context context, int oldMode, int newMode, int userId) { |
| 66 | Intent intent = new Intent(LocationManager.MODE_CHANGING_ACTION); |
| 67 | intent.putExtra(CURRENT_MODE_KEY, oldMode); |
| 68 | intent.putExtra(NEW_MODE_KEY, newMode); |
| 69 | context.sendBroadcastAsUser( |
| 70 | intent, UserHandle.of(userId), android.Manifest.permission.WRITE_SECURE_SETTINGS); |
| 71 | return Settings.Secure.putIntForUser( |
| 72 | context.getContentResolver(), Settings.Secure.LOCATION_MODE, newMode, userId); |
| 73 | } |
| 74 | |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 75 | /** |
| 76 | * Return string resource that best describes combination of tethering |
| 77 | * options available on this device. |
| 78 | */ |
| 79 | public static int getTetheringLabel(ConnectivityManager cm) { |
| 80 | String[] usbRegexs = cm.getTetherableUsbRegexs(); |
| 81 | String[] wifiRegexs = cm.getTetherableWifiRegexs(); |
| 82 | String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs(); |
| 83 | |
| 84 | boolean usbAvailable = usbRegexs.length != 0; |
| 85 | boolean wifiAvailable = wifiRegexs.length != 0; |
| 86 | boolean bluetoothAvailable = bluetoothRegexs.length != 0; |
| 87 | |
| 88 | if (wifiAvailable && usbAvailable && bluetoothAvailable) { |
| 89 | return R.string.tether_settings_title_all; |
| 90 | } else if (wifiAvailable && usbAvailable) { |
| 91 | return R.string.tether_settings_title_all; |
| 92 | } else if (wifiAvailable && bluetoothAvailable) { |
| 93 | return R.string.tether_settings_title_all; |
| 94 | } else if (wifiAvailable) { |
| 95 | return R.string.tether_settings_title_wifi; |
| 96 | } else if (usbAvailable && bluetoothAvailable) { |
| 97 | return R.string.tether_settings_title_usb_bluetooth; |
| 98 | } else if (usbAvailable) { |
| 99 | return R.string.tether_settings_title_usb; |
| 100 | } else { |
| 101 | return R.string.tether_settings_title_bluetooth; |
| 102 | } |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Returns a label for the user, in the form of "User: user name" or "Work profile". |
| 107 | */ |
| 108 | public static String getUserLabel(Context context, UserInfo info) { |
| 109 | String name = info != null ? info.name : null; |
| 110 | if (info.isManagedProfile()) { |
| 111 | // We use predefined values for managed profiles |
| 112 | return context.getString(R.string.managed_user_title); |
| 113 | } else if (info.isGuest()) { |
| 114 | name = context.getString(R.string.user_guest); |
| 115 | } |
| 116 | if (name == null && info != null) { |
| 117 | name = Integer.toString(info.id); |
| 118 | } else if (info == null) { |
| 119 | name = context.getString(R.string.unknown); |
| 120 | } |
| 121 | return context.getResources().getString(R.string.running_process_item_user_label, name); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Returns a circular icon for a user. |
| 126 | */ |
Daniel Nishi | f26dbd8 | 2017-08-15 15:25:39 -0700 | [diff] [blame] | 127 | public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) { |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 128 | final int iconSize = UserIconDrawable.getSizeForList(context); |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 129 | if (user.isManagedProfile()) { |
Tony Mak | bca5c93 | 2017-11-08 19:54:15 +0000 | [diff] [blame] | 130 | Drawable drawable = context.getDrawable(com.android.internal.R.drawable.ic_corp_badge); |
Daniel Nishi | 07d0f59 | 2017-08-21 15:50:11 -0700 | [diff] [blame] | 131 | drawable.setBounds(0, 0, iconSize, iconSize); |
| 132 | return drawable; |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 133 | } |
| 134 | if (user.iconPath != null) { |
| 135 | Bitmap icon = um.getUserIcon(user.id); |
| 136 | if (icon != null) { |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 137 | return new UserIconDrawable(iconSize).setIcon(icon).bake(); |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Evan Rosky | aa7f51f | 2016-03-16 13:15:53 -0700 | [diff] [blame] | 140 | return new UserIconDrawable(iconSize).setIconDrawable( |
Tony Mak | 213955e | 2017-11-23 16:57:08 +0800 | [diff] [blame] | 141 | UserIcons.getDefaultUserIcon(context.getResources(), user.id, /* light= */ false)) |
| 142 | .bake(); |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 143 | } |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 144 | |
jackqdyulei | 5dc1f36 | 2017-02-17 14:41:05 -0800 | [diff] [blame] | 145 | /** Formats a double from 0.0..100.0 with an option to round **/ |
| 146 | public static String formatPercentage(double percentage, boolean round) { |
| 147 | final int localPercentage = round ? Math.round((float) percentage) : (int) percentage; |
| 148 | return formatPercentage(localPercentage); |
| 149 | } |
| 150 | |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 151 | /** Formats the ratio of amount/total as a percentage. */ |
| 152 | public static String formatPercentage(long amount, long total) { |
| 153 | return formatPercentage(((double) amount) / total); |
| 154 | } |
| 155 | |
| 156 | /** Formats an integer from 0..100 as a percentage. */ |
| 157 | public static String formatPercentage(int percentage) { |
| 158 | return formatPercentage(((double) percentage) / 100.0); |
| 159 | } |
| 160 | |
| 161 | /** Formats a double from 0.0..1.0 as a percentage. */ |
Daniel Nishi | 3f94f68 | 2017-06-27 14:38:06 -0700 | [diff] [blame] | 162 | public static String formatPercentage(double percentage) { |
jackqdyulei | 5dc1f36 | 2017-02-17 14:41:05 -0800 | [diff] [blame] | 163 | return NumberFormat.getPercentInstance().format(percentage); |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | public static int getBatteryLevel(Intent batteryChangedIntent) { |
| 167 | int level = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); |
| 168 | int scale = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_SCALE, 100); |
| 169 | return (level * 100) / scale; |
| 170 | } |
| 171 | |
| 172 | public static String getBatteryStatus(Resources res, Intent batteryChangedIntent) { |
Muyuan Li | 18d2b32 | 2016-03-31 13:53:56 -0700 | [diff] [blame] | 173 | int status = batteryChangedIntent.getIntExtra(BatteryManager.EXTRA_STATUS, |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 174 | BatteryManager.BATTERY_STATUS_UNKNOWN); |
| 175 | String statusString; |
| 176 | if (status == BatteryManager.BATTERY_STATUS_CHARGING) { |
jackqdyulei | 806f78d | 2017-03-24 12:13:49 -0700 | [diff] [blame] | 177 | statusString = res.getString(R.string.battery_info_status_charging); |
Jason Monk | c06fbb1 | 2016-01-08 14:12:18 -0500 | [diff] [blame] | 178 | } else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING) { |
| 179 | statusString = res.getString(R.string.battery_info_status_discharging); |
| 180 | } else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING) { |
| 181 | statusString = res.getString(R.string.battery_info_status_not_charging); |
| 182 | } else if (status == BatteryManager.BATTERY_STATUS_FULL) { |
| 183 | statusString = res.getString(R.string.battery_info_status_full); |
| 184 | } else { |
| 185 | statusString = res.getString(R.string.battery_info_status_unknown); |
| 186 | } |
| 187 | |
| 188 | return statusString; |
| 189 | } |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 190 | |
Andrew Sapperstein | 5c37344 | 2016-06-12 13:17:16 -0700 | [diff] [blame] | 191 | @ColorInt |
| 192 | public static int getColorAccent(Context context) { |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 193 | return getColorAttr(context, android.R.attr.colorAccent); |
Andrew Sapperstein | 5c37344 | 2016-06-12 13:17:16 -0700 | [diff] [blame] | 194 | } |
| 195 | |
jackqdyulei | b68fd7a | 2017-01-04 15:43:26 -0800 | [diff] [blame] | 196 | @ColorInt |
| 197 | public static int getColorError(Context context) { |
Jason Monk | 58be7a6 | 2017-02-01 20:17:51 -0500 | [diff] [blame] | 198 | return getColorAttr(context, android.R.attr.colorError); |
jackqdyulei | b68fd7a | 2017-01-04 15:43:26 -0800 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @ColorInt |
| 202 | public static int getDefaultColor(Context context, int resId) { |
| 203 | final ColorStateList list = |
| 204 | context.getResources().getColorStateList(resId, context.getTheme()); |
| 205 | |
| 206 | return list.getDefaultColor(); |
| 207 | } |
| 208 | |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 209 | @ColorInt |
| 210 | public static int getDisabled(Context context, int inputColor) { |
| 211 | return applyAlphaAttr(context, android.R.attr.disabledAlpha, inputColor); |
| 212 | } |
| 213 | |
| 214 | @ColorInt |
| 215 | public static int applyAlphaAttr(Context context, int attr, int inputColor) { |
| 216 | TypedArray ta = context.obtainStyledAttributes(new int[]{attr}); |
| 217 | float alpha = ta.getFloat(0, 0); |
| 218 | ta.recycle(); |
Jason Monk | 824ffff | 2017-04-11 15:49:06 -0400 | [diff] [blame] | 219 | return applyAlpha(alpha, inputColor); |
| 220 | } |
| 221 | |
| 222 | @ColorInt |
| 223 | public static int applyAlpha(float alpha, int inputColor) { |
Jason Monk | 3250885 | 2017-01-18 09:17:13 -0500 | [diff] [blame] | 224 | alpha *= Color.alpha(inputColor); |
| 225 | return Color.argb((int) (alpha), Color.red(inputColor), Color.green(inputColor), |
| 226 | Color.blue(inputColor)); |
| 227 | } |
| 228 | |
| 229 | @ColorInt |
| 230 | public static int getColorAttr(Context context, int attr) { |
| 231 | TypedArray ta = context.obtainStyledAttributes(new int[]{attr}); |
| 232 | @ColorInt int colorAccent = ta.getColor(0, 0); |
| 233 | ta.recycle(); |
| 234 | return colorAccent; |
| 235 | } |
| 236 | |
Jason Monk | 9a376bc | 2017-05-10 09:52:10 -0400 | [diff] [blame] | 237 | public static int getThemeAttr(Context context, int attr) { |
| 238 | TypedArray ta = context.obtainStyledAttributes(new int[]{attr}); |
| 239 | int theme = ta.getResourceId(0, 0); |
| 240 | ta.recycle(); |
| 241 | return theme; |
| 242 | } |
| 243 | |
Jason Monk | 790442e | 2017-02-13 17:49:39 -0500 | [diff] [blame] | 244 | public static Drawable getDrawable(Context context, int attr) { |
| 245 | TypedArray ta = context.obtainStyledAttributes(new int[]{attr}); |
| 246 | Drawable drawable = ta.getDrawable(0); |
| 247 | ta.recycle(); |
| 248 | return drawable; |
| 249 | } |
| 250 | |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 251 | /** |
| 252 | * Determine whether a package is a "system package", in which case certain things (like |
| 253 | * disabling notifications or disabling the package altogether) should be disallowed. |
| 254 | */ |
Tony Mak | bfba9d4 | 2016-07-14 15:29:44 +0800 | [diff] [blame] | 255 | public static boolean isSystemPackage(Resources resources, PackageManager pm, PackageInfo pkg) { |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 256 | if (sSystemSignature == null) { |
| 257 | sSystemSignature = new Signature[]{ getSystemSignature(pm) }; |
| 258 | } |
Svet Ganov | 81fb0d4 | 2016-03-04 09:27:23 -0800 | [diff] [blame] | 259 | if (sPermissionControllerPackageName == null) { |
| 260 | sPermissionControllerPackageName = pm.getPermissionControllerPackageName(); |
| 261 | } |
Svetoslav Ganov | a9c2500 | 2016-04-13 19:25:56 -0700 | [diff] [blame] | 262 | if (sServicesSystemSharedLibPackageName == null) { |
| 263 | sServicesSystemSharedLibPackageName = pm.getServicesSystemSharedLibraryPackageName(); |
| 264 | } |
| 265 | if (sSharedSystemSharedLibPackageName == null) { |
| 266 | sSharedSystemSharedLibPackageName = pm.getSharedSystemSharedLibraryPackageName(); |
| 267 | } |
Svet Ganov | 81fb0d4 | 2016-03-04 09:27:23 -0800 | [diff] [blame] | 268 | return (sSystemSignature[0] != null |
| 269 | && sSystemSignature[0].equals(getFirstSignature(pkg))) |
Svetoslav Ganov | a9c2500 | 2016-04-13 19:25:56 -0700 | [diff] [blame] | 270 | || pkg.packageName.equals(sPermissionControllerPackageName) |
| 271 | || pkg.packageName.equals(sServicesSystemSharedLibPackageName) |
Philip P. Moltmann | 545a58a | 2016-06-28 14:14:06 -0700 | [diff] [blame] | 272 | || pkg.packageName.equals(sSharedSystemSharedLibPackageName) |
Tony Mak | bfba9d4 | 2016-07-14 15:29:44 +0800 | [diff] [blame] | 273 | || pkg.packageName.equals(PrintManager.PRINT_SPOOLER_PACKAGE_NAME) |
| 274 | || isDeviceProvisioningPackage(resources, pkg.packageName); |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 275 | } |
| 276 | |
Julia Reynolds | 21c3054 | 2016-01-15 15:00:02 -0500 | [diff] [blame] | 277 | private static Signature getFirstSignature(PackageInfo pkg) { |
| 278 | if (pkg != null && pkg.signatures != null && pkg.signatures.length > 0) { |
| 279 | return pkg.signatures[0]; |
| 280 | } |
| 281 | return null; |
| 282 | } |
| 283 | |
| 284 | private static Signature getSystemSignature(PackageManager pm) { |
| 285 | try { |
| 286 | final PackageInfo sys = pm.getPackageInfo("android", PackageManager.GET_SIGNATURES); |
| 287 | return getFirstSignature(sys); |
| 288 | } catch (NameNotFoundException e) { |
| 289 | } |
| 290 | return null; |
| 291 | } |
Tony Mak | bfba9d4 | 2016-07-14 15:29:44 +0800 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * Returns {@code true} if the supplied package is the device provisioning app. Otherwise, |
| 295 | * returns {@code false}. |
| 296 | */ |
| 297 | public static boolean isDeviceProvisioningPackage(Resources resources, String packageName) { |
| 298 | String deviceProvisioningPackage = resources.getString( |
| 299 | com.android.internal.R.string.config_deviceProvisioningPackage); |
| 300 | return deviceProvisioningPackage != null && deviceProvisioningPackage.equals(packageName); |
| 301 | } |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 302 | |
| 303 | /** |
Eric Schwarzenbach | 44268e3 | 2017-08-04 16:38:07 -0700 | [diff] [blame] | 304 | * Returns the Wifi icon resource for a given RSSI level. |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 305 | * |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 306 | * @param level The number of bars to show (0-4) |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 307 | * |
Eric Schwarzenbach | 44268e3 | 2017-08-04 16:38:07 -0700 | [diff] [blame] | 308 | * @throws IllegalArgumentException if an invalid RSSI level is given. |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 309 | */ |
Eric Schwarzenbach | 44268e3 | 2017-08-04 16:38:07 -0700 | [diff] [blame] | 310 | public static int getWifiIconResource(int level) { |
| 311 | if (level < 0 || level >= WIFI_PIE.length) { |
| 312 | throw new IllegalArgumentException("No Wifi icon found for level: " + level); |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 313 | } |
Eric Schwarzenbach | 44268e3 | 2017-08-04 16:38:07 -0700 | [diff] [blame] | 314 | return WIFI_PIE[level]; |
Sundeep Ghuman | f84e057 | 2017-01-10 13:43:03 -0800 | [diff] [blame] | 315 | } |
Daniel Nishi | 5398280 | 2017-05-23 15:54:34 -0700 | [diff] [blame] | 316 | |
| 317 | public static int getDefaultStorageManagerDaysToRetain(Resources resources) { |
| 318 | int defaultDays = Settings.Secure.AUTOMATIC_STORAGE_MANAGER_DAYS_TO_RETAIN_DEFAULT; |
| 319 | try { |
| 320 | defaultDays = |
| 321 | resources.getInteger( |
| 322 | com.android |
| 323 | .internal |
| 324 | .R |
| 325 | .integer |
| 326 | .config_storageManagerDaystoRetainDefault); |
| 327 | } catch (Resources.NotFoundException e) { |
| 328 | // We are likely in a test environment. |
| 329 | } |
| 330 | return defaultDays; |
| 331 | } |
Tony Mantler | 8892014 | 2017-10-20 15:03:56 -0700 | [diff] [blame] | 332 | |
| 333 | public static boolean isWifiOnly(Context context) { |
| 334 | return !context.getSystemService(ConnectivityManager.class) |
| 335 | .isNetworkSupported(ConnectivityManager.TYPE_MOBILE); |
| 336 | } |
Wei Liu | 30275c1 | 2015-08-24 17:35:49 -0700 | [diff] [blame] | 337 | } |