The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | */ |
| 17 | package android.widget; |
| 18 | |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 19 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import com.android.internal.R; |
Gilles Debunne | 6b8bdaa | 2010-10-10 13:24:39 -0700 | [diff] [blame] | 21 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 22 | import android.app.AlertDialog; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 24 | import android.content.DialogInterface; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 25 | import android.content.pm.ApplicationInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.pm.PackageInfo; |
| 27 | import android.content.pm.PackageManager; |
Gilles Debunne | 6b8bdaa | 2010-10-10 13:24:39 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager.NameNotFoundException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | import android.content.pm.PermissionGroupInfo; |
| 30 | import android.content.pm.PermissionInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.graphics.drawable.Drawable; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 32 | import android.os.Parcel; |
| 33 | import android.text.SpannableStringBuilder; |
| 34 | import android.text.TextUtils; |
| 35 | import android.util.AttributeSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.util.Log; |
| 37 | import android.view.LayoutInflater; |
| 38 | import android.view.View; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 39 | import android.view.ViewGroup; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import java.text.Collator; |
| 42 | import java.util.ArrayList; |
| 43 | import java.util.Collections; |
| 44 | import java.util.Comparator; |
| 45 | import java.util.HashMap; |
| 46 | import java.util.HashSet; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | import java.util.List; |
| 48 | import java.util.Map; |
| 49 | import 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 | */ |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 62 | public class AppSecurityPermissions { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 64 | public static final int WHICH_NEW = 1<<2; |
| 65 | public static final int WHICH_ALL = 0xffff; |
Dianne Hackborn | 0e128bb | 2012-05-01 14:40:15 -0700 | [diff] [blame] | 66 | |
| 67 | private final static String TAG = "AppSecurityPermissions"; |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 68 | private final static boolean localLOGV = false; |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 69 | private final Context mContext; |
| 70 | private final LayoutInflater mInflater; |
| 71 | private final PackageManager mPm; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 72 | private final Map<String, MyPermissionGroupInfo> mPermGroups |
| 73 | = new HashMap<String, MyPermissionGroupInfo>(); |
| 74 | private final List<MyPermissionGroupInfo> mPermGroupsList |
| 75 | = new ArrayList<MyPermissionGroupInfo>(); |
Julia Reynolds | 9a5c911 | 2015-07-09 15:23:42 -0400 | [diff] [blame] | 76 | private final PermissionGroupInfoComparator mPermGroupComparator = |
| 77 | new PermissionGroupInfoComparator(); |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 78 | private final PermissionInfoComparator mPermComparator = new PermissionInfoComparator(); |
| 79 | private final List<MyPermissionInfo> mPermsList = new ArrayList<MyPermissionInfo>(); |
| 80 | private final CharSequence mNewPermPrefix; |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 81 | private String mPackageName; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 82 | |
| 83 | static class MyPermissionGroupInfo extends PermissionGroupInfo { |
| 84 | CharSequence mLabel; |
| 85 | |
| 86 | final ArrayList<MyPermissionInfo> mNewPermissions = new ArrayList<MyPermissionInfo>(); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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 | |
Julia Reynolds | d1af446 | 2015-07-08 11:12:28 -0400 | [diff] [blame] | 98 | public Drawable loadGroupIcon(Context context, PackageManager pm) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 99 | if (icon != 0) { |
Benjamin Franz | ec2d48b | 2014-10-01 15:38:43 +0100 | [diff] [blame] | 100 | return loadUnbadgedIcon(pm); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 101 | } else { |
Julia Reynolds | d1af446 | 2015-07-08 11:12:28 -0400 | [diff] [blame] | 102 | return context.getDrawable(R.drawable.ic_perm_device_info); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 103 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 104 | } |
| 105 | } |
| 106 | |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 107 | private static class MyPermissionInfo extends PermissionInfo { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 126 | MyPermissionInfo(PermissionInfo info) { |
| 127 | super(info); |
| 128 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | public static class PermissionItemView extends LinearLayout implements View.OnClickListener { |
| 132 | MyPermissionGroupInfo mGroup; |
| 133 | MyPermissionInfo mPerm; |
| 134 | AlertDialog mDialog; |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 135 | private boolean mShowRevokeUI = false; |
| 136 | private String mPackageName; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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, |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 144 | boolean first, CharSequence newPermPrefix, String packageName, |
| 145 | boolean showRevokeUI) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 146 | mGroup = grp; |
| 147 | mPerm = perm; |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 148 | mShowRevokeUI = showRevokeUI; |
| 149 | mPackageName = packageName; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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) { |
Julia Reynolds | d1af446 | 2015-07-08 11:12:28 -0400 | [diff] [blame] | 157 | icon = grp.loadGroupIcon(getContext(), pm); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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); |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 176 | if (localLOGV) Log.i(TAG, "Made perm item " + perm.name |
| 177 | + ": " + label + " in group " + grp.name); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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); |
Julia Reynolds | d1af446 | 2015-07-08 11:12:28 -0400 | [diff] [blame] | 207 | builder.setIcon(mGroup.loadGroupIcon(getContext(), pm)); |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 208 | addRevokeUIIfNecessary(builder); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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 | } |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 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(); |
Svet Ganov | 8c7f700 | 2015-05-07 10:48:44 -0700 | [diff] [blame] | 238 | pm.revokeRuntimePermission(mPackageName, mPerm.name, |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 239 | new UserHandle(mContext.getUserId())); |
Nick Kralevich | 98cbcf1 | 2013-04-08 10:02:08 -0700 | [diff] [blame] | 240 | PermissionItemView.this.setVisibility(View.GONE); |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 241 | } |
| 242 | }; |
Nick Kralevich | 98cbcf1 | 2013-04-08 10:02:08 -0700 | [diff] [blame] | 243 | builder.setNegativeButton(R.string.revoke, ocl); |
| 244 | builder.setPositiveButton(R.string.ok, null); |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 245 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 248 | private AppSecurityPermissions(Context context) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | mContext = context; |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 250 | mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 251 | mPm = mContext.getPackageManager(); |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 252 | // Pick up from framework resources instead. |
| 253 | mNewPermPrefix = mContext.getText(R.string.perms_new_perm_prefix); |
| 254 | } |
| 255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 256 | public AppSecurityPermissions(Context context, String packageName) { |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 257 | this(context); |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 258 | mPackageName = packageName; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 259 | Set<MyPermissionInfo> permSet = new HashSet<MyPermissionInfo>(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | PackageInfo pkgInfo; |
| 261 | try { |
| 262 | pkgInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); |
| 263 | } catch (NameNotFoundException e) { |
Dianne Hackborn | 52c6234 | 2012-09-21 10:57:45 -0700 | [diff] [blame] | 264 | Log.w(TAG, "Couldn't retrieve permissions for package:"+packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | // Extract all user permissions |
| 268 | if((pkgInfo.applicationInfo != null) && (pkgInfo.applicationInfo.uid != -1)) { |
| 269 | getAllUsedPermissions(pkgInfo.applicationInfo.uid, permSet); |
| 270 | } |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 271 | mPermsList.addAll(permSet); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 272 | setPermissions(mPermsList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 274 | |
Dianne Hackborn | eba784ff | 2012-09-19 12:42:37 -0700 | [diff] [blame] | 275 | public AppSecurityPermissions(Context context, PackageInfo info) { |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 276 | this(context); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 277 | Set<MyPermissionInfo> permSet = new HashSet<MyPermissionInfo>(); |
Dianne Hackborn | eba784ff | 2012-09-19 12:42:37 -0700 | [diff] [blame] | 278 | if(info == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | return; |
| 280 | } |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 281 | mPackageName = info.packageName; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 282 | |
| 283 | // Convert to a PackageInfo |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 284 | PackageInfo installedPkgInfo = null; |
Suchi Amalapurapu | c7b14e9 | 2009-05-27 14:11:50 -0700 | [diff] [blame] | 285 | // Get requested permissions |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 286 | if (info.requestedPermissions != null) { |
| 287 | try { |
| 288 | installedPkgInfo = mPm.getPackageInfo(info.packageName, |
| 289 | PackageManager.GET_PERMISSIONS); |
| 290 | } catch (NameNotFoundException e) { |
Suchi Amalapurapu | c7b14e9 | 2009-05-27 14:11:50 -0700 | [diff] [blame] | 291 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 292 | extractPerms(info, permSet, installedPkgInfo); |
Suchi Amalapurapu | c7b14e9 | 2009-05-27 14:11:50 -0700 | [diff] [blame] | 293 | } |
Svetoslav | c6d1c34 | 2015-02-26 14:44:43 -0800 | [diff] [blame] | 294 | // Get permissions related to shared user if any |
Dianne Hackborn | eba784ff | 2012-09-19 12:42:37 -0700 | [diff] [blame] | 295 | if (info.sharedUserId != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | int sharedUid; |
| 297 | try { |
Dianne Hackborn | eba784ff | 2012-09-19 12:42:37 -0700 | [diff] [blame] | 298 | sharedUid = mPm.getUidForSharedUser(info.sharedUserId); |
Suchi Amalapurapu | c7b14e9 | 2009-05-27 14:11:50 -0700 | [diff] [blame] | 299 | getAllUsedPermissions(sharedUid, permSet); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 300 | } catch (NameNotFoundException e) { |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 301 | Log.w(TAG, "Couldn't retrieve shared user id for: " + info.packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | } |
Suchi Amalapurapu | c7b14e9 | 2009-05-27 14:11:50 -0700 | [diff] [blame] | 304 | // Retrieve list of permissions |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 305 | mPermsList.addAll(permSet); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 306 | setPermissions(mPermsList); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 307 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 308 | |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 309 | /** |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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. |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 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); |
Alan Viverette | 8eea3ea | 2014-02-03 18:40:20 -0800 | [diff] [blame] | 318 | Drawable icon = context.getDrawable(dangerous |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 319 | ? R.drawable.ic_bullet_key_permission : R.drawable.ic_text_dot); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 320 | return getPermissionItemViewOld(context, inflater, grpName, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 321 | description, dangerous, icon); |
| 322 | } |
| 323 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 324 | private void getAllUsedPermissions(int sharedUid, Set<MyPermissionInfo> permSet) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 334 | private void getPermissionsForPackage(String packageName, Set<MyPermissionInfo> permSet) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 335 | try { |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 336 | PackageInfo pkgInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 337 | extractPerms(pkgInfo, permSet, pkgInfo); |
Nick Kralevich | 10ac1d1 | 2013-03-24 14:27:00 -0700 | [diff] [blame] | 338 | } catch (NameNotFoundException e) { |
| 339 | Log.w(TAG, "Couldn't retrieve permissions for package: " + packageName); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 340 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 348 | return; |
| 349 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 350 | for (int i=0; i<strList.length; i++) { |
| 351 | String permName = strList[i]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | try { |
| 353 | PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 354 | if (tmpPermInfo == null) { |
| 355 | continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 356 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | } catch (NameNotFoundException e) { |
| 412 | Log.i(TAG, "Ignoring unknown permission:"+permName); |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | public int getPermissionCount() { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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; |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | public View getPermissionsView() { |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 438 | return getPermissionsView(WHICH_ALL, false); |
| 439 | } |
| 440 | |
| 441 | public View getPermissionsViewWithRevokeButtons() { |
| 442 | return getPermissionsView(WHICH_ALL, true); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | public View getPermissionsView(int which) { |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 446 | return getPermissionsView(which, false); |
| 447 | } |
| 448 | |
| 449 | private View getPermissionsView(int which, boolean showRevokeUI) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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); |
Dianne Hackborn | 4034bc4 | 2012-06-01 12:45:49 -0700 | [diff] [blame] | 453 | |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 454 | displayPermissions(mPermGroupsList, displayList, which, showRevokeUI); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 455 | if (displayList.getChildCount() <= 0) { |
| 456 | noPermsView.setVisibility(View.VISIBLE); |
| 457 | } |
Dianne Hackborn | 0e128bb | 2012-05-01 14:40:15 -0700 | [diff] [blame] | 458 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 459 | return permsView; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
| 463 | * Utility method that displays permissions from a map containing group name and |
| 464 | * list of permission descriptions. |
| 465 | */ |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 466 | private void displayPermissions(List<MyPermissionGroupInfo> groups, |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 467 | LinearLayout permListView, int which, boolean showRevokeUI) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 468 | permListView.removeAllViews(); |
| 469 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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, |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 478 | which != WHICH_NEW ? mNewPermPrefix : null, showRevokeUI); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 493 | } |
| 494 | } |
| 495 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 496 | private PermissionItemView getPermissionItemView(MyPermissionGroupInfo grp, |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 497 | MyPermissionInfo perm, boolean first, CharSequence newPermPrefix, boolean showRevokeUI) { |
| 498 | return getPermissionItemView(mContext, mInflater, grp, perm, first, newPermPrefix, |
| 499 | mPackageName, showRevokeUI); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 500 | } |
| 501 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 502 | private static PermissionItemView getPermissionItemView(Context context, LayoutInflater inflater, |
| 503 | MyPermissionGroupInfo grp, MyPermissionInfo perm, boolean first, |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 504 | CharSequence newPermPrefix, String packageName, boolean showRevokeUI) { |
Nick Kralevich | a56b78d | 2013-04-07 11:13:16 -0700 | [diff] [blame] | 505 | PermissionItemView permView = (PermissionItemView)inflater.inflate( |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 506 | (perm.flags & PermissionInfo.FLAG_COSTS_MONEY) != 0 |
| 507 | ? R.layout.app_permission_item_money : R.layout.app_permission_item, |
| 508 | null); |
Nick Kralevich | ddfbe00 | 2013-04-05 18:32:07 -0700 | [diff] [blame] | 509 | permView.setPermission(grp, perm, first, newPermPrefix, packageName, showRevokeUI); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 510 | return permView; |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 511 | } |
| 512 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 513 | private static View getPermissionItemViewOld(Context context, LayoutInflater inflater, |
Dianne Hackborn | 8aa2e89 | 2010-01-22 11:31:30 -0800 | [diff] [blame] | 514 | CharSequence grpName, CharSequence permList, boolean dangerous, Drawable icon) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 515 | View permView = inflater.inflate(R.layout.app_permission_item_old, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | |
| 517 | TextView permGrpView = (TextView) permView.findViewById(R.id.permission_group); |
| 518 | TextView permDescView = (TextView) permView.findViewById(R.id.permission_list); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 532 | private boolean isDisplayablePermission(PermissionInfo pInfo, int newReqFlags, |
| 533 | int existingReqFlags) { |
| 534 | final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE; |
Nick Kralevich | a5043ed | 2013-03-25 12:11:58 -0700 | [diff] [blame] | 535 | final boolean isNormal = (base == PermissionInfo.PROTECTION_NORMAL); |
Svetoslav | a3f68ef | 2015-07-22 17:02:46 -0700 | [diff] [blame] | 536 | |
| 537 | // We do not show normal permissions in the UI. |
| 538 | if (isNormal) { |
| 539 | return false; |
| 540 | } |
| 541 | |
Dianne Hackborn | de15eda | 2015-07-01 12:30:54 -0700 | [diff] [blame] | 542 | final boolean isDangerous = (base == PermissionInfo.PROTECTION_DANGEROUS) |
| 543 | || ((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_PRE23) != 0); |
Nick Kralevich | a5043ed | 2013-03-25 12:11:58 -0700 | [diff] [blame] | 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); |
Nick Kralevich | 7a8c135 | 2013-03-26 16:59:26 -0700 | [diff] [blame] | 550 | final boolean isGranted = |
| 551 | ((newReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0); |
Nick Kralevich | a5043ed | 2013-03-25 12:11:58 -0700 | [diff] [blame] | 552 | |
| 553 | // Dangerous and normal permissions are always shown to the user if the permission |
| 554 | // is required, or it was previously granted |
Svetoslav | a3f68ef | 2015-07-22 17:02:46 -0700 | [diff] [blame] | 555 | if (isDangerous && (isRequired || wasGranted || isGranted)) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 556 | return true; |
Dianne Hackborn | e639da7 | 2012-02-21 15:11:13 -0800 | [diff] [blame] | 557 | } |
Nick Kralevich | a5043ed | 2013-03-25 12:11:58 -0700 | [diff] [blame] | 558 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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. |
Nick Kralevich | a5043ed | 2013-03-25 12:11:58 -0700 | [diff] [blame] | 562 | if (isDevelopment && wasGranted) { |
Dianne Hackborn | 2ca2c87 | 2012-09-16 16:03:36 -0700 | [diff] [blame] | 563 | if (localLOGV) Log.i(TAG, "Special perm " + pInfo.name |
| 564 | + ": protlevel=0x" + Integer.toHexString(pInfo.protectionLevel)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | return true; |
| 566 | } |
| 567 | return false; |
| 568 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 569 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 570 | private static class PermissionGroupInfoComparator implements Comparator<MyPermissionGroupInfo> { |
Dianne Hackborn | 0e128bb | 2012-05-01 14:40:15 -0700 | [diff] [blame] | 571 | private final Collator sCollator = Collator.getInstance(); |
Julia Reynolds | 9a5c911 | 2015-07-09 15:23:42 -0400 | [diff] [blame] | 572 | @Override |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 573 | public final int compare(MyPermissionGroupInfo a, MyPermissionGroupInfo b) { |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 574 | return sCollator.compare(a.mLabel, b.mLabel); |
Dianne Hackborn | 0e128bb | 2012-05-01 14:40:15 -0700 | [diff] [blame] | 575 | } |
| 576 | } |
Dianne Hackborn | 4034bc4 | 2012-06-01 12:45:49 -0700 | [diff] [blame] | 577 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 601 | if (permList != null) { |
| 602 | // First pass to group permissions |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 603 | for (MyPermissionInfo pInfo : permList) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | if(localLOGV) Log.i(TAG, "Processing permission:"+pInfo.name); |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 605 | if(!isDisplayablePermission(pInfo, pInfo.mNewReqFlags, pInfo.mExistingReqFlags)) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 606 | if(localLOGV) Log.i(TAG, "Permission:"+pInfo.name+" is not displayable"); |
| 607 | continue; |
| 608 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 618 | } |
| 619 | |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 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); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |
Dianne Hackborn | 7454d3b | 2012-09-12 17:22:00 -0700 | [diff] [blame] | 634 | Collections.sort(mPermGroupsList, mPermGroupComparator); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 635 | } |
| 636 | } |