Skip to content

Commit e4d1833

Browse files
author
Arthur Shuai
committed
Grant group permissions instead of single permission.
In grant process, when require permission, will grant all group permissions instead of single permission. CRs-Fixed: 1066060 Change-Id: Iafe1d308a6ecb301da1c00450838a87344fc7f5f
1 parent b787f07 commit e4d1833

1 file changed

Lines changed: 75 additions & 139 deletions

File tree

src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java

100755100644
Lines changed: 75 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public class GrantPermissionsActivity extends OverlayTouchActivity
6161
private int[] mGrantResults;
6262

6363
private LinkedHashMap<String, GroupState> mRequestGrantPermissionGroups = new LinkedHashMap<>();
64-
private LinkedHashMap<String, ItemState> mRequestGrantPermissionItems = new LinkedHashMap<>();
6564

6665
private GrantPermissionsViewHandler mViewHandler;
6766
private AppPermissions mAppPermissions;
@@ -143,68 +142,49 @@ public void run() {
143142
}
144143
// We allow the user to choose only non-fixed permissions. A permission
145144
// is fixed either by device policy or the user denying with prejudice.
146-
if (!AppPermissionGroup.isStrictOpEnable()) {
147-
if (!group.isUserFixed() && !group.isPolicyFixed()) {
148-
switch (permissionPolicy) {
149-
case DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT: {
150-
if (!group.areRuntimePermissionsGranted()) {
151-
group.grantRuntimePermissions(false);
152-
}
153-
group.setPolicyFixed();
154-
} break;
145+
if (!group.isUserFixed() && !group.isPolicyFixed()) {
146+
switch (permissionPolicy) {
147+
case DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT: {
148+
if (!group.areRuntimePermissionsGranted()) {
149+
group.grantRuntimePermissions(false);
150+
}
151+
group.setPolicyFixed();
152+
}
153+
break;
155154

156-
case DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY: {
157-
if (group.areRuntimePermissionsGranted()) {
158-
group.revokeRuntimePermissions(false);
159-
}
160-
group.setPolicyFixed();
161-
} break;
162-
163-
default: {
164-
if (!group.areRuntimePermissionsGranted()) {
165-
mRequestGrantPermissionGroups.put(group.getName(),
166-
new GroupState(group));
167-
} else {
168-
group.grantRuntimePermissions(false);
169-
updateGrantResults(group);
170-
}
171-
} break;
155+
case DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY: {
156+
if (group.areRuntimePermissionsGranted()) {
157+
group.revokeRuntimePermissions(false);
158+
}
159+
group.setPolicyFixed();
172160
}
173-
} else {
174-
// if the permission is fixed, ensure that we return the right request result
175-
updateGrantResults(group);
176-
}
177-
}
178-
}
161+
break;
179162

180-
if (AppPermissionGroup.isStrictOpEnable()) {
181-
for (String permName : mRequestedPermissions) {
182-
PermissionInfo permissionInfo;
183-
AppPermissionGroup permAppGroup;
184-
try {
185-
permissionInfo = this.getPackageManager().getPermissionInfo(permName, 0);
186-
permAppGroup = mAppPermissions.getPermissionGroup(permissionInfo.group);
187-
} catch (PackageManager.NameNotFoundException e) {
188-
continue;
163+
default: {
164+
if (!group.areRuntimePermissionsGranted()) {
165+
mRequestGrantPermissionGroups.put(group.getName(),
166+
new GroupState(group));
167+
} else {
168+
group.grantRuntimePermissions(false);
169+
updateGrantResults(group);
170+
}
171+
}
172+
break;
189173
}
190-
mRequestGrantPermissionItems.put(
191-
permName, new ItemState(permAppGroup, permissionInfo, permName));
174+
} else {
175+
// if the permission is fixed, ensure that we return the right request result
176+
updateGrantResults(group);
192177
}
193178
}
179+
194180
setContentView(mViewHandler.createView());
195181

196182
Window window = getWindow();
197183
WindowManager.LayoutParams layoutParams = window.getAttributes();
198184
mViewHandler.updateWindowAttributes(layoutParams);
199185
window.setAttributes(layoutParams);
200-
if (AppPermissionGroup.isStrictOpEnable()) {
201-
if (!showNextPermissionItemGrantRequest()) {
202-
setResultAndFinish();
203-
}
204-
} else {
205-
if (!showNextPermissionGroupGrantRequest()) {
206-
setResultAndFinish();
207-
}
186+
if (!showNextPermissionGroupGrantRequest()) {
187+
setResultAndFinish();
208188
}
209189

210190
}
@@ -253,8 +233,31 @@ private boolean showNextPermissionGroupGrantRequest() {
253233
for (GroupState groupState : mRequestGrantPermissionGroups.values()) {
254234
if (groupState.mState == GroupState.STATE_UNKNOWN) {
255235
CharSequence appLabel = mAppPermissions.getAppLabel();
236+
CharSequence desc = null;
237+
if (AppPermissionGroup.isStrictOpEnable()) {
238+
String info = "";
239+
AppPermissionGroup group = mAppPermissions.getPermissionGroup(groupState
240+
.mGroup.getName());
241+
for (Permission permission : group.getPermissions()) {
242+
try {
243+
PermissionInfo permissionInfo = this.getPackageManager()
244+
.getPermissionInfo(permission.getName(), 0);
245+
if (info.length() != 0) {
246+
info += ", ";
247+
}
248+
info += permissionInfo.loadLabel(getPackageManager());
249+
} catch (PackageManager.NameNotFoundException e) {
250+
e.printStackTrace();
251+
}
252+
}
253+
if (info.length() != 0) {
254+
desc = groupState.mGroup.getDescription() + "(" + info + ")";
255+
}
256+
} else {
257+
desc = groupState.mGroup.getDescription();
258+
}
256259
Spanned message = Html.fromHtml(getString(R.string.permission_warning_template,
257-
appLabel, groupState.mGroup.getDescription()), 0);
260+
appLabel, desc), 0);
258261
// Set the permission message as the title so it can be announced.
259262
setTitle(message);
260263

@@ -269,46 +272,15 @@ private boolean showNextPermissionGroupGrantRequest() {
269272
resources = Resources.getSystem();
270273
}
271274
int icon = groupState.mGroup.getIconResId();
272-
273-
mViewHandler.updateUi(groupState.mGroup.getName(), groupCount, currentIndex,
274-
Icon.createWithResource(resources, icon), message,
275-
groupState.mGroup.isUserSet());
276-
return true;
277-
}
278-
279-
currentIndex++;
280-
}
281-
return false;
282-
}
283-
284-
private boolean showNextPermissionItemGrantRequest() {
285-
final int itemCount = mRequestGrantPermissionItems.size();
286-
int currentIndex = 0;
287-
for (ItemState permState : mRequestGrantPermissionItems.values()) {
288-
if (permState.mState == ItemState.STATE_UNKNOWN) {
289-
CharSequence appLabel = mAppPermissions.getAppLabel();
290-
Spanned message = Html.fromHtml(getString(R.string.permission_warning_template,
291-
appLabel, permState.mItem.loadLabel(this.getPackageManager())), 0);
292-
// Set the permission message as the title so it can be announced.
293-
setTitle(message);
294-
295-
// Set the new grant view
296-
// TODO: Use a real message for the action. We need group action APIs
297-
AppPermissionGroup permGroup = mAppPermissions.getPermissionGroup(
298-
permState.mItem.group);
299-
Resources resources;
300-
try {
301-
resources = getPackageManager().getResourcesForApplication(
302-
permGroup.getIconPkg());
303-
} catch (NameNotFoundException e) {
304-
// Fallback to system.
305-
Log.w(LOG_TAG, "Can't get resources", e);
306-
resources = Resources.getSystem();
275+
if (AppPermissionGroup.isStrictOpEnable()) {
276+
mViewHandler.updateUi(groupState.mGroup.getName(), groupCount, currentIndex,
277+
Icon.createWithResource(resources, icon), message,
278+
true);
279+
} else {
280+
mViewHandler.updateUi(groupState.mGroup.getName(), groupCount, currentIndex,
281+
Icon.createWithResource(resources, icon), message,
282+
groupState.mGroup.isUserSet());
307283
}
308-
int icon = permGroup.getIconResId();
309-
mViewHandler.updateUi(permState.mPermName, itemCount, currentIndex, ///updateUi
310-
Icon.createWithResource(resources, icon), message,
311-
true);
312284
return true;
313285
}
314286

@@ -319,39 +291,19 @@ private boolean showNextPermissionItemGrantRequest() {
319291

320292
@Override
321293
public void onPermissionGrantResult(String name, boolean granted, boolean doNotAskAgain) {
322-
if (AppPermissionGroup.isStrictOpEnable()) {
323-
ItemState permItemState = mRequestGrantPermissionItems.get(name);
324-
final String[] filterPermissions = new String[]{name};
325-
if (permItemState.mGroup != null) {
326-
Log.i(LOG_TAG, "onPermissionGrantResult permItemState.mGroup != null ");
327-
if (granted) {
328-
permItemState.mGroup.grantRuntimePermissions(doNotAskAgain, filterPermissions);
329-
permItemState.mState = ItemState.STATE_ALLOWED;
330-
} else {
331-
permItemState.mGroup.revokeRuntimePermissions(doNotAskAgain, filterPermissions);
332-
permItemState.mState = ItemState.STATE_DENIED;
333-
}
334-
updateGrantResults(permItemState.mGroup);
335-
}
336-
337-
if (!showNextPermissionItemGrantRequest()) {
338-
setResultAndFinish();
339-
}
340-
} else {
341-
GroupState groupState = mRequestGrantPermissionGroups.get(name);
342-
if (groupState.mGroup != null) {
343-
if (granted) {
344-
groupState.mGroup.grantRuntimePermissions(doNotAskAgain);
345-
groupState.mState = GroupState.STATE_ALLOWED;
346-
} else {
347-
groupState.mGroup.revokeRuntimePermissions(doNotAskAgain);
348-
groupState.mState = GroupState.STATE_DENIED;
349-
}
350-
updateGrantResults(groupState.mGroup);
351-
}
352-
if (!showNextPermissionGroupGrantRequest()) {
353-
setResultAndFinish();
294+
GroupState groupState = mRequestGrantPermissionGroups.get(name);
295+
if (groupState.mGroup != null) {
296+
if (granted) {
297+
groupState.mGroup.grantRuntimePermissions(doNotAskAgain);
298+
groupState.mState = GroupState.STATE_ALLOWED;
299+
} else {
300+
groupState.mGroup.revokeRuntimePermissions(doNotAskAgain);
301+
groupState.mState = GroupState.STATE_DENIED;
354302
}
303+
updateGrantResults(groupState.mGroup);
304+
}
305+
if (!showNextPermissionGroupGrantRequest()) {
306+
setResultAndFinish();
355307
}
356308
}
357309

@@ -485,20 +437,4 @@ private static final class GroupState {
485437
mGroup = group;
486438
}
487439
}
488-
489-
private static final class ItemState {
490-
static final int STATE_UNKNOWN = 0;
491-
static final int STATE_ALLOWED = 1;
492-
static final int STATE_DENIED = 2;
493-
494-
final PermissionInfo mItem;
495-
int mState = STATE_UNKNOWN;
496-
String mPermName;
497-
final AppPermissionGroup mGroup;
498-
ItemState(AppPermissionGroup group, PermissionInfo item, String itemId) {
499-
mItem = item;
500-
mPermName = itemId;
501-
mGroup = group;
502-
}
503-
}
504440
}

0 commit comments

Comments
 (0)