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