Merge "Tweak summary for permission manager"
This commit is contained in:
committed by
Android (Google) Code Review
commit
2db8d1d88f
@@ -9138,6 +9138,8 @@
|
||||
<string name="app_permissions">Permission manager</string>
|
||||
<!-- 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>
|
||||
<!-- 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] -->
|
||||
<string name="tap_to_wake">Tap to wake</string>
|
||||
|
@@ -33,7 +33,7 @@ import java.util.stream.Collectors;
|
||||
public class AppPermissionsPreferenceController extends BasePreferenceController {
|
||||
|
||||
private static final String TAG = "AppPermissionPrefCtrl";
|
||||
private static int NUM_PACKAGE_TO_CHECK = 3;
|
||||
private static final int NUM_PACKAGE_TO_CHECK = 4;
|
||||
|
||||
@VisibleForTesting
|
||||
static int NUM_PERMISSIONS_TO_SHOW = 3;
|
||||
@@ -78,7 +78,7 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
||||
void queryPermissionSummary() {
|
||||
final List<PackageInfo> installedPackages =
|
||||
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()
|
||||
.filter(pInfo -> pInfo.permissions != null)
|
||||
.limit(NUM_PACKAGE_TO_CHECK)
|
||||
@@ -102,10 +102,21 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
||||
final List<CharSequence> permissionsToShow = mPermissionGroups.stream()
|
||||
.limit(NUM_PERMISSIONS_TO_SHOW)
|
||||
.collect(Collectors.toList());
|
||||
final CharSequence summary = !permissionsToShow.isEmpty()
|
||||
? mContext.getString(R.string.app_permissions_summary,
|
||||
ListFormatter.getInstance().format(permissionsToShow).toLowerCase())
|
||||
: mContext.getString(R.string.runtime_permissions_summary_no_permissions_granted);
|
||||
final boolean isMoreShowed = mPermissionGroups.size() > NUM_PERMISSIONS_TO_SHOW;
|
||||
CharSequence summary;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -16,8 +16,6 @@
|
||||
|
||||
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 org.mockito.ArgumentMatchers.anyString;
|
||||
@@ -75,7 +73,7 @@ public class AppPermissionsPreferenceControllerTest {
|
||||
public void updateSummary_noGrantedPermission_shouldSetNoPermissionGrantedSummary() {
|
||||
doNothing().when(mController).queryPermissionSummary();
|
||||
mController.updateState(mPreference);
|
||||
mController.mNumPackageChecked = 2;
|
||||
mController.mNumPackageChecked = 3;
|
||||
|
||||
mController.updateSummary(new ArrayList<>());
|
||||
|
||||
@@ -84,20 +82,55 @@ public class AppPermissionsPreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateSummary_hasPermissionGroups_shouldSetPermissionAsSummary() {
|
||||
public void updateSummary_hasOnePermission_shouldSetPermissionAsSummary() {
|
||||
doNothing().when(mController).queryPermissionSummary();
|
||||
mController.updateState(mPreference);
|
||||
final String permission = "location";
|
||||
final ArrayList<CharSequence> labels = new ArrayList<>();
|
||||
labels.add(permission);
|
||||
final String summary = "Apps using " + permission;
|
||||
mController.mNumPackageChecked = 2;
|
||||
mController.mNumPackageChecked = 3;
|
||||
|
||||
mController.updateSummary(labels);
|
||||
|
||||
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
|
||||
public void updateSummary_notReachCallbackCount_shouldNotSetSummary() {
|
||||
doNothing().when(mController).queryPermissionSummary();
|
||||
@@ -110,29 +143,4 @@ public class AppPermissionsPreferenceControllerTest {
|
||||
|
||||
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