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