Merge "Add showSystem in RecentLocationAccess (SettingsLib)" into sc-dev
This commit is contained in:
@@ -80,7 +80,8 @@ public class RecentLocationAccesses {
|
|||||||
* Fills a list of applications which queried location recently within specified time.
|
* 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.
|
* 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
|
// Retrieve a location usage list from AppOps
|
||||||
PackageManager pm = mContext.getPackageManager();
|
PackageManager pm = mContext.getPackageManager();
|
||||||
AppOpsManager aoManager =
|
AppOpsManager aoManager =
|
||||||
@@ -108,14 +109,17 @@ public class RecentLocationAccesses {
|
|||||||
|
|
||||||
// Don't show apps that do not have user sensitive location permissions
|
// Don't show apps that do not have user sensitive location permissions
|
||||||
boolean showApp = true;
|
boolean showApp = true;
|
||||||
|
if (!showSystemApps) {
|
||||||
for (int op : LOCATION_OPS) {
|
for (int op : LOCATION_OPS) {
|
||||||
final String permission = AppOpsManager.opToPermission(op);
|
final String permission = AppOpsManager.opToPermission(op);
|
||||||
final int permissionFlags = pm.getPermissionFlags(permission, packageName, user);
|
final int permissionFlags = pm.getPermissionFlags(permission, packageName,
|
||||||
|
user);
|
||||||
if (PermissionChecker.checkPermissionForPreflight(mContext, permission,
|
if (PermissionChecker.checkPermissionForPreflight(mContext, permission,
|
||||||
PermissionChecker.PID_UNKNOWN, uid, packageName)
|
PermissionChecker.PID_UNKNOWN, uid, packageName)
|
||||||
== PermissionChecker.PERMISSION_GRANTED) {
|
== PermissionChecker.PERMISSION_GRANTED) {
|
||||||
if ((permissionFlags
|
if ((permissionFlags
|
||||||
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED) == 0) {
|
& PackageManager.FLAG_PERMISSION_USER_SENSITIVE_WHEN_GRANTED)
|
||||||
|
== 0) {
|
||||||
showApp = false;
|
showApp = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -127,6 +131,7 @@ public class RecentLocationAccesses {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (showApp) {
|
if (showApp) {
|
||||||
Access access = getAccessFromOps(now, ops);
|
Access access = getAccessFromOps(now, ops);
|
||||||
if (access != null) {
|
if (access != null) {
|
||||||
@@ -137,8 +142,15 @@ public class RecentLocationAccesses {
|
|||||||
return accesses;
|
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.
|
// Sort the list of Access by recency. Most recent accesses first.
|
||||||
Collections.sort(accesses, Collections.reverseOrder(new Comparator<Access>() {
|
Collections.sort(accesses, Collections.reverseOrder(new Comparator<Access>() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ public class RecentLocationAccessesTest {
|
|||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
public void testGetAppList_shouldFilterRecentAccesses() {
|
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.
|
// Only two of the apps have requested location within 15 min.
|
||||||
assertThat(requests).hasSize(2);
|
assertThat(requests).hasSize(2);
|
||||||
// Make sure apps are ordered by recency
|
// Make sure apps are ordered by recency
|
||||||
@@ -115,7 +115,7 @@ public class RecentLocationAccessesTest {
|
|||||||
mockTestApplicationInfos(
|
mockTestApplicationInfos(
|
||||||
Process.SYSTEM_UID, RecentLocationAccesses.ANDROID_SYSTEM_PACKAGE_NAME);
|
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.
|
// Android OS shouldn't show up in the list of apps.
|
||||||
assertThat(requests).hasSize(2);
|
assertThat(requests).hasSize(2);
|
||||||
// Make sure apps are ordered by recency
|
// Make sure apps are ordered by recency
|
||||||
|
|||||||
Reference in New Issue
Block a user