AppSecurityPermissions.java revision ae0e03a9e03de34e37b768b971d7596d7220a053
1/*
2**
3** Copyright 2007, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9**     http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17package android.widget;
18
19import android.annotation.SystemApi;
20import android.os.UserHandle;
21import com.android.internal.R;
22
23import android.app.AlertDialog;
24import android.content.Context;
25import android.content.DialogInterface;
26import android.content.pm.ApplicationInfo;
27import android.content.pm.PackageInfo;
28import android.content.pm.PackageManager;
29import android.content.pm.PackageManager.NameNotFoundException;
30import android.content.pm.PermissionGroupInfo;
31import android.content.pm.PermissionInfo;
32import android.graphics.drawable.Drawable;
33import android.os.Parcel;
34import android.text.SpannableStringBuilder;
35import android.text.TextUtils;
36import android.util.AttributeSet;
37import android.util.Log;
38import android.view.LayoutInflater;
39import android.view.View;
40import android.view.ViewGroup;
41
42import java.text.Collator;
43import java.util.ArrayList;
44import java.util.Collections;
45import java.util.Comparator;
46import java.util.HashMap;
47import java.util.HashSet;
48import java.util.List;
49import java.util.Map;
50import java.util.Set;
51
52/**
53 * This class contains the SecurityPermissions view implementation.
54 * Initially the package's advanced or dangerous security permissions
55 * are displayed under categorized
56 * groups. Clicking on the additional permissions presents
57 * extended information consisting of all groups and permissions.
58 * To use this view define a LinearLayout or any ViewGroup and add this
59 * view by instantiating AppSecurityPermissions and invoking getPermissionsView.
60 *
61 * {@hide}
62 */
63public class AppSecurityPermissions {
64
65    public static final int WHICH_NEW = 1<<2;
66    public static final int WHICH_ALL = 0xffff;
67
68    private final static String TAG = "AppSecurityPermissions";
69    private final static boolean localLOGV = false;
70    private final Context mContext;
71    private final LayoutInflater mInflater;
72    private final PackageManager mPm;
73    private final Map<String, MyPermissionGroupInfo> mPermGroups
74            = new HashMap<String, MyPermissionGroupInfo>();
75    private final List<MyPermissionGroupInfo> mPermGroupsList
76            = new ArrayList<MyPermissionGroupInfo>();
77    private final PermissionGroupInfoComparator mPermGroupComparator =
78            new PermissionGroupInfoComparator();
79    private final PermissionInfoComparator mPermComparator = new PermissionInfoComparator();
80    private final List<MyPermissionInfo> mPermsList = new ArrayList<MyPermissionInfo>();
81    private final CharSequence mNewPermPrefix;
82    private String mPackageName;
83
84    /** @hide */
85    static class MyPermissionGroupInfo extends PermissionGroupInfo {
86        CharSequence mLabel;
87
88        final ArrayList<MyPermissionInfo> mNewPermissions = new ArrayList<MyPermissionInfo>();
89        final ArrayList<MyPermissionInfo> mAllPermissions = new ArrayList<MyPermissionInfo>();
90
91        MyPermissionGroupInfo(PermissionInfo perm) {
92            name = perm.packageName;
93            packageName = perm.packageName;
94        }
95
96        MyPermissionGroupInfo(PermissionGroupInfo info) {
97            super(info);
98        }
99
100        public Drawable loadGroupIcon(Context context, PackageManager pm) {
101            if (icon != 0) {
102                return loadUnbadgedIcon(pm);
103            } else {
104                return context.getDrawable(R.drawable.ic_perm_device_info);
105            }
106        }
107    }
108
109    /** @hide */
110    private static class MyPermissionInfo extends PermissionInfo {
111        CharSequence mLabel;
112
113        /**
114         * PackageInfo.requestedPermissionsFlags for the new package being installed.
115         */
116        int mNewReqFlags;
117
118        /**
119         * PackageInfo.requestedPermissionsFlags for the currently installed
120         * package, if it is installed.
121         */
122        int mExistingReqFlags;
123
124        /**
125         * True if this should be considered a new permission.
126         */
127        boolean mNew;
128
129        MyPermissionInfo(PermissionInfo info) {
130            super(info);
131        }
132    }
133
134    /** @hide */
135    public static class PermissionItemView extends LinearLayout implements View.OnClickListener {
136        MyPermissionGroupInfo mGroup;
137        MyPermissionInfo mPerm;
138        AlertDialog mDialog;
139        private boolean mShowRevokeUI = false;
140        private String mPackageName;
141
142        public PermissionItemView(Context context, AttributeSet attrs) {
143            super(context, attrs);
144            setClickable(true);
145        }
146
147        public void setPermission(MyPermissionGroupInfo grp, MyPermissionInfo perm,
148                boolean first, CharSequence newPermPrefix, String packageName,
149                boolean showRevokeUI) {
150            mGroup = grp;
151            mPerm = perm;
152            mShowRevokeUI = showRevokeUI;
153            mPackageName = packageName;
154
155            ImageView permGrpIcon = (ImageView) findViewById(R.id.perm_icon);
156            TextView permNameView = (TextView) findViewById(R.id.perm_name);
157
158            PackageManager pm = getContext().getPackageManager();
159            Drawable icon = null;
160            if (first) {
161                icon = grp.loadGroupIcon(getContext(), pm);
162            }
163            CharSequence label = perm.mLabel;
164            if (perm.mNew && newPermPrefix != null) {
165                // If this is a new permission, format it appropriately.
166                SpannableStringBuilder builder = new SpannableStringBuilder();
167                Parcel parcel = Parcel.obtain();
168                TextUtils.writeToParcel(newPermPrefix, parcel, 0);
169                parcel.setDataPosition(0);
170                CharSequence newStr = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel);
171                parcel.recycle();
172                builder.append(newStr);
173                builder.append(label);
174                label = builder;
175            }
176
177            permGrpIcon.setImageDrawable(icon);
178            permNameView.setText(label);
179            setOnClickListener(this);
180            if (localLOGV) Log.i(TAG, "Made perm item " + perm.name
181                    + ": " + label + " in group " + grp.name);
182        }
183
184        @Override
185        public void onClick(View v) {
186            if (mGroup != null && mPerm != null) {
187                if (mDialog != null) {
188                    mDialog.dismiss();
189                }
190                PackageManager pm = getContext().getPackageManager();
191                AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
192                builder.setTitle(mGroup.mLabel);
193                if (mPerm.descriptionRes != 0) {
194                    builder.setMessage(mPerm.loadDescription(pm));
195                } else {
196                    CharSequence appName;
197                    try {
198                        ApplicationInfo app = pm.getApplicationInfo(mPerm.packageName, 0);
199                        appName = app.loadLabel(pm);
200                    } catch (NameNotFoundException e) {
201                        appName = mPerm.packageName;
202                    }
203                    StringBuilder sbuilder = new StringBuilder(128);
204                    sbuilder.append(getContext().getString(
205                            R.string.perms_description_app, appName));
206                    sbuilder.append("\n\n");
207                    sbuilder.append(mPerm.name);
208                    builder.setMessage(sbuilder.toString());
209                }
210                builder.setCancelable(true);
211                builder.setIcon(mGroup.loadGroupIcon(getContext(), pm));
212                addRevokeUIIfNecessary(builder);
213                mDialog = builder.show();
214                mDialog.setCanceledOnTouchOutside(true);
215            }
216        }
217
218        @Override
219        protected void onDetachedFromWindow() {
220            super.onDetachedFromWindow();
221            if (mDialog != null) {
222                mDialog.dismiss();
223            }
224        }
225
226        private void addRevokeUIIfNecessary(AlertDialog.Builder builder) {
227            if (!mShowRevokeUI) {
228                return;
229            }
230
231            final boolean isRequired =
232                    ((mPerm.mExistingReqFlags & PackageInfo.REQUESTED_PERMISSION_REQUIRED) != 0);
233
234            if (isRequired) {
235                return;
236            }
237
238            DialogInterface.OnClickListener ocl = new DialogInterface.OnClickListener() {
239                @Override
240                public void onClick(DialogInterface dialog, int which) {
241                    PackageManager pm = getContext().getPackageManager();
242                    pm.revokeRuntimePermission(mPackageName, mPerm.name,
243                            new UserHandle(mContext.getUserId()));
244                    PermissionItemView.this.setVisibility(View.GONE);
245                }
246            };
247            builder.setNegativeButton(R.string.revoke, ocl);
248            builder.setPositiveButton(R.string.ok, null);
249        }
250    }
251
252    private AppSecurityPermissions(Context context) {
253        mContext = context;
254        mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
255        mPm = mContext.getPackageManager();
256        // Pick up from framework resources instead.
257        mNewPermPrefix = mContext.getText(R.string.perms_new_perm_prefix);
258    }
259
260    public AppSecurityPermissions(Context context, String packageName) {
261        this(context);
262        mPackageName = packageName;
263        Set<MyPermissionInfo> permSet = new HashSet<MyPermissionInfo>();
264        PackageInfo pkgInfo;
265        try {
266            pkgInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
267        } catch (NameNotFoundException e) {
268            Log.w(TAG, "Couldn't retrieve permissions for package:"+packageName);
269            return;
270        }
271        // Extract all user permissions
272        if((pkgInfo.applicationInfo != null) && (pkgInfo.applicationInfo.uid != -1)) {
273            getAllUsedPermissions(pkgInfo.applicationInfo.uid, permSet);
274        }
275        mPermsList.addAll(permSet);
276        setPermissions(mPermsList);
277    }
278
279    public AppSecurityPermissions(Context context, PackageInfo info) {
280        this(context);
281        Set<MyPermissionInfo> permSet = new HashSet<MyPermissionInfo>();
282        if(info == null) {
283            return;
284        }
285        mPackageName = info.packageName;
286
287        // Convert to a PackageInfo
288        PackageInfo installedPkgInfo = null;
289        // Get requested permissions
290        if (info.requestedPermissions != null) {
291            try {
292                installedPkgInfo = mPm.getPackageInfo(info.packageName,
293                        PackageManager.GET_PERMISSIONS);
294            } catch (NameNotFoundException e) {
295            }
296            extractPerms(info, permSet, installedPkgInfo);
297        }
298        // Get permissions related to shared user if any
299        if (info.sharedUserId != null) {
300            int sharedUid;
301            try {
302                sharedUid = mPm.getUidForSharedUser(info.sharedUserId);
303                getAllUsedPermissions(sharedUid, permSet);
304            } catch (NameNotFoundException e) {
305                Log.w(TAG, "Couldn't retrieve shared user id for: " + info.packageName);
306            }
307        }
308        // Retrieve list of permissions
309        mPermsList.addAll(permSet);
310        setPermissions(mPermsList);
311    }
312
313    /**
314     * Utility to retrieve a view displaying a single permission.  This provides
315     * the old UI layout for permissions; it is only here for the device admin
316     * settings to continue to use.
317     */
318    public static View getPermissionItemView(Context context,
319            CharSequence grpName, CharSequence description, boolean dangerous) {
320        LayoutInflater inflater = (LayoutInflater)context.getSystemService(
321                Context.LAYOUT_INFLATER_SERVICE);
322        Drawable icon = context.getDrawable(dangerous
323                ? R.drawable.ic_bullet_key_permission : R.drawable.ic_text_dot);
324        return getPermissionItemViewOld(context, inflater, grpName,
325                description, dangerous, icon);
326    }
327
328    private void getAllUsedPermissions(int sharedUid, Set<MyPermissionInfo> permSet) {
329        String sharedPkgList[] = mPm.getPackagesForUid(sharedUid);
330        if(sharedPkgList == null || (sharedPkgList.length == 0)) {
331            return;
332        }
333        for(String sharedPkg : sharedPkgList) {
334            getPermissionsForPackage(sharedPkg, permSet);
335        }
336    }
337
338    private void getPermissionsForPackage(String packageName, Set<MyPermissionInfo> permSet) {
339        try {
340            PackageInfo pkgInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
341            extractPerms(pkgInfo, permSet, pkgInfo);
342        } catch (NameNotFoundException e) {
343            Log.w(TAG, "Couldn't retrieve permissions for package: " + packageName);
344        }
345    }
346
347    private void extractPerms(PackageInfo info, Set<MyPermissionInfo> permSet,
348            PackageInfo installedPkgInfo) {
349        String[] strList = info.requestedPermissions;
350        int[] flagsList = info.requestedPermissionsFlags;
351        if ((strList == null) || (strList.length == 0)) {
352            return;
353        }
354        for (int i=0; i<strList.length; i++) {
355            String permName = strList[i];
356            try {
357                PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0);
358                if (tmpPermInfo == null) {
359                    continue;
360                }
361                int existingIndex = -1;
362                if (installedPkgInfo != null
363                        && installedPkgInfo.requestedPermissions != null) {
364                    for (int j=0; j<installedPkgInfo.requestedPermissions.length; j++) {
365                        if (permName.equals(installedPkgInfo.requestedPermissions[j])) {
366                            existingIndex = j;
367                            break;
368                        }
369                    }
370                }
371                final int existingFlags = existingIndex >= 0 ?
372                        installedPkgInfo.requestedPermissionsFlags[existingIndex] : 0;
373                if (!isDisplayablePermission(tmpPermInfo, flagsList[i], existingFlags)) {
374                    // This is not a permission that is interesting for the user
375                    // to see, so skip it.
376                    continue;
377                }
378                final String origGroupName = tmpPermInfo.group;
379                String groupName = origGroupName;
380                if (groupName == null) {
381                    groupName = tmpPermInfo.packageName;
382                    tmpPermInfo.group = groupName;
383                }
384                MyPermissionGroupInfo group = mPermGroups.get(groupName);
385                if (group == null) {
386                    PermissionGroupInfo grp = null;
387                    if (origGroupName != null) {
388                        grp = mPm.getPermissionGroupInfo(origGroupName, 0);
389                    }
390                    if (grp != null) {
391                        group = new MyPermissionGroupInfo(grp);
392                    } else {
393                        // We could be here either because the permission
394                        // didn't originally specify a group or the group it
395                        // gave couldn't be found.  In either case, we consider
396                        // its group to be the permission's package name.
397                        tmpPermInfo.group = tmpPermInfo.packageName;
398                        group = mPermGroups.get(tmpPermInfo.group);
399                        if (group == null) {
400                            group = new MyPermissionGroupInfo(tmpPermInfo);
401                        }
402                        group = new MyPermissionGroupInfo(tmpPermInfo);
403                    }
404                    mPermGroups.put(tmpPermInfo.group, group);
405                }
406                final boolean newPerm = installedPkgInfo != null
407                        && (existingFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0;
408                MyPermissionInfo myPerm = new MyPermissionInfo(tmpPermInfo);
409                myPerm.mNewReqFlags = flagsList[i];
410                myPerm.mExistingReqFlags = existingFlags;
411                // This is a new permission if the app is already installed and
412                // doesn't currently hold this permission.
413                myPerm.mNew = newPerm;
414                permSet.add(myPerm);
415            } catch (NameNotFoundException e) {
416                Log.i(TAG, "Ignoring unknown permission:"+permName);
417            }
418        }
419    }
420
421    public int getPermissionCount() {
422        return getPermissionCount(WHICH_ALL);
423    }
424
425    private List<MyPermissionInfo> getPermissionList(MyPermissionGroupInfo grp, int which) {
426        if (which == WHICH_NEW) {
427            return grp.mNewPermissions;
428        } else {
429            return grp.mAllPermissions;
430        }
431    }
432
433    public int getPermissionCount(int which) {
434        int N = 0;
435        for (int i=0; i<mPermGroupsList.size(); i++) {
436            N += getPermissionList(mPermGroupsList.get(i), which).size();
437        }
438        return N;
439    }
440
441    public View getPermissionsView() {
442        return getPermissionsView(WHICH_ALL, false);
443    }
444
445    public View getPermissionsViewWithRevokeButtons() {
446        return getPermissionsView(WHICH_ALL, true);
447    }
448
449    public View getPermissionsView(int which) {
450        return getPermissionsView(which, false);
451    }
452
453    private View getPermissionsView(int which, boolean showRevokeUI) {
454        LinearLayout permsView = (LinearLayout) mInflater.inflate(R.layout.app_perms_summary, null);
455        LinearLayout displayList = (LinearLayout) permsView.findViewById(R.id.perms_list);
456        View noPermsView = permsView.findViewById(R.id.no_permissions);
457
458        displayPermissions(mPermGroupsList, displayList, which, showRevokeUI);
459        if (displayList.getChildCount() <= 0) {
460            noPermsView.setVisibility(View.VISIBLE);
461        }
462
463        return permsView;
464    }
465
466    /**
467     * Utility method that displays permissions from a map containing group name and
468     * list of permission descriptions.
469     */
470    private void displayPermissions(List<MyPermissionGroupInfo> groups,
471            LinearLayout permListView, int which, boolean showRevokeUI) {
472        permListView.removeAllViews();
473
474        int spacing = (int)(8*mContext.getResources().getDisplayMetrics().density);
475
476        for (int i=0; i<groups.size(); i++) {
477            MyPermissionGroupInfo grp = groups.get(i);
478            final List<MyPermissionInfo> perms = getPermissionList(grp, which);
479            for (int j=0; j<perms.size(); j++) {
480                MyPermissionInfo perm = perms.get(j);
481                View view = getPermissionItemView(grp, perm, j == 0,
482                        which != WHICH_NEW ? mNewPermPrefix : null, showRevokeUI);
483                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
484                        ViewGroup.LayoutParams.MATCH_PARENT,
485                        ViewGroup.LayoutParams.WRAP_CONTENT);
486                if (j == 0) {
487                    lp.topMargin = spacing;
488                }
489                if (j == grp.mAllPermissions.size()-1) {
490                    lp.bottomMargin = spacing;
491                }
492                if (permListView.getChildCount() == 0) {
493                    lp.topMargin *= 2;
494                }
495                permListView.addView(view, lp);
496            }
497        }
498    }
499
500    private PermissionItemView getPermissionItemView(MyPermissionGroupInfo grp,
501            MyPermissionInfo perm, boolean first, CharSequence newPermPrefix, boolean showRevokeUI) {
502        return getPermissionItemView(mContext, mInflater, grp, perm, first, newPermPrefix,
503                mPackageName, showRevokeUI);
504    }
505
506    private static PermissionItemView getPermissionItemView(Context context, LayoutInflater inflater,
507            MyPermissionGroupInfo grp, MyPermissionInfo perm, boolean first,
508            CharSequence newPermPrefix, String packageName, boolean showRevokeUI) {
509            PermissionItemView permView = (PermissionItemView)inflater.inflate(
510                (perm.flags & PermissionInfo.FLAG_COSTS_MONEY) != 0
511                        ? R.layout.app_permission_item_money : R.layout.app_permission_item,
512                null);
513        permView.setPermission(grp, perm, first, newPermPrefix, packageName, showRevokeUI);
514        return permView;
515    }
516
517    private static View getPermissionItemViewOld(Context context, LayoutInflater inflater,
518            CharSequence grpName, CharSequence permList, boolean dangerous, Drawable icon) {
519        View permView = inflater.inflate(R.layout.app_permission_item_old, null);
520
521        TextView permGrpView = (TextView) permView.findViewById(R.id.permission_group);
522        TextView permDescView = (TextView) permView.findViewById(R.id.permission_list);
523
524        ImageView imgView = (ImageView)permView.findViewById(R.id.perm_icon);
525        imgView.setImageDrawable(icon);
526        if(grpName != null) {
527            permGrpView.setText(grpName);
528            permDescView.setText(permList);
529        } else {
530            permGrpView.setText(permList);
531            permDescView.setVisibility(View.GONE);
532        }
533        return permView;
534    }
535
536    private boolean isDisplayablePermission(PermissionInfo pInfo, int newReqFlags,
537            int existingReqFlags) {
538        final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
539        final boolean isNormal = (base == PermissionInfo.PROTECTION_NORMAL);
540
541        // We do not show normal permissions in the UI.
542        if (isNormal) {
543            return false;
544        }
545
546        final boolean isDangerous = (base == PermissionInfo.PROTECTION_DANGEROUS)
547                || ((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_PRE23) != 0);
548        final boolean isRequired =
549                ((newReqFlags&PackageInfo.REQUESTED_PERMISSION_REQUIRED) != 0);
550        final boolean isDevelopment =
551                ((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
552        final boolean wasGranted =
553                ((existingReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);
554        final boolean isGranted =
555                ((newReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);
556
557        // Dangerous and normal permissions are always shown to the user if the permission
558        // is required, or it was previously granted
559        if (isDangerous && (isRequired || wasGranted || isGranted)) {
560            return true;
561        }
562
563        // Development permissions are only shown to the user if they are already
564        // granted to the app -- if we are installing an app and they are not
565        // already granted, they will not be granted as part of the install.
566        if (isDevelopment && wasGranted) {
567            if (localLOGV) Log.i(TAG, "Special perm " + pInfo.name
568                    + ": protlevel=0x" + Integer.toHexString(pInfo.protectionLevel));
569            return true;
570        }
571        return false;
572    }
573
574    private static class PermissionGroupInfoComparator implements Comparator<MyPermissionGroupInfo> {
575        private final Collator sCollator = Collator.getInstance();
576        @Override
577        public final int compare(MyPermissionGroupInfo a, MyPermissionGroupInfo b) {
578            return sCollator.compare(a.mLabel, b.mLabel);
579        }
580    }
581
582    private static class PermissionInfoComparator implements Comparator<MyPermissionInfo> {
583        private final Collator sCollator = Collator.getInstance();
584        PermissionInfoComparator() {
585        }
586        public final int compare(MyPermissionInfo a, MyPermissionInfo b) {
587            return sCollator.compare(a.mLabel, b.mLabel);
588        }
589    }
590
591    private void addPermToList(List<MyPermissionInfo> permList,
592            MyPermissionInfo pInfo) {
593        if (pInfo.mLabel == null) {
594            pInfo.mLabel = pInfo.loadLabel(mPm);
595        }
596        int idx = Collections.binarySearch(permList, pInfo, mPermComparator);
597        if(localLOGV) Log.i(TAG, "idx="+idx+", list.size="+permList.size());
598        if (idx < 0) {
599            idx = -idx-1;
600            permList.add(idx, pInfo);
601        }
602    }
603
604    private void setPermissions(List<MyPermissionInfo> permList) {
605        if (permList != null) {
606            // First pass to group permissions
607            for (MyPermissionInfo pInfo : permList) {
608                if(localLOGV) Log.i(TAG, "Processing permission:"+pInfo.name);
609                if(!isDisplayablePermission(pInfo, pInfo.mNewReqFlags, pInfo.mExistingReqFlags)) {
610                    if(localLOGV) Log.i(TAG, "Permission:"+pInfo.name+" is not displayable");
611                    continue;
612                }
613                MyPermissionGroupInfo group = mPermGroups.get(pInfo.group);
614                if (group != null) {
615                    pInfo.mLabel = pInfo.loadLabel(mPm);
616                    addPermToList(group.mAllPermissions, pInfo);
617                    if (pInfo.mNew) {
618                        addPermToList(group.mNewPermissions, pInfo);
619                    }
620                }
621            }
622        }
623
624        for (MyPermissionGroupInfo pgrp : mPermGroups.values()) {
625            if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) {
626                pgrp.mLabel = pgrp.loadLabel(mPm);
627            } else {
628                ApplicationInfo app;
629                try {
630                    app = mPm.getApplicationInfo(pgrp.packageName, 0);
631                    pgrp.mLabel = app.loadLabel(mPm);
632                } catch (NameNotFoundException e) {
633                    pgrp.mLabel = pgrp.loadLabel(mPm);
634                }
635            }
636            mPermGroupsList.add(pgrp);
637        }
638        Collections.sort(mPermGroupsList, mPermGroupComparator);
639    }
640}
641