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