Utils.java revision 30275c1924b2bd45b05bd9c98f8648ecbc71374f
1package com.android.settingslib; 2 3import android.content.Context; 4import android.content.pm.UserInfo; 5import android.graphics.Bitmap; 6import android.graphics.BitmapFactory; 7import android.graphics.drawable.Drawable; 8import android.net.ConnectivityManager; 9import android.os.UserManager; 10 11import com.android.internal.util.UserIcons; 12import com.android.settingslib.drawable.CircleFramedDrawable; 13 14public final class Utils { 15 16 /** 17 * Return string resource that best describes combination of tethering 18 * options available on this device. 19 */ 20 public static int getTetheringLabel(ConnectivityManager cm) { 21 String[] usbRegexs = cm.getTetherableUsbRegexs(); 22 String[] wifiRegexs = cm.getTetherableWifiRegexs(); 23 String[] bluetoothRegexs = cm.getTetherableBluetoothRegexs(); 24 25 boolean usbAvailable = usbRegexs.length != 0; 26 boolean wifiAvailable = wifiRegexs.length != 0; 27 boolean bluetoothAvailable = bluetoothRegexs.length != 0; 28 29 if (wifiAvailable && usbAvailable && bluetoothAvailable) { 30 return R.string.tether_settings_title_all; 31 } else if (wifiAvailable && usbAvailable) { 32 return R.string.tether_settings_title_all; 33 } else if (wifiAvailable && bluetoothAvailable) { 34 return R.string.tether_settings_title_all; 35 } else if (wifiAvailable) { 36 return R.string.tether_settings_title_wifi; 37 } else if (usbAvailable && bluetoothAvailable) { 38 return R.string.tether_settings_title_usb_bluetooth; 39 } else if (usbAvailable) { 40 return R.string.tether_settings_title_usb; 41 } else { 42 return R.string.tether_settings_title_bluetooth; 43 } 44 } 45 46 /** 47 * Returns a label for the user, in the form of "User: user name" or "Work profile". 48 */ 49 public static String getUserLabel(Context context, UserInfo info) { 50 String name = info != null ? info.name : null; 51 if (info.isManagedProfile()) { 52 // We use predefined values for managed profiles 53 return context.getString(R.string.managed_user_title); 54 } else if (info.isGuest()) { 55 name = context.getString(R.string.user_guest); 56 } 57 if (name == null && info != null) { 58 name = Integer.toString(info.id); 59 } else if (info == null) { 60 name = context.getString(R.string.unknown); 61 } 62 return context.getResources().getString(R.string.running_process_item_user_label, name); 63 } 64 65 /** 66 * Returns a circular icon for a user. 67 */ 68 public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) { 69 if (user.isManagedProfile()) { 70 // We use predefined values for managed profiles 71 Bitmap b = BitmapFactory.decodeResource(context.getResources(), 72 com.android.internal.R.drawable.ic_corp_icon); 73 return CircleFramedDrawable.getInstance(context, b); 74 } 75 if (user.iconPath != null) { 76 Bitmap icon = um.getUserIcon(user.id); 77 if (icon != null) { 78 return CircleFramedDrawable.getInstance(context, icon); 79 } 80 } 81 return CircleFramedDrawable.getInstance(context, UserIcons.convertToBitmap( 82 UserIcons.getDefaultUserIcon(user.id, /* light= */ false))); 83 } 84} 85