Tweak summary for permission manager
Summary appends "and more" while the items of permission are larger than 3. Change-Id: Ic3c16404237fb0cb81f0ed5d2cbdff32cf23c452 Fix: 136258315 Test: Robo test and visual
This commit is contained in:
@@ -9132,6 +9132,8 @@
|
|||||||
<string name="app_permissions">Permission manager</string>
|
<string name="app_permissions">Permission manager</string>
|
||||||
<!-- Summary of permissions currently granted to apps [CHAR LIMIT=60] -->
|
<!-- Summary of permissions currently granted to apps [CHAR LIMIT=60] -->
|
||||||
<string name="app_permissions_summary">Apps using <xliff:g id="apps" example="location">%1$s</xliff:g></string>
|
<string name="app_permissions_summary">Apps using <xliff:g id="apps" example="location">%1$s</xliff:g></string>
|
||||||
|
<!-- Summary of permissions currently granted to apps [CHAR LIMIT=60] -->
|
||||||
|
<string name="app_permissions_summary_more">Apps using <xliff:g id="apps" example="location">%1$s</xliff:g>, and more</string>
|
||||||
|
|
||||||
<!-- Label for tap to wake setting [CHAR LIMIT=30] -->
|
<!-- Label for tap to wake setting [CHAR LIMIT=30] -->
|
||||||
<string name="tap_to_wake">Tap to wake</string>
|
<string name="tap_to_wake">Tap to wake</string>
|
||||||
|
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
|
|||||||
public class AppPermissionsPreferenceController extends BasePreferenceController {
|
public class AppPermissionsPreferenceController extends BasePreferenceController {
|
||||||
|
|
||||||
private static final String TAG = "AppPermissionPrefCtrl";
|
private static final String TAG = "AppPermissionPrefCtrl";
|
||||||
private static int NUM_PACKAGE_TO_CHECK = 3;
|
private static final int NUM_PACKAGE_TO_CHECK = 4;
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static int NUM_PERMISSIONS_TO_SHOW = 3;
|
static int NUM_PERMISSIONS_TO_SHOW = 3;
|
||||||
@@ -78,7 +78,7 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
|||||||
void queryPermissionSummary() {
|
void queryPermissionSummary() {
|
||||||
final List<PackageInfo> installedPackages =
|
final List<PackageInfo> installedPackages =
|
||||||
mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
|
mPackageManager.getInstalledPackages(PackageManager.GET_PERMISSIONS);
|
||||||
// Here we only get the first three apps and check their permissions.
|
// Here we only get the first four apps and check their permissions.
|
||||||
final List<PackageInfo> packagesWithPermission = installedPackages.stream()
|
final List<PackageInfo> packagesWithPermission = installedPackages.stream()
|
||||||
.filter(pInfo -> pInfo.permissions != null)
|
.filter(pInfo -> pInfo.permissions != null)
|
||||||
.limit(NUM_PACKAGE_TO_CHECK)
|
.limit(NUM_PACKAGE_TO_CHECK)
|
||||||
@@ -102,10 +102,21 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
|||||||
final List<CharSequence> permissionsToShow = mPermissionGroups.stream()
|
final List<CharSequence> permissionsToShow = mPermissionGroups.stream()
|
||||||
.limit(NUM_PERMISSIONS_TO_SHOW)
|
.limit(NUM_PERMISSIONS_TO_SHOW)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
final CharSequence summary = !permissionsToShow.isEmpty()
|
final boolean isMoreShowed = mPermissionGroups.size() > NUM_PERMISSIONS_TO_SHOW;
|
||||||
? mContext.getString(R.string.app_permissions_summary,
|
CharSequence summary;
|
||||||
ListFormatter.getInstance().format(permissionsToShow).toLowerCase())
|
|
||||||
: mContext.getString(R.string.runtime_permissions_summary_no_permissions_granted);
|
if (!permissionsToShow.isEmpty()) {
|
||||||
|
if (isMoreShowed) {
|
||||||
|
summary = mContext.getString(R.string.app_permissions_summary_more,
|
||||||
|
ListFormatter.getInstance().format(permissionsToShow).toLowerCase());
|
||||||
|
} else {
|
||||||
|
summary = mContext.getString(R.string.app_permissions_summary,
|
||||||
|
ListFormatter.getInstance().format(permissionsToShow).toLowerCase());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
summary = mContext.getString(
|
||||||
|
R.string.runtime_permissions_summary_no_permissions_granted);
|
||||||
|
}
|
||||||
mPreference.setSummary(summary);
|
mPreference.setSummary(summary);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -16,8 +16,6 @@
|
|||||||
|
|
||||||
package com.android.settings.applications;
|
package com.android.settings.applications;
|
||||||
|
|
||||||
import static com.android.settings.applications.AppPermissionsPreferenceController.NUM_PERMISSIONS_TO_SHOW;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
@@ -75,7 +73,7 @@ public class AppPermissionsPreferenceControllerTest {
|
|||||||
public void updateSummary_noGrantedPermission_shouldSetNoPermissionGrantedSummary() {
|
public void updateSummary_noGrantedPermission_shouldSetNoPermissionGrantedSummary() {
|
||||||
doNothing().when(mController).queryPermissionSummary();
|
doNothing().when(mController).queryPermissionSummary();
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
mController.mNumPackageChecked = 2;
|
mController.mNumPackageChecked = 3;
|
||||||
|
|
||||||
mController.updateSummary(new ArrayList<>());
|
mController.updateSummary(new ArrayList<>());
|
||||||
|
|
||||||
@@ -84,20 +82,55 @@ public class AppPermissionsPreferenceControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSummary_hasPermissionGroups_shouldSetPermissionAsSummary() {
|
public void updateSummary_hasOnePermission_shouldSetPermissionAsSummary() {
|
||||||
doNothing().when(mController).queryPermissionSummary();
|
doNothing().when(mController).queryPermissionSummary();
|
||||||
mController.updateState(mPreference);
|
mController.updateState(mPreference);
|
||||||
final String permission = "location";
|
final String permission = "location";
|
||||||
final ArrayList<CharSequence> labels = new ArrayList<>();
|
final ArrayList<CharSequence> labels = new ArrayList<>();
|
||||||
labels.add(permission);
|
labels.add(permission);
|
||||||
final String summary = "Apps using " + permission;
|
final String summary = "Apps using " + permission;
|
||||||
mController.mNumPackageChecked = 2;
|
mController.mNumPackageChecked = 3;
|
||||||
|
|
||||||
mController.updateSummary(labels);
|
mController.updateSummary(labels);
|
||||||
|
|
||||||
assertThat(mPreference.getSummary()).isEqualTo(summary);
|
assertThat(mPreference.getSummary()).isEqualTo(summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateSummary_hasThreePermissions_shouldShowThreePermissionAsSummary() {
|
||||||
|
doNothing().when(mController).queryPermissionSummary();
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
mController.mNumPackageChecked = 3;
|
||||||
|
final List<CharSequence> labels = new ArrayList<>();
|
||||||
|
labels.add("Phone");
|
||||||
|
labels.add("SMS");
|
||||||
|
labels.add("Microphone");
|
||||||
|
|
||||||
|
mController.updateSummary(labels);
|
||||||
|
|
||||||
|
final String summary = "Apps using microphone, sms, and phone";
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(summary);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateSummary_hasFivePermissions_shouldShowThreePermissionsAndMoreAsSummary() {
|
||||||
|
doNothing().when(mController).queryPermissionSummary();
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
mController.mNumPackageChecked = 3;
|
||||||
|
final List<CharSequence> labels = new ArrayList<>();
|
||||||
|
labels.add("Phone");
|
||||||
|
labels.add("SMS");
|
||||||
|
labels.add("Microphone");
|
||||||
|
labels.add("Contacts");
|
||||||
|
labels.add("Camera");
|
||||||
|
labels.add("Location");
|
||||||
|
|
||||||
|
mController.updateSummary(labels);
|
||||||
|
|
||||||
|
final String summary = "Apps using microphone, contacts, and sms, and more";
|
||||||
|
assertThat(mPreference.getSummary()).isEqualTo(summary);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void updateSummary_notReachCallbackCount_shouldNotSetSummary() {
|
public void updateSummary_notReachCallbackCount_shouldNotSetSummary() {
|
||||||
doNothing().when(mController).queryPermissionSummary();
|
doNothing().when(mController).queryPermissionSummary();
|
||||||
@@ -110,29 +143,4 @@ public class AppPermissionsPreferenceControllerTest {
|
|||||||
|
|
||||||
verify(mPreference, never()).setSummary(anyString());
|
verify(mPreference, never()).setSummary(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void updateSummary_hasFiveItems_shouldShowCertainNumItems() {
|
|
||||||
doNothing().when(mController).queryPermissionSummary();
|
|
||||||
mController.updateState(mPreference);
|
|
||||||
mController.mNumPackageChecked = 2;
|
|
||||||
|
|
||||||
mController.updateSummary(getPermissionGroupsSet());
|
|
||||||
|
|
||||||
final CharSequence summary = mPreference.getSummary();
|
|
||||||
final int items = summary.toString().split(",").length;
|
|
||||||
assertThat(items).isEqualTo(NUM_PERMISSIONS_TO_SHOW);
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<CharSequence> getPermissionGroupsSet() {
|
|
||||||
final List<CharSequence> labels = new ArrayList<>();
|
|
||||||
labels.add("Phone");
|
|
||||||
labels.add("SMS");
|
|
||||||
labels.add("Microphone");
|
|
||||||
labels.add("Contacts");
|
|
||||||
labels.add("Camera");
|
|
||||||
labels.add("Location");
|
|
||||||
|
|
||||||
return labels;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user