Add showSystem in RecentLocationAccess (SettingsLib)
Bug: 180533061 Test: manual on device Test: make RunSettingsLibRoboTests Change-Id: Icf4b294a04e2b852b9fad66a108a8e5114549ec4
This commit is contained in:
@@ -80,7 +80,8 @@ public class RecentLocationAccesses {
|
||||
* Fills a list of applications which queried location recently within specified time.
|
||||
* Apps are sorted by recency. Apps with more recent location accesses are in the front.
|
||||
*/
|
||||
public List<Access> getAppList() {
|
||||
@VisibleForTesting
|
||||
List<Access> getAppList(boolean showSystemApps) {
|
||||
// Retrieve a location usage list from AppOps
|
||||
PackageManager pm = mContext.getPackageManager();
|
||||
AppOpsManager aoManager =
|
||||
@@ -108,22 +109,26 @@ public class RecentLocationAccesses {
|
||||
|
||||
// Don't show apps that do not have user sensitive location permissions
|
||||
boolean showApp = true;
|
||||
for (int op : LOCATION_OPS) {
|
||||
final String permission = AppOpsManager.opToPermission(op);
|
||||
final int permissionFlags = pm.getPermissionFlags(permission, packageName, user);
|
||||
if (PermissionChecker.checkPermissionForPreflight(mContext, permission,
|
||||
PermissionChecker.PID_UNKNOWN, uid, packageName)
|
||||
== PermissionChecker.PERMISSION_GRANTED) {
|
||||
if ((permissionFlags
|
||||
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED) == 0) {
|
||||
showApp = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ((permissionFlags
|
||||
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_DENIED) == 0) {
|
||||
showApp = false;
|
||||
break;
|
||||
if (!showSystemApps) {
|
||||
for (int op : LOCATION_OPS) {
|
||||
final String permission = AppOpsManager.opToPermission(op);
|
||||
final int permissionFlags = pm.getPermissionFlags(permission, packageName,
|
||||
user);
|
||||
if (PermissionChecker.checkPermissionForPreflight(mContext, permission,
|
||||
PermissionChecker.PID_UNKNOWN, uid, packageName)
|
||||
== PermissionChecker.PERMISSION_GRANTED) {
|
||||
if ((permissionFlags
|
||||
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED)
|
||||
== 0) {
|
||||
showApp = false;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ((permissionFlags
|
||||
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_DENIED) == 0) {
|
||||
showApp = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +142,15 @@ public class RecentLocationAccesses {
|
||||
return accesses;
|
||||
}
|
||||
|
||||
public List<Access> getAppListSorted() {
|
||||
List<Access> accesses = getAppList();
|
||||
|
||||
/**
|
||||
* Gets a list of apps that accessed location recently, sorting by recency.
|
||||
*
|
||||
* @param showSystemApps whether includes system apps in the list.
|
||||
* @return the list of apps that recently accessed location.
|
||||
*/
|
||||
public List<Access> getAppListSorted(boolean showSystemApps) {
|
||||
List<Access> accesses = getAppList(showSystemApps);
|
||||
// Sort the list of Access by recency. Most recent accesses first.
|
||||
Collections.sort(accesses, Collections.reverseOrder(new Comparator<Access>() {
|
||||
@Override
|
||||
|
||||
@@ -86,7 +86,7 @@ public class RecentLocationAccessesTest {
|
||||
@Test
|
||||
@Ignore
|
||||
public void testGetAppList_shouldFilterRecentAccesses() {
|
||||
List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList();
|
||||
List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList(false);
|
||||
// Only two of the apps have requested location within 15 min.
|
||||
assertThat(requests).hasSize(2);
|
||||
// Make sure apps are ordered by recency
|
||||
@@ -115,7 +115,7 @@ public class RecentLocationAccessesTest {
|
||||
mockTestApplicationInfos(
|
||||
Process.SYSTEM_UID, RecentLocationAccesses.ANDROID_SYSTEM_PACKAGE_NAME);
|
||||
|
||||
List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList();
|
||||
List<RecentLocationAccesses.Access> requests = mRecentLocationAccesses.getAppList(true);
|
||||
// Android OS shouldn't show up in the list of apps.
|
||||
assertThat(requests).hasSize(2);
|
||||
// Make sure apps are ordered by recency
|
||||
|
||||
Reference in New Issue
Block a user