1 package com.koushikdutta.superuser;
3 import java.lang.reflect.Method;
5 import android.annotation.SuppressLint;
6 import android.content.Context;
7 import android.content.pm.PackageInfo;
8 import android.content.pm.PackageManager;
9 import android.graphics.drawable.Drawable;
10 import android.os.UserManager;
12 import com.koushikdutta.superuser.util.ImageCache;
15 public static Drawable loadPackageIcon(Context context, String pn) {
17 PackageManager pm = context.getPackageManager();
18 PackageInfo pi = context.getPackageManager().getPackageInfo(pn, 0);
19 Drawable ret = ImageCache.getInstance().get(pn);
22 ImageCache.getInstance().put(pn, ret = pi.applicationInfo.loadIcon(pm));
25 catch (Exception ex) {
30 @SuppressLint("NewApi")
31 public static boolean supportsMultipleUsers(Context context) {
32 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
34 Method supportsMultipleUsers = UserManager.class.getMethod("supportsMultipleUsers");
35 return (Boolean)supportsMultipleUsers.invoke(um);
37 catch (Exception ex) {
42 @SuppressLint("NewApi")
43 public static boolean isAdminUser(Context context) {
44 final UserManager um = (UserManager) context.getSystemService(Context.USER_SERVICE);
46 Method getUserHandle = UserManager.class.getMethod("getUserHandle");
47 int userHandle = (Integer)getUserHandle.invoke(um);
48 return userHandle == 0;
50 catch (Exception ex) {