From 004e489a251d6adf94922368e98a730185642123 Mon Sep 17 00:00:00 2001 From: "Philip P. Moltmann" Date: Thu, 14 Jun 2018 11:52:14 -0700 Subject: [PATCH] Abbreviate permission labels less aggressively We switched the package installer app to always abbreviate all labels loaded from foreign packages. This is done so that a foreign app cannot crorrupt the UI via super-long strings. The default abbreviation is very aggressive and abbreviates to ~5 cm. When an app with a targetSDK <= M gets installed, all permissions will get auto-granted. Hence when a user side-loads such an app, we show the permissions during install so that the user is aware of this. Unfortunately most permission labels and restrictions do not fit into a single line. This change allows much longer strings for permissions names and descriptions. It still abbreviates eventually and handles permission descriptions with weird characters (such as back-space) correctly. Fixes: 110209410 Test: Side-loaded old app and verified that permission labels and descriptions are not abbreviated. Change-Id: Ie1db240883c9f5cb9c1b74ca7bdcb80625e3f7f2 --- .../android/widget/AppSecurityPermissions.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/java/android/widget/AppSecurityPermissions.java b/core/java/android/widget/AppSecurityPermissions.java index 6df76fa2e09a7..e6f948f2d9692 100644 --- a/core/java/android/widget/AppSecurityPermissions.java +++ b/core/java/android/widget/AppSecurityPermissions.java @@ -21,6 +21,7 @@ import android.content.Context; import android.content.DialogInterface; import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; +import android.content.pm.PackageItemInfo; import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PermissionGroupInfo; @@ -590,7 +591,8 @@ public class AppSecurityPermissions { private void addPermToList(List permList, MyPermissionInfo pInfo) { if (pInfo.mLabel == null) { - pInfo.mLabel = pInfo.loadLabel(mPm); + pInfo.mLabel = pInfo.loadSafeLabel(mPm, 20000, PackageItemInfo.SAFE_LABEL_FLAG_TRIM + | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE); } int idx = Collections.binarySearch(permList, pInfo, mPermComparator); if(localLOGV) Log.i(TAG, "idx="+idx+", list.size="+permList.size()); @@ -611,7 +613,9 @@ public class AppSecurityPermissions { } MyPermissionGroupInfo group = mPermGroups.get(pInfo.group); if (group != null) { - pInfo.mLabel = pInfo.loadLabel(mPm); + pInfo.mLabel = pInfo.loadSafeLabel(mPm, 20000, + PackageItemInfo.SAFE_LABEL_FLAG_TRIM + | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE); addPermToList(group.mAllPermissions, pInfo); if (pInfo.mNew) { addPermToList(group.mNewPermissions, pInfo); @@ -622,14 +626,18 @@ public class AppSecurityPermissions { for (MyPermissionGroupInfo pgrp : mPermGroups.values()) { if (pgrp.labelRes != 0 || pgrp.nonLocalizedLabel != null) { - pgrp.mLabel = pgrp.loadLabel(mPm); + pgrp.mLabel = pgrp.loadSafeLabel(mPm, 20000, PackageItemInfo.SAFE_LABEL_FLAG_TRIM + | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE); } else { ApplicationInfo app; try { app = mPm.getApplicationInfo(pgrp.packageName, 0); - pgrp.mLabel = app.loadLabel(mPm); + pgrp.mLabel = app.loadSafeLabel(mPm, 20000, PackageItemInfo.SAFE_LABEL_FLAG_TRIM + | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE); } catch (NameNotFoundException e) { - pgrp.mLabel = pgrp.loadLabel(mPm); + pgrp.mLabel = pgrp.loadSafeLabel(mPm, 20000, + PackageItemInfo.SAFE_LABEL_FLAG_TRIM + | PackageItemInfo.SAFE_LABEL_FLAG_FIRST_LINE); } } mPermGroupsList.add(pgrp);